Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Avatar to remove mergeProps #19449

Merged
merged 32 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9b0ac34
Initial work removing mergeProps from Avatar
behowell Aug 18, 2021
11088ad
Refactor Avatar to remove mergeProps
behowell Aug 19, 2021
e99f3ed
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
behowell Aug 19, 2021
031e7c1
Update from latest changes to resolveShorthand
behowell Aug 19, 2021
de4ec29
Pull the slot names out into a separate array
behowell Aug 19, 2021
f75a92f
Remove null from badge and image types
behowell Aug 19, 2021
2c45767
Move badge size and default icon to helper functions
behowell Aug 19, 2021
2d3214c
Fix up comments
behowell Aug 19, 2021
2df2848
More refactoring
behowell Aug 19, 2021
9816ed6
More refactoring
behowell Aug 19, 2021
7f2c6f7
Change files
behowell Aug 19, 2021
66fa558
Merge branch 'master' of https://github.com/behowell/fluentui into av…
behowell Aug 19, 2021
062b0e8
Move logic to resolve 'colorful' back to useAvatar
behowell Aug 19, 2021
c725042
Fix badge size
behowell Aug 19, 2021
281ee81
Remove unnecessary Partial
behowell Aug 19, 2021
be2fce9
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
behowell Aug 19, 2021
00483e4
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
behowell Sep 16, 2021
782ba9c
Update for latest changes to root-as-slot and IntrinsicShorthandProps
behowell Sep 16, 2021
34166ab
Change files
behowell Sep 16, 2021
ed381ac
merge master
ling1726 Sep 23, 2021
beba542
Fix badge typings
ling1726 Sep 23, 2021
05aa843
Change files
ling1726 Sep 23, 2021
ef4d247
fix tests
ling1726 Sep 24, 2021
ce0ce67
merge master
ling1726 Sep 24, 2021
eea6a3e
change interfaces to types
ling1726 Sep 24, 2021
c1fb930
Change files
ling1726 Sep 24, 2021
7bfa16e
update md
ling1726 Sep 24, 2021
1475b3f
revert react-utilities changes
ling1726 Sep 24, 2021
8b923f6
update md
ling1726 Sep 24, 2021
ee71de6
use undefined instaed of boolean for image
ling1726 Sep 24, 2021
be8277e
fix ver tests
ling1726 Sep 24, 2021
439ce8b
make image typings scripts
ling1726 Sep 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions apps/vr-tests/src/stories/AvatarConverged.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const AvatarList: React.FC<
key={size}
size={size}
name={names && names[i % names.length]}
image={images && images[i % images.length]}
image={images ? { src: images[i % images.length] } : undefined}
{...restOfProps}
/>
))}
Expand Down Expand Up @@ -55,7 +55,7 @@ const AvatarCustomSizeList: React.FC<
size={baseSize}
style={{ width: customSize, height: customSize }}
name={names && names[names.length - (i % names.length) - 1]}
image={images && images[images.length - (i % images.length) - 1]}
image={images ? { src: images[images.length - (i % images.length) - 1] } : undefined}
{...restOfProps}
/>
))}
Expand Down Expand Up @@ -91,20 +91,28 @@ storiesOf('Avatar Converged', module)
<Avatar name="(111)-555-1234" icon={<PersonCall20Regular />} />
<Avatar icon={<People20Regular />} shape="square" />
<Avatar name="Group" icon={<People20Regular />} shape="square" />
<Avatar image={examples.image[14]} badge="away" />
<Avatar name={examples.name[7]} image={examples.image[7]} badge="available" />
<Avatar image={{ src: examples.image[14] }} badge={{ status: 'away' }} />
<Avatar
name={examples.name[7]}
image={{ src: examples.image[7] }}
badge={{ status: 'available' }}
/>
</>
),
{ includeRtl: true, includeHighContrast: true, includeDarkMode: true },
)
.addStory('size+name', () => <AvatarList names={examples.name} />)
.addStory('size+icon+badge+square', () => <AvatarList badge="outOfOffice" shape="square" />)
.addStory('size+image+badge', () => <AvatarList images={examples.image} badge="doNotDisturb" />)
.addStory('size+icon+badge+square', () => (
<AvatarList badge={{ status: 'outOfOffice' }} shape="square" />
))
.addStory('size+image+badge', () => (
<AvatarList images={examples.image} badge={{ status: 'doNotDisturb' }} />
))
.addStory('size+inactive+badge', () => (
<AvatarList images={examples.image} active="inactive" badge="offline" />
<AvatarList images={examples.image} active="inactive" badge={{ status: 'offline' }} />
))
.addStory('size+active+badge', () => (
<AvatarList images={examples.image} active="active" badge="available" />
<AvatarList images={examples.image} active="active" badge={{ status: 'available' }} />
))
.addStory('size+active+shadow', () => (
<AvatarList images={examples.image} active="active" activeAppearance="shadow" />
Expand All @@ -120,7 +128,7 @@ storiesOf('Avatar Converged', module)
))
.addStory('customSize+image', () => <AvatarCustomSizeList images={examples.image} />)
.addStory('customSize+name+badge', () => (
<AvatarCustomSizeList names={examples.name} badge="available" />
<AvatarCustomSizeList names={examples.name} badge={{ status: 'available' }} />
))
.addStory('customSize+icon+active', () => <AvatarCustomSizeList active="active" />)
.addStory(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix badge examples to use shorthand props",
"packageName": "@fluentui/example-data",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Refactor Avatar to remove mergeProps",
"packageName": "@fluentui/react-avatar",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Revert to ObjectShorthandProps for slots to allow correct typing in Avatar",
"packageName": "@fluentui/react-badge",
"email": "[email protected]",
"dependentChangeType": "patch"
}
15 changes: 13 additions & 2 deletions packages/example-data/etc/example-data.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ export const AvatarExamples: {
}[];
readonly name: string[];
readonly image: string[];
readonly badge: readonly ["available", "away", "busy", "doNotDisturb", "offline", "outOfOffice", {
readonly badge: readonly [{
readonly status: "available";
}, {
readonly status: "away";
}, {
readonly status: "busy";
}, {
readonly status: "doNotDisturb";
}, {
readonly status: "offline";
}, {
readonly status: "outOfOffice";
}, {
readonly status: "available";
readonly outOfOffice: true;
}, {
Expand Down Expand Up @@ -172,5 +184,4 @@ export const TestImages: {
personaMale: string;
};


```
12 changes: 6 additions & 6 deletions packages/example-data/src/AvatarExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export const AvatarExamples = {
name: nameAndImage.map(p => p.name),
image: nameAndImage.map(p => p.image),
badge: [
'available',
'away',
'busy',
'doNotDisturb',
'offline',
'outOfOffice',
{ status: 'available' },
{ status: 'away' },
{ status: 'busy' },
{ status: 'doNotDisturb' },
{ status: 'offline' },
{ status: 'outOfOffice' },
{ status: 'available', outOfOffice: true },
{ status: 'away', outOfOffice: true },
{ status: 'busy', outOfOffice: true },
Expand Down
91 changes: 47 additions & 44 deletions packages/react-avatar/etc/react-avatar.api.md

Large diffs are not rendered by default.

44 changes: 27 additions & 17 deletions packages/react-avatar/src/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Basic = () => {
<Avatar />
<Avatar name={examples.name[0]} />
<Avatar size={40} icon={<Guest20Regular />} />
<Avatar size={72} name={examples.name[0]} image={examples.image[0]} />
<Avatar size={72} name={examples.name[0]} image={{ src: examples.image[0] }} />
</StoryExample>
<StoryExample title="Shape">
<Avatar name="Group" />
Expand All @@ -51,12 +51,12 @@ export const Basic = () => {
<StoryExample title="Badges">
<Avatar name={examples.name[1]} badge="available" />
<Avatar name={examples.name[2]} badge={{ status: 'available', outOfOffice: true }} />
<Avatar name={examples.name[3]} image={examples.image[3]} badge="offline" />
<Avatar name={examples.name[3]} image={{ src: examples.image[3] }} badge="offline" />
</StoryExample>
<StoryExample title="Size">
<Avatar size={20} name={examples.name[4]} image={examples.image[4]} badge="offline" />
<Avatar size={48} name={examples.name[5]} image={examples.image[5]} badge="available" />
<Avatar size={96} name={examples.name[6]} image={examples.image[6]} badge="away" />
<Avatar size={20} name={examples.name[4]} image={{ src: examples.image[4] }} badge="offline" />
<Avatar size={48} name={examples.name[5]} image={{ src: examples.image[5] }} badge="available" />
<Avatar size={96} name={examples.name[6]} image={{ src: examples.image[6] }} badge="away" />
</StoryExample>
<StoryExample title="Brand color">
<Avatar color="brand" name={examples.name[4]} badge="doNotDisturb" />
Expand All @@ -77,11 +77,11 @@ export const Basic = () => {
<StoryExample title="Active/inactive">
<div className={styles.flex}>
<Avatar name={examples.name[7]} active="active" />
<Avatar image={examples.image[8]} active="active" activeAppearance="shadow" />
<Avatar image={examples.image[9]} active="active" activeAppearance="glow" />
<Avatar image={examples.image[10]} active="active" activeAppearance="ring-shadow" />
<Avatar image={examples.image[11]} active="active" activeAppearance="ring-glow" />
<Avatar image={examples.image[12]} active="inactive" />
<Avatar image={{ src: examples.image[8] }} active="active" activeAppearance="shadow" />
<Avatar image={{ src: examples.image[9] }} active="active" activeAppearance="glow" />
<Avatar image={{ src: examples.image[10] }} active="active" activeAppearance="ring-shadow" />
<Avatar image={{ src: examples.image[11] }} active="active" activeAppearance="ring-glow" />
<Avatar image={{ src: examples.image[12] }} active="inactive" />
</div>
</StoryExample>
</>
Expand Down Expand Up @@ -179,7 +179,7 @@ export const ActiveAnimation = () => {
active={active ? 'active' : 'inactive'}
activeAppearance={activeAppearance}
name={display === 'label' ? examples.name[10] : undefined}
image={display === 'image' ? examples.image[10] : undefined}
image={display === 'image' ? { src: examples.image[10] } : undefined}
/>
</div>
<div className={flexStyles.stack}>
Expand Down Expand Up @@ -222,11 +222,21 @@ export const ActiveAnimation = () => {
export const CustomSizes = () => (
<StoryExample title="Custom size">
<Avatar name={examples.name[11]} badge="available" size={20} style={{ width: '13px', height: '13px' }} />
<Avatar image={examples.image[12]} badge="away" size={20} style={{ width: '21px', height: '21px' }} />
<Avatar image={{ src: examples.image[12] }} badge="away" size={20} style={{ width: '21px', height: '21px' }} />
<Avatar name={examples.name[13]} badge="busy" size={32} style={{ width: '34px', height: '34px' }} />
<Avatar image={examples.image[14]} badge="doNotDisturb" size={48} style={{ width: '55px', height: '55px' }} />
<Avatar
image={{ src: examples.image[14] }}
badge="doNotDisturb"
size={48}
style={{ width: '55px', height: '55px' }}
/>
<Avatar name={examples.name[15]} badge="offline" size={72} style={{ width: '89px', height: '89px' }} />
<Avatar image={examples.image[16]} badge="outOfOffice" size={128} style={{ width: '144px', height: '144px' }} />
<Avatar
image={{ src: examples.image[16] }}
badge="outOfOffice"
size={128}
style={{ width: '144px', height: '144px' }}
/>
</StoryExample>
);

Expand Down Expand Up @@ -255,7 +265,7 @@ const RobotAvatar = React.forwardRef((props: AvatarProps, ref: React.Ref<HTMLEle

const icon = size <= 40 ? <Bot20Regular /> : <Bot24Regular />;

const state = useAvatar(props, ref, { icon });
const state = useAvatar({ icon, ...props }, ref);
const styles = useRobotAvatarStyles();

state.className = mergeClasses(styles.root, styles[state.size], state.className);
Expand Down Expand Up @@ -288,7 +298,7 @@ export const AvatarPlayground = () => {
useValueSelector('name', [nameAndImage.name, nextNameAndImage, prevNameAndImage], true),
useValueSelector(
'image',
[nameAndImage.image, nextNameAndImage, prevNameAndImage],
[{ src: nameAndImage.image }, nextNameAndImage, prevNameAndImage],
true,
getFilenameFromUrl as () => string,
),
Expand Down Expand Up @@ -343,7 +353,7 @@ const AvatarExampleList: React.FC<
key={size}
size={size}
name={names && names[(i + offset) % names.length]}
image={images && images[(i + offset) % images.length]}
image={images && { src: images[(i + offset) % images.length] }}
badge={examples.badge[(i + offset) % examples.badge.length]}
{...restOfProps}
/>
Expand Down
12 changes: 7 additions & 5 deletions packages/react-avatar/src/components/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Avatar', () => {
});

it('renders an image', () => {
const component = renderer.create(<Avatar image="i.png" />);
const component = renderer.create(<Avatar image={{ src: 'i.png' }} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down Expand Up @@ -79,25 +79,27 @@ describe('Avatar', () => {
});

it('prioritizes image over initials', () => {
const component = renderer.create(<Avatar name="First Last" image="i.png" />);
const component = renderer.create(<Avatar name="First Last" image={{ src: 'i.png' }} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('prioritizes image over icon', () => {
const component = renderer.create(<Avatar icon={<span className="icon" />} image="i.png" />);
const component = renderer.create(<Avatar icon={<span className="icon" />} image={{ src: 'i.png' }} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('prioritizes image over initials and icon', () => {
const component = renderer.create(<Avatar name="First Last" icon={<span className="icon" />} image="i.png" />);
const component = renderer.create(
<Avatar name="First Last" icon={<span className="icon" />} image={{ src: 'i.png' }} />,
);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('displays a badge', () => {
const component = renderer.create(<Avatar name="First Last" badge="available" />);
const component = renderer.create(<Avatar name="First Last" badge={{ status: 'available' }} />);
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down
Loading