Coder Social home page Coder Social logo

stevenlangbroek / styled-components-codemods Goto Github PK

View Code? Open in Web Editor NEW

This project forked from styled-components/styled-components-codemods

0.0 2.0 0.0 98 KB

Automatic codemods to upgrade your styled-components code to newer versions.

License: MIT License

JavaScript 100.00%

styled-components-codemods's Introduction

styled-components-codemods

Automatic codemods to upgrade your styled-components code to newer versions.

Installation

npm install -g styled-components-codemods

Usage

Usage: styled-components-codemods [options] [command]

Options:

  -V, --version  output the version number
  -h, --help     output usage information

Commands:

  v4 [files...]  Upgrade your code to styled-components v4 (codemods .extend)

Examples:

  $ styled-components-codemods v4 src/components/Box.js src/components/Button.js
  $ styled-components-codemods v4 src/**/*.js (this will only work if your terminal expands globs)

Codemods

v4

In version 4 of styled-components the Component.extends API will be removed in favor of only using styled(Component). This codemod replaces all .extends calls to equivalent styled() calls instead.

Limitations

There is no way to distinguish whether .extend identifier is related to styled-components or any other library/prototype etc. If you know that there is another .extend function in your project that is not related to styled-components be aware and revert these instances manually.

Be aware that .extend used in combination with .withComponent can give you a different result than styled(WithComponentedComponent). Refer to this issue to understand the difference.

Example
Code Before
StyledComponent.extend``

StyledComponent.extend`color: red;`

StyledComponent.extend({ color: "red" })

StyledComponent.extend

StyledComponent.extend``.extend

StyledComponent.extend({ color: red }).extend

styled.div``.extend``

styled.div`color: red;`.extend`color: blue;`

styled.div({ color: "red"}).extend({ color: "blue"})

StyledComponent.withComponent('div').extend``

StyledComponent.withComponent('div').extend`color: red;`

StyledComponent.withComponent('div').extend()

StyledComponent.withComponent('div').extend({ color: red })

StyledComponent.extend().extend().extend().extend``

StyledComponent.extend``.extend().extend``.extend``
Code after
import styled, { css } from 'styled-components'

styled(StyledComponent)``

styled(StyledComponent)`
  color: red;
`

styled(StyledComponent)({ color: 'red' })

styled(StyledComponent)

styled(styled(StyledComponent)``)

styled(styled(StyledComponent)({ color: red }))

styled(styled.div``)``

styled(
  styled.div`
    color: red;
  `
)`
  color: blue;
`

styled(styled.div({ color: 'red' }))({ color: 'blue' })

styled(StyledComponent.withComponent('div'))``

styled(StyledComponent.withComponent('div'))`
  color: red;
`

styled(StyledComponent.withComponent('div'))()

styled(StyledComponent.withComponent('div'))({ color: red })

styled(styled(styled(styled(StyledComponent)())())())``

styled(styled(styled(styled(StyledComponent)``)())``)``

styled-components-codemods's People

Contributors

mxstbr avatar rip21 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.