-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a038dba
commit 3f4b1ef
Showing
25 changed files
with
172 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
transforms/add-button-margin-prop/__testfixtures__/ExportDefaultDeclaration.input.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
transforms/add-button-margin-prop/__testfixtures__/ExportDefaultDeclaration.output.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
transforms/add-button-margin-prop/__testfixtures__/ExportNamedDeclaration.input.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
transforms/add-button-margin-prop/__testfixtures__/ExportNamedDeclaration.output.js
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
transforms/add-button-margin-prop/__testfixtures__/SiblingCombinator.input.js
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
transforms/add-button-margin-prop/__testfixtures__/SiblingCombinator.output.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
transforms/add-button-margin-prop/__tests__/add-button-margin-prop.js
This file was deleted.
Oops, something went wrong.
84 changes: 0 additions & 84 deletions
84
transforms/add-button-margin-prop/add-button-margin-prop.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,58 @@ | ||
# add-attribute | ||
# add-prop | ||
|
||
In order to accomodate the `styled-system` spacing api being added to Carbon components, the `padding` prop on `Tile` has been replaced with `p`. | ||
This universal codemod provides possibility to add any prop to any component. | ||
|
||
Currently `padding` accepts the values `XS`, `S`, `M`, `L` and `XL` which map to paddings of `8px` up to `40px`. This codemod will replace these with the `styled-system` equivalent. I.e. for `padding="XS"` this will be `p={1}`, both of which map to `8px`. | ||
```diff | ||
- <Component /> | ||
+ <Component newProp="info" /> | ||
|
||
``` | ||
## Usage | ||
|
||
`npx carbon-codemod add-prop <target> <component-import-path> <prop> <value>` | ||
|
||
### Examples | ||
|
||
### String | ||
`npx carbon-codemod add-prop src carbon-react/lib/components/button ml "16px"` | ||
|
||
```js | ||
import Button from "carbon-react/lib/components/button"; | ||
``` | ||
```diff | ||
- <Button>Button</Button> | ||
+ <Button ml="16px">Button</Button> | ||
``` | ||
|
||
### Number | ||
`npx carbon-codemod add-prop src carbon-react/lib/components/button ml 2` | ||
|
||
```js | ||
import Button from "carbon-react/lib/components/button"; | ||
``` | ||
```diff | ||
- <Tile padding="XS">Content</Tile> | ||
+ <Tile p={1}>Content</Tile> | ||
- <Button>Button</Button> | ||
+ <Button ml={2}>Button</Button> | ||
``` | ||
|
||
If there is a pattern that you use that is not transformed, please file a feature request. | ||
### Boolean - True | ||
`npx carbon-codemod add-prop src carbon-react/lib/components/button hasBorder true` | ||
|
||
## Usage | ||
```js | ||
import Button from "carbon-react/lib/components/button"; | ||
``` | ||
```diff | ||
- <Button>Button</Button> | ||
+ <Button hasBorder>Button</Button> | ||
``` | ||
|
||
### Boolean - False | ||
`npx carbon-codemod add-prop src carbon-react/lib/components/button hasBorder true` | ||
|
||
`npx carbon-codemod tile-update-padding-prop <target>` | ||
```js | ||
import Button from "carbon-react/lib/components/button"; | ||
``` | ||
```diff | ||
- <Button>Button</Button> | ||
+ <Button hasBorder={false}>Button</Button> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asFalse = () => <Button /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asFalse = () => <Button hasBorder={false} /> |
2 changes: 1 addition & 1 deletion
2
.../add-prop/__testfixtures__/Basic.input.js → ...rop/__testfixtures__/BooleanTrue.input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const App = () => <Button /> | ||
export const asTrue = () => <Button /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asTrue = () => <Button hasBorder /> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asNumber = () => <Button /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asNumber = () => <Button ml={2} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asString = () => <Button /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Button from "carbon-react/lib/components/button"; | ||
|
||
export const asString = () => <Button ml="16px" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,67 @@ | ||
import defineTest from "../../../defineTest"; | ||
|
||
defineTest(__dirname, "add-prop", { | ||
component: "carbon-react/lib/components/button", | ||
prop: "ml", | ||
value: "2", | ||
}, "Basic"); | ||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/button", | ||
prop: "ml", | ||
value: 2, | ||
}, | ||
"Number" | ||
); | ||
|
||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/button", | ||
prop: "ml", | ||
value: "16px", | ||
}, | ||
"String" | ||
); | ||
|
||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/button", | ||
prop: "hasBorder", | ||
value: true, | ||
}, | ||
"BooleanTrue" | ||
); | ||
|
||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/button", | ||
prop: "hasBorder", | ||
value: false, | ||
}, | ||
"BooleanFalse" | ||
); | ||
|
||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/component", | ||
prop: "newProp", | ||
value: "value", | ||
}, | ||
"NoImport" | ||
); | ||
|
||
defineTest( | ||
__dirname, | ||
"add-prop", | ||
{ | ||
component: "carbon-react/lib/components/button", | ||
prop: "ml", | ||
value: "2", | ||
}, | ||
"NoTransformRequired" | ||
); |
Oops, something went wrong.