Skip to content

Commit 0d7b99d

Browse files
committed
[Avatar] Remove customer prop and experiemntal values
1 parent dbe3d9e commit 0d7b99d

File tree

11 files changed

+58
-57
lines changed

11 files changed

+58
-57
lines changed

.changeset/hot-apples-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
Removed experimental suffix from Avatar size values

documentation/guides/migrating-from-v11-to-v12.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ Polaris v12.0.0 ([full release notes](https://github.com/Shopify/polaris/release
88

99
## Quick migration guide
1010

11+
**Avatar**
12+
13+
- Customer
14+
15+
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Avatar" --from="customer" --to=""`
16+
17+
- Size
18+
19+
`... coming soon`
20+
1121
**Layout.Section**
1222

1323
- One third:

polaris-react/src/components/ActionList/ActionList.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export function WithAPrefixAndASuffix() {
374374
},
375375
{
376376
content: 'Or there',
377-
prefix: <Avatar customer name="Farrah" size="small" />,
377+
prefix: <Avatar name="Farrah" size="small" />,
378378
suffix: <Icon source={ChevronRightMinor} />,
379379
},
380380
]}

polaris-react/src/components/AppProvider/AppProvider.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function Default(_, context) {
5858
]}
5959
renderItem={(item) => {
6060
const {id, url, name, location} = item;
61-
const media = <Avatar customer size="medium" name={name} />;
61+
const media = <Avatar size="medium" name={name} />;
6262

6363
return (
6464
<ResourceList.Item id={id} url={url} media={media}>
@@ -121,7 +121,7 @@ export function WithI18n(_, context) {
121121
]}
122122
renderItem={(item) => {
123123
const {id, url, name, location} = item;
124-
const media = <Avatar customer size="medium" name={name} />;
124+
const media = <Avatar size="medium" name={name} />;
125125

126126
return (
127127
<ResourceList.Item id={id} url={url} media={media}>

polaris-react/src/components/Avatar/Avatar.stories.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default {
2323
const sizes: {
2424
[S in NonNullable<AvatarProps['size']>]: string;
2525
} = {
26-
'2xl-experimental': 'XXL',
27-
'xl-experimental': 'XL',
26+
'2xl': 'XXL',
27+
xl: 'XL',
2828
large: 'Large',
2929
medium: 'Medium',
3030
small: 'Small',
31-
extraSmall: 'XS',
31+
xs: 'XS',
3232
};
3333

3434
const sizeEntries = Object.entries(sizes) as Entries<typeof sizes>;
@@ -84,7 +84,7 @@ export function All() {
8484
</Text>
8585
<InlineStack gap="2" blockAlign="center">
8686
{sizeEntries.map(([size]) => (
87-
<Avatar key={size} size={size} customer />
87+
<Avatar key={size} size={size} />
8888
))}
8989
</InlineStack>
9090
</BlockStack>
@@ -194,13 +194,11 @@ export function ExtraSmallInContext() {
194194
items={[
195195
{
196196
content: 'Chet Baker',
197-
prefix: <Avatar customer size="extraSmall" name="Chet Baker" />,
197+
prefix: <Avatar size="extraSmall" name="Chet Baker" />,
198198
},
199199
{
200200
content: 'Farrah Fawcett',
201-
prefix: (
202-
<Avatar customer size="extraSmall" name="Farrah Fawcett" />
203-
),
201+
prefix: <Avatar size="extraSmall" name="Farrah Fawcett" />,
204202
},
205203
]}
206204
/>

polaris-react/src/components/Avatar/Avatar.tsx

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import React, {useState, useCallback, useEffect} from 'react';
22

3-
import type {Experimental} from '../../types';
43
import {classNames, variationName} from '../../utilities/css';
54
import {useI18n} from '../../utilities/i18n';
65
import {useIsAfterInitialMount} from '../../utilities/use-is-after-initial-mount';
76
import {Image} from '../Image';
87

98
import styles from './Avatar.scss';
109

11-
type Size =
12-
| 'extraSmall'
13-
| 'small'
14-
| 'medium'
15-
| 'large'
16-
| Experimental<'xl' | '2xl'>;
10+
type Size = 'xs' | 'small' | 'medium' | 'large' | 'xl' | '2xl';
1711

1812
enum Status {
1913
Pending = 'PENDING',
@@ -24,12 +18,12 @@ enum Status {
2418
export const STYLE_CLASSES = ['one', 'two', 'three', 'four', 'five'] as const;
2519

2620
const avatarStrokeWidth: {[S in Size]: string} = {
27-
extraSmall: '3',
21+
xs: '3',
2822
small: '2.5',
2923
medium: '2.5',
3024
large: '2.5',
31-
'xl-experimental': '2',
32-
'2xl-experimental': '1.5',
25+
xl: '2',
26+
'2xl': '1.5',
3327
};
3428

3529
/**
@@ -62,8 +56,6 @@ export interface AvatarProps {
6256
name?: string;
6357
/** Initials of person to display */
6458
initials?: string;
65-
/** Whether the avatar is for a customer */
66-
customer?: boolean;
6759
/** URL of the avatar image which falls back to initials if the image fails to load */
6860
source?: string;
6961
/** Callback fired when the image fails to load */
@@ -77,7 +69,6 @@ export function Avatar({
7769
source,
7870
onError,
7971
initials,
80-
customer,
8172
size = 'medium',
8273
accessibilityLabel,
8374
}: AvatarProps) {
@@ -122,9 +113,7 @@ export function Avatar({
122113
styles.Avatar,
123114
size && styles[variationName('size', size)],
124115
hasImage && status === Status.Loaded && styles.imageHasLoaded,
125-
!customer &&
126-
!source &&
127-
styles[variationName('style', styleClass(nameString))],
116+
!source && styles[variationName('style', styleClass(nameString))],
128117
);
129118

130119
const textClassName = classNames(
@@ -170,21 +159,20 @@ export function Avatar({
170159
</>
171160
);
172161

173-
const avatarBody =
174-
customer || !initials ? (
175-
avatarPath
176-
) : (
177-
<text
178-
className={textClassName}
179-
x="50%"
180-
y="50%"
181-
dy={verticalOffset}
182-
fill="currentColor"
183-
textAnchor="middle"
184-
>
185-
{initials}
186-
</text>
187-
);
162+
const avatarBody = !initials ? (
163+
avatarPath
164+
) : (
165+
<text
166+
className={textClassName}
167+
x="50%"
168+
y="50%"
169+
dy={verticalOffset}
170+
fill="currentColor"
171+
textAnchor="middle"
172+
>
173+
{initials}
174+
</text>
175+
);
188176

189177
const svgMarkup = hasImage ? null : (
190178
<span className={styles.Initials}>

polaris-react/src/components/Avatar/tests/Avatar.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ describe('<Avatar />', () => {
4646

4747
describe('customer', () => {
4848
it('renders an inline svg', () => {
49-
const avatar = mountWithApp(<Avatar customer />);
49+
const avatar = mountWithApp(<Avatar />);
5050
expect(avatar).toContainReactComponentTimes('svg', 1);
5151
});
5252

5353
it('does not render a customer Avatar if a source is provided', () => {
5454
const src = 'image/path/';
55-
const avatar = mountWithApp(<Avatar customer source={src} />);
55+
const avatar = mountWithApp(<Avatar source={src} />);
5656
expect(avatar).not.toContainReactComponent('svg');
5757
});
5858

5959
it('does not apply a style class', () => {
6060
const src = 'image/path/';
61-
const avatar = mountWithApp(<Avatar customer source={src} />);
61+
const avatar = mountWithApp(<Avatar source={src} />);
6262
expect(avatar).toContainReactComponent('span', {
6363
className: 'Avatar sizeMedium',
6464
});

polaris-react/src/components/ResourceItem/tests/ResourceItem.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ describe('<ResourceItem />', () => {
559559
it('includes an <Avatar /> if one is provided', () => {
560560
const wrapper = mountWithApp(
561561
<ResourceListContext.Provider value={mockDefaultContext}>
562-
<ResourceItem id={itemId} url={url} media={<Avatar customer />} />
562+
<ResourceItem id={itemId} url={url} media={<Avatar />} />
563563
</ResourceListContext.Provider>,
564564
);
565565
expect(wrapper).toContainReactComponent(Avatar);

polaris.shopify.com/content/components/images-and-icons/avatar.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ examples:
3232

3333
## Best practices
3434

35-
Avatars should be one of 4 sizes:
36-
37-
- Extra small (24 x 24 px): use in tightly condensed layouts
38-
- Small (32 × 32 px): use when the medium size is too big for the layout, or when the avatar has less importance
39-
- Medium (40 × 40 px): use as the default size
40-
- Large (60 × 60 px): use when an avatar is a focal point, such as on a single customer card
35+
Avatars should be one of 6 sizes:
36+
37+
- Extra small (20 x 20 px): use in tightly condensed layouts
38+
- Small (24 × 24 px): use when the medium size is too big for the layout, or when the avatar has less importance
39+
- Medium (28 × 28 px): use as the default size
40+
- Large (32 × 32 px): use when an avatar is a focal point, such as on a single customer card
41+
- Extra large (40 × 40 px): use when an avatar is a focal point, such as on a single customer card
42+
- 2 extra large (54 × 54 px): use when an avatar is a focal point, such as on a single customer card
4143

4244
---
4345

polaris.shopify.com/pages/examples/avatar-default.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';
44

55
function AvatarExample() {
6-
return <Avatar customer name="Farrah" />;
6+
return <Avatar name="Farrah" />;
77
}
88

99
export default withPolarisExample(AvatarExample);

0 commit comments

Comments
 (0)