forked from Shopify/polaris
-
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.
[Avatar] Remove customer prop and experiemntal values (Shopify#10283)
### WHY are these changes introduced? Fixes Shopify#9977 ### WHAT is this pull request doing? - [x] Remove `customer` boolean prop (make the default) - [x] Remove `-experimental` from `size` prop - [x] Update Avatar stories - [x] Update Avatar documentation examples - [x] Update `v12` migration guide - [x] Write migration for `Avatar` prop changes - [x] remove `customer` prop - [x] `size` prop mapping ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide --------- Co-authored-by: Sam Rose <11774595+samrose3@users.noreply.github.com> Co-authored-by: aveline <aveline@users.noreply.github.com>
- Loading branch information
1 parent
54ac269
commit 15352ad
Showing
65 changed files
with
336 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
'@shopify/polaris': major | ||
--- | ||
|
||
Renamed `size` prop values for the Avatar component. See the following table for the new prop mappings. | ||
|
||
| Before | After | | ||
| ------------------------- | ----------- | | ||
| `size="extraSmall"` | `size="xs"` | | ||
| `size="small"` | `size="sm"` | | ||
| `size="medium"` | `size="md"` | | ||
| `size="large"` | `size="lg"` | | ||
| `size="xl-experimental"` | `size="xl"` | | ||
| `size="2xl-experimental"` | `size="xl"` | |
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
14 changes: 14 additions & 0 deletions
14
polaris-migrator/src/migrations/v12-react-avatar-component/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,14 @@ | ||
import {check} from '../../../utilities/check'; | ||
|
||
const transform = 'v12-react-avatar-component'; | ||
const fixtures = ['v12-react-avatar-component']; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture, | ||
transform, | ||
options: { | ||
relative: fixture.includes('relative') ? true : undefined, | ||
}, | ||
}); | ||
} |
16 changes: 16 additions & 0 deletions
16
...ator/src/migrations/v12-react-avatar-component/tests/v12-react-avatar-component.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,16 @@ | ||
import React from 'react'; | ||
import {Avatar} from '@shopify/polaris'; | ||
|
||
export function App() { | ||
return ( | ||
<> | ||
<Avatar customer size="unknown" /> | ||
<Avatar customer size="extraSmall" /> | ||
<Avatar customer size="small" /> | ||
<Avatar customer size="medium" /> | ||
<Avatar customer size="large" /> | ||
<Avatar size="xl-experimental" /> | ||
<Avatar size="2xl-experimental" /> | ||
</> | ||
); | ||
} |
16 changes: 16 additions & 0 deletions
16
...tor/src/migrations/v12-react-avatar-component/tests/v12-react-avatar-component.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,16 @@ | ||
import React from 'react'; | ||
import {Avatar} from '@shopify/polaris'; | ||
|
||
export function App() { | ||
return ( | ||
<> | ||
<Avatar size="unknown" /> | ||
<Avatar size="xs" /> | ||
<Avatar size="sm" /> | ||
<Avatar size="md" /> | ||
<Avatar size="lg" /> | ||
<Avatar size="xl" /> | ||
<Avatar size="xl" /> | ||
</> | ||
); | ||
} |
66 changes: 66 additions & 0 deletions
66
polaris-migrator/src/migrations/v12-react-avatar-component/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,66 @@ | ||
import type {API, FileInfo, Options} from 'jscodeshift'; | ||
|
||
import { | ||
getImportSpecifierName, | ||
hasImportDeclaration, | ||
hasImportSpecifier, | ||
normalizeImportSourcePaths, | ||
} from '../../utilities/imports'; | ||
import {removeJSXAttributes, replaceJSXAttributes} from '../../utilities/jsx'; | ||
|
||
export interface MigrationOptions extends Options { | ||
relative?: boolean; | ||
} | ||
|
||
export default function transformer( | ||
file: FileInfo, | ||
{jscodeshift: j}: API, | ||
options: MigrationOptions, | ||
) { | ||
const source = j(file.source); | ||
|
||
if ( | ||
!options.relative && | ||
!hasImportDeclaration(j, source, '@shopify/polaris') | ||
) { | ||
return file.source; | ||
} | ||
|
||
const sourcePaths = normalizeImportSourcePaths(j, source, { | ||
relative: options.relative, | ||
from: 'Avatar', | ||
to: 'Avatar', | ||
}); | ||
|
||
if (!sourcePaths) return; | ||
if ( | ||
!hasImportSpecifier(j, source, 'Avatar', sourcePaths.from) && | ||
!hasImportSpecifier(j, source, 'AvatarProps', sourcePaths.from) | ||
) { | ||
return; | ||
} | ||
|
||
const localElementName = | ||
getImportSpecifierName(j, source, 'Avatar', sourcePaths.from) || 'Avatar'; | ||
|
||
// Find all JSX elements with the name 'Avatar' | ||
source.findJSXElements(localElementName).forEach((element) => { | ||
// Remove the 'customer' prop | ||
removeJSXAttributes(j, element, 'customer'); | ||
// Replace the 'size' prop value with the new size | ||
replaceJSXAttributes(j, element, 'size', 'size', sizeMapping); | ||
}); | ||
|
||
return source.toSource(); | ||
} | ||
|
||
// Define the mapping of old sizes to new sizes | ||
const sizeMapping = { | ||
extraSmall: 'xs', | ||
small: 'sm', | ||
medium: 'md', | ||
large: 'lg', | ||
'xl-experimental': 'xl', | ||
// 2xl-experimental is not supported in the new Avatar component | ||
'2xl-experimental': 'xl', | ||
}; |
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
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
Oops, something went wrong.