-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(cli): add codemod for List props * refactor(cli): extract function to find local component names * feat(cli): add codemod to rename onChange props * feat(cli): add codemod to rename as prop * feat(cli): add codemod to rename Selector props * feat(cli): add codemod to remove exit animations * feat(cli): add codemod to rename ref Input prop
- Loading branch information
1 parent
b63d385
commit f9cbb24
Showing
22 changed files
with
588 additions
and
12 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 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,35 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Heading, SubHeading, Text, Input } from '@sumup/circuit-ui'; | ||
|
||
const BaseHeading = () => <Heading element="h1" />; | ||
|
||
const RedHeading = styled(Heading)` | ||
color: red; | ||
`; | ||
|
||
const StyledHeading = () => <RedHeading element="h1" />; | ||
|
||
const BaseSubHeading = () => <SubHeading element="h1" />; | ||
|
||
const RedSubHeading = styled(SubHeading)` | ||
color: red; | ||
`; | ||
|
||
const StyledSubHeading = () => <RedSubHeading element="h1" />; | ||
|
||
const BaseText = () => <Text element="h1" />; | ||
|
||
const RedText = styled(Text)` | ||
color: red; | ||
`; | ||
|
||
const StyledText = () => <RedText element="h1" />; | ||
|
||
const BaseInput = () => <Input element="h1" />; | ||
|
||
const RedInput = styled(Input)` | ||
color: red; | ||
`; | ||
|
||
const StyledInput = () => <RedInput element="h1" />; |
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,35 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Heading, SubHeading, Text, Input } from '@sumup/circuit-ui'; | ||
|
||
const BaseHeading = () => <Heading as="h1" />; | ||
|
||
const RedHeading = styled(Heading)` | ||
color: red; | ||
`; | ||
|
||
const StyledHeading = () => <RedHeading as="h1" />; | ||
|
||
const BaseSubHeading = () => <SubHeading as="h1" />; | ||
|
||
const RedSubHeading = styled(SubHeading)` | ||
color: red; | ||
`; | ||
|
||
const StyledSubHeading = () => <RedSubHeading as="h1" />; | ||
|
||
const BaseText = () => <Text as="h1" />; | ||
|
||
const RedText = styled(Text)` | ||
color: red; | ||
`; | ||
|
||
const StyledText = () => <RedText as="h1" />; | ||
|
||
const BaseInput = () => <Input as="h1" />; | ||
|
||
const RedInput = styled(Input)` | ||
color: red; | ||
`; | ||
|
||
const StyledInput = () => <RedInput as="h1" />; |
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,23 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { LoadingButton } from '@sumup/circuit-ui'; | ||
|
||
const BaseLoadingButton = () => ( | ||
<LoadingButton | ||
exitAnimation={LoadingButton.ERROR} | ||
onAnimationComplete={console.log} | ||
exitAnimationDuration={300} | ||
/> | ||
); | ||
|
||
const RedLoadingButton = styled(LoadingButton)` | ||
color: red; | ||
`; | ||
|
||
const StyledLoadingButton = () => ( | ||
<RedLoadingButton | ||
exitAnimation={LoadingButton.ERROR} | ||
onAnimationComplete={console.log} | ||
exitAnimationDuration={300} | ||
/> | ||
); |
15 changes: 15 additions & 0 deletions
15
src/cli/migrate/__testfixtures__/exit-animations.output.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { LoadingButton } from '@sumup/circuit-ui'; | ||
|
||
const BaseLoadingButton = () => ( | ||
<LoadingButton /> | ||
); | ||
|
||
const RedLoadingButton = styled(LoadingButton)` | ||
color: red; | ||
`; | ||
|
||
const StyledLoadingButton = () => ( | ||
<RedLoadingButton /> | ||
); |
17 changes: 17 additions & 0 deletions
17
src/cli/migrate/__testfixtures__/input-deepref-prop.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { useRef } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Input } from '@sumup/circuit-ui'; | ||
|
||
const Form = () => { | ||
const ref = useRef(null); | ||
return <Input deepRef={ref} />; | ||
}; | ||
|
||
const RedInput = styled(Input)` | ||
color: red; | ||
`; | ||
|
||
const RedForm = () => { | ||
const ref = useRef(null); | ||
return <RedInput deepRef={ref} />; | ||
}; |
17 changes: 17 additions & 0 deletions
17
src/cli/migrate/__testfixtures__/input-deepref-prop.output.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { useRef } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Input } from '@sumup/circuit-ui'; | ||
|
||
const Form = () => { | ||
const ref = useRef(null); | ||
return <Input ref={ref} />; | ||
}; | ||
|
||
const RedInput = styled(Input)` | ||
color: red; | ||
`; | ||
|
||
const RedForm = () => { | ||
const ref = useRef(null); | ||
return <RedInput ref={ref} />; | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/cli/migrate/__testfixtures__/list-variant-enum.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { List, Text } from '@sumup/circuit-ui'; | ||
|
||
const Ordered = () => <List ordered>primary</List>; | ||
|
||
const Unordered = () => <List unordered>Secondary</List>; | ||
|
||
const RedList = styled(List)` | ||
color: red; | ||
`; | ||
|
||
const BlueList = styled(List)` | ||
color: blue; | ||
`; | ||
|
||
const BlueText = styled(Text)` | ||
color: blue; | ||
`; | ||
|
||
const Styled = () => ( | ||
<> | ||
<RedList ordered>Ordered red</RedList> | ||
<BlueList unordered>Unordered blue</BlueList> | ||
<Text ordered>Text</Text> | ||
<BlueText unordered>Text blue</BlueText> | ||
</> | ||
); |
28 changes: 28 additions & 0 deletions
28
src/cli/migrate/__testfixtures__/list-variant-enum.output.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { List, Text } from '@sumup/circuit-ui'; | ||
|
||
const Ordered = () => <List variant="ordered">primary</List>; | ||
|
||
const Unordered = () => <List variant="unordered">Secondary</List>; | ||
|
||
const RedList = styled(List)` | ||
color: red; | ||
`; | ||
|
||
const BlueList = styled(List)` | ||
color: blue; | ||
`; | ||
|
||
const BlueText = styled(Text)` | ||
color: blue; | ||
`; | ||
|
||
const Styled = () => ( | ||
<> | ||
<RedList variant="ordered">Ordered red</RedList> | ||
<BlueList variant="unordered">Unordered blue</BlueList> | ||
<Text ordered>Text</Text> | ||
<BlueText unordered>Text blue</BlueText> | ||
</> | ||
); |
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,21 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { RadioButton, Switch } from '@sumup/circuit-ui'; | ||
|
||
const BaseRadioButton = () => <RadioButton onToggle={console.log} checked />; | ||
|
||
const RedRadioButton = styled(RadioButton)` | ||
color: red; | ||
`; | ||
|
||
const StyledRadioButton = () => ( | ||
<RedRadioButton onToggle={console.log} checked /> | ||
); | ||
|
||
const BaseSwitch = () => <Switch onToggle={console.log} checked />; | ||
|
||
const RedSwitch = styled(Switch)` | ||
color: red; | ||
`; | ||
|
||
const StyledSwitch = () => <RedSwitch onToggle={console.log} checked />; |
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,21 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { RadioButton, Switch } from '@sumup/circuit-ui'; | ||
|
||
const BaseRadioButton = () => <RadioButton onChange={console.log} checked />; | ||
|
||
const RedRadioButton = styled(RadioButton)` | ||
color: red; | ||
`; | ||
|
||
const StyledRadioButton = () => ( | ||
<RedRadioButton onChange={console.log} checked /> | ||
); | ||
|
||
const BaseSwitch = () => <Switch onChange={console.log} checked />; | ||
|
||
const RedSwitch = styled(Switch)` | ||
color: red; | ||
`; | ||
|
||
const StyledSwitch = () => <RedSwitch onChange={console.log} checked />; |
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,11 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Selector } from '@sumup/circuit-ui'; | ||
|
||
const BaseSelector = () => <Selector onClick={console.log} selected />; | ||
|
||
const RedSelector = styled(Selector)` | ||
color: red; | ||
`; | ||
|
||
const StyledSelector = () => <RedSelector onClick={console.log} selected />; |
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,11 @@ | ||
import React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Selector } from '@sumup/circuit-ui'; | ||
|
||
const BaseSelector = () => <Selector onChange={console.log} checked />; | ||
|
||
const RedSelector = styled(Selector)` | ||
color: red; | ||
`; | ||
|
||
const StyledSelector = () => <RedSelector onChange={console.log} checked />; |
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 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,47 @@ | ||
/** | ||
* Copyright 2020, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Transform, JSCodeshift, Collection } from 'jscodeshift'; | ||
|
||
import { renameJSXAttribute, findLocalNames } from './utils'; | ||
|
||
function transformFactory( | ||
j: JSCodeshift, | ||
root: Collection, | ||
componentName: string | ||
): void { | ||
const components = findLocalNames(j, root, componentName); | ||
|
||
if (!components) { | ||
return; | ||
} | ||
|
||
components.forEach(component => { | ||
renameJSXAttribute(j, root, component, 'element', 'as'); | ||
}); | ||
} | ||
|
||
const transform: Transform = (file, api) => { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
|
||
['Heading', 'SubHeading', 'Text', 'Input'].forEach(componentName => { | ||
transformFactory(j, root, componentName); | ||
}); | ||
|
||
return root.toSource(); | ||
}; | ||
|
||
export default transform; |
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
Oops, something went wrong.