-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
v12-react-update-component-prop-shadow
migrations
- Loading branch information
1 parent
f98694b
commit dc66310
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
polaris-migrator/src/migrations/v12-react-update-component-prop-shadow/tests/basic.input.tsx
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,20 @@ | ||
import React from 'react'; | ||
import {Box} from '@shopify/polaris'; | ||
|
||
declare function Child(props: any): JSX.Element; | ||
|
||
const BoxWrapper = Box; | ||
|
||
export function App() { | ||
return ( | ||
<> | ||
<Box shadow="sm" padding="0"> | ||
Hello | ||
<Child shadow="sm" /> | ||
<BoxWrapper /> | ||
<Box shadow="border-inset-experimental" /> | ||
<Box shadow="card-lg-experimental" /> | ||
</Box> | ||
</> | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
...ris-migrator/src/migrations/v12-react-update-component-prop-shadow/tests/basic.output.tsx
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,22 @@ | ||
import React from 'react'; | ||
import {Box} from '@shopify/polaris'; | ||
|
||
declare function Child(props: any): JSX.Element; | ||
|
||
const BoxWrapper = | ||
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */ | ||
Box; | ||
|
||
export function App() { | ||
return ( | ||
<> | ||
<Box shadow="200" padding="0"> | ||
Hello | ||
<Child shadow="sm" /> | ||
<BoxWrapper /> | ||
<Box shadow="border-inset" /> | ||
<Box shadow="300" /> | ||
</Box> | ||
</> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
...is-migrator/src/migrations/v12-react-update-component-prop-shadow/tests/transform.test.ts
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 {check} from '../../../utilities/check'; | ||
|
||
const transform = 'v12-react-update-component-prop-space'; | ||
const fixtures = [ | ||
{ | ||
name: 'basic', | ||
}, | ||
]; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture: fixture.name, | ||
transform, | ||
}); | ||
} |
26 changes: 26 additions & 0 deletions
26
polaris-migrator/src/migrations/v12-react-update-component-prop-shadow/transform.ts
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,26 @@ | ||
import type {FileInfo, API} from 'jscodeshift'; | ||
|
||
import {replacementMaps} from '../v12-styles-replace-custom-property-shadow/transform'; | ||
import reactUpdateComponentProp from '../react-update-component-prop/transform'; | ||
import type {ComponentReplacementOptions} from '../react-update-component-prop/utils'; | ||
import {getReplacementMaps} from '../react-update-component-prop/utils'; | ||
|
||
const normalizedReplacementMap = Object.fromEntries( | ||
Object.entries(replacementMaps['/.+/']).map(([fromValue, toValue]) => [ | ||
fromValue.replace('--p-shadow-', ''), | ||
toValue.replace('--p-shadow-', ''), | ||
]), | ||
); | ||
|
||
const componentReplacementOptions: ComponentReplacementOptions = { | ||
Box: ['shadow'], | ||
}; | ||
|
||
export default function transformer(fileInfo: FileInfo, _: API) { | ||
return reactUpdateComponentProp(fileInfo, _, { | ||
replacementMaps: getReplacementMaps( | ||
componentReplacementOptions, | ||
normalizedReplacementMap, | ||
), | ||
}); | ||
} |
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