@@ -4,36 +4,35 @@ Automatic codemods to upgrade your styled-components code to newer versions.
4
4
5
5
## Installation
6
6
7
- ``` sh
8
- npm install -g styled-components-codemods
9
- ```
7
+ Thanks to ` npx ` no installation is needed, just run the command below!
10
8
11
9
## Usage
12
10
13
- ``` sh
14
- Usage: styled-components-codemods [options] [command]
11
+ ``` sh
12
+ Usage: npx styled-components-codemods [options] [command]
15
13
16
14
Options:
17
15
18
- -V, --version output the version number
19
- -h, --help output usage information
16
+ -V, --version output the version number
17
+ -h, --help output usage information
20
18
21
19
Commands:
22
20
23
- v4 [files...] Upgrade your code to styled-components v4 (codemods .extend)
21
+ v4 [...files] Run all v4 codemods
22
+ v4-extendToStyled [...files] Run just the extendToStyled codemod
23
+ v4-injectGlobalToCreateGlobalStyle [...files] Run just the injectGlobalToCreateGlobalStyle codemod
24
24
25
25
Examples:
26
26
27
- $ styled-components-codemods v4 src/components/Box.js src/components/Button.js
27
+ $ styled-components-codemods v4-extendToStyled src/components/Box.js src/components/Button.js
28
28
$ styled-components-codemods v4 src/** /* .js (this will only work if your terminal expands globs)
29
29
` ` `
30
30
31
31
# ## Codemods
32
32
33
-
34
33
# ### v4
35
34
36
- 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.
35
+ 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. Furthermore, the injectGlobal API has been upgraded to slot into React ' s lifecycle more naturally. It refactors all `injectGlobal` calls, and warns you where they are, so you can export them and include them when rendering.
37
36
38
37
##### Limitations
39
38
@@ -47,37 +46,42 @@ There is no way to distinguish whether `.extend` identifier is related to `style
47
46
48
47
<summary>Code Before</summary>
49
48
50
-
51
49
```javascript
52
- StyledComponent.extend` `
50
+ StyledComponent.extend``;
53
51
54
- StyledComponent.extend` color: red; `
52
+ StyledComponent.extend`
53
+ color: red;
54
+ `;
55
55
56
- StyledComponent.extend({ color: " red" })
56
+ StyledComponent.extend({ color: "red" });
57
57
58
- StyledComponent.extend
58
+ StyledComponent.extend;
59
59
60
- StyledComponent.extend` ` .extend
60
+ StyledComponent.extend``.extend;
61
61
62
- StyledComponent.extend({ color: red }).extend
62
+ StyledComponent.extend({ color: red }).extend;
63
63
64
- styled.div` ` .extend` `
64
+ styled.div``.extend``;
65
65
66
- styled.div` color: red; ` .extend` color: blue; `
66
+ styled.div`
67
+ color: red;
68
+ `.extend`color: blue;`;
67
69
68
- styled.div({ color: " red" }).extend({ color: " blue" })
70
+ styled.div({ color: "red" }).extend({ color: "blue" });
69
71
70
- StyledComponent.withComponent(' div' ).extend` `
72
+ StyledComponent.withComponent(" div" ).extend``;
71
73
72
- StyledComponent.withComponent(' div' ).extend` color: red; `
74
+ StyledComponent.withComponent(" div" ).extend`color: red;`;
73
75
74
- StyledComponent.withComponent(' div' ).extend ()
76
+ StyledComponent.withComponent(" div" ).extend();
75
77
76
- StyledComponent.withComponent(' div' ).extend({ color: red })
78
+ StyledComponent.withComponent(" div" ).extend({ color: red });
77
79
78
- StyledComponent.extend().extend().extend ().extend` `
80
+ StyledComponent.extend()
81
+ .extend()
82
+ .extend().extend``;
79
83
80
- StyledComponent.extend``.extend ().extend` ` .extend` `
84
+ StyledComponent.extend``.extend().extend``.extend``;
81
85
```
82
86
83
87
</details>
@@ -87,49 +91,47 @@ StyledComponent.extend``.extend().extend``.extend``
87
91
<summary>Code after</summary>
88
92
89
93
```javascript
90
- import styled, { css } from ' styled-components'
94
+ import styled, { css } from " styled-components";
91
95
92
- styled(StyledComponent)` `
96
+ styled(StyledComponent)``;
93
97
94
98
styled(StyledComponent)`
95
99
color: red;
96
- `
100
+ `;
97
101
98
- styled(StyledComponent)({ color: ' red' })
102
+ styled(StyledComponent)({ color: " red" });
99
103
100
- styled(StyledComponent)
104
+ styled(StyledComponent);
101
105
102
- styled(styled(StyledComponent)` ` )
106
+ styled(styled(StyledComponent)``);
103
107
104
- styled(styled(StyledComponent)({ color: red }))
108
+ styled(styled(StyledComponent)({ color: red }));
105
109
106
- styled(styled.div` ` )` `
110
+ styled(styled.div``)``;
107
111
108
112
styled(
109
113
styled.div`
110
114
color: red;
111
115
`
112
116
)`
113
117
color: blue;
114
- `
118
+ `;
115
119
116
- styled(styled.div({ color: ' red' }))({ color: ' blue' })
120
+ styled(styled.div({ color: " red" }))({ color: " blue" });
117
121
118
- styled(StyledComponent.withComponent(' div' ))` `
122
+ styled(StyledComponent.withComponent(" div" ))``;
119
123
120
- styled(StyledComponent.withComponent(' div' ))`
124
+ styled(StyledComponent.withComponent(" div" ))`
121
125
color: red;
122
- `
126
+ `;
123
127
124
- styled(StyledComponent.withComponent(' div' )) ()
128
+ styled(StyledComponent.withComponent(" div" ))();
125
129
126
- styled(StyledComponent.withComponent(' div' ))({ color: red })
130
+ styled(StyledComponent.withComponent(" div" ))({ color: red });
127
131
128
- styled(styled(styled(styled(StyledComponent)())()) ())` `
132
+ styled(styled(styled(styled(StyledComponent)())())())``;
129
133
130
- styled(styled(styled(styled(StyledComponent)``) ())` ` )` `
134
+ styled(styled(styled(styled(StyledComponent)``)())``)``;
131
135
```
132
136
133
137
</details>
134
-
135
-
0 commit comments