Skip to content

Conversation

@ling1726
Copy link
Contributor

Done as part or RFC 24790. Creates a new context in react-shared-contexts that will be consumed by the Avatar component.

This context provider can be used only internally and it is up to the component author to make sure that the provider is located as close as possible to where the overrides need to occur.

The PR includes the first usage of this context in the media slot of TableCellLayout

Fixes #24805

Done as part or RFC 24790. Creates a new context in
react-shared-contexts that will be consumed by the `Avatar` component.

This context provider can be used only internally and it is up to the
component author to make sure that the provider is located as close as
possible to where the overrides need to occur.
@fabricteam
Copy link
Collaborator

fabricteam commented Sep 15, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-alert
Alert
83.822 kB
21.029 kB
83.958 kB
21.073 kB
136 B
44 B
react-avatar
Avatar
48.692 kB
13.8 kB
48.828 kB
13.842 kB
136 B
42 B
react-avatar
AvatarGroupItem
68.66 kB
19.138 kB
68.796 kB
19.182 kB
136 B
44 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-avatar
AvatarGroup
14.95 kB
5.989 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
188.681 kB
52.366 kB
react-components
react-components: FluentProvider & webLightTheme
33.394 kB
11.007 kB
react-portal-compat
PortalCompatProvider
5.851 kB
1.964 kB
🤖 This report was generated against d7c027ced7d54b83d6cc2897350a6adb856dcfef

@size-auditor
Copy link

size-auditor bot commented Sep 15, 2022

Asset size changes

⚠️ Insufficient baseline data to detect size changes

Unable to find bundle size details for Baseline commit: a0d258e

Possible causes

  • The baseline build a0d258e is broken
  • The Size Auditor run for the baseline build a0d258e was not triggered

Recommendations

  • Please merge your branch for this Pull request with the latest master build and commit your changes once again

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 15, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 810164e:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@fabricteam
Copy link
Collaborator

fabricteam commented Sep 15, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1689 1697 5000
Button mount 1178 1179 5000
FluentProvider mount 1959 1941 5000
FluentProviderWithTheme mount 720 717 10
FluentProviderWithTheme virtual-rerender 667 679 10
FluentProviderWithTheme virtual-rerender-with-unmount 730 734 10
MakeStyles mount 2338 2311 50000
SpinButton mount 3305 3237 5000

@@ -0,0 +1,28 @@
import * as React from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you, but I think that it should be hosted in a separate package as portal-compat-context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there any real issue with including it in the react-avatar package? The rest of react-avatar should be tree shaken out of react-table if it's not used, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind, I've moved the avatar context to react-avatar in e29a351


const avatar = React.useMemo(
() => ({
size: tableAvatarSizeMap[tableSize],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, a value should be stored in state so it could be overridden with composition patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I added avatarSize to state

@ling1726 ling1726 marked this pull request as ready for review September 26, 2022 19:35
@ling1726
Copy link
Contributor Author

Could also be moved to a specific package like @fluentui/react-avatar-context WDYT @layershifter @behowell

@@ -1,5 +1,6 @@
import { PresenceBadge } from '@fluentui/react-badge';
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import type { AvatarSizes as AvatarContextSizes } from '@fluentui/react-shared-contexts';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to just export it directly?

Suggested change
import type { AvatarSizes as AvatarContextSizes } from '@fluentui/react-shared-contexts';
export type { AvatarSizes } from '@fluentui/react-shared-contexts';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that would work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e48ff9c

Comment on lines 17 to 19
<AvatarContextProvider value={contextValues.avatar}>
{slots.media && <slots.media {...slotProps.media} />}
</AvatarContextProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to include the AvatarContextProvider if there's no media content:

Suggested change
<AvatarContextProvider value={contextValues.avatar}>
{slots.media && <slots.media {...slotProps.media} />}
</AvatarContextProvider>
{slots.media && (
<AvatarContextProvider value={contextValues.avatar}>
<slots.media {...slotProps.media} />
</AvatarContextProvider>
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e29a351

import { useTableContext } from '../../contexts/tableContext';

const tableAvatarSizeMap = {
medium: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 32 instead of undefined? Unless table specifically doesn't care about the size in this state.

Suggested change
medium: undefined,
medium: 32,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 is the default so I didn't think I'd need to add it, but I can

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in f792ca2

badge={{ status: item.author.status as PresenceBadgeStatus }}
size={24}
/>
<Avatar name={item.author.label} badge={{ status: item.author.status as PresenceBadgeStatus }} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) This is unrelated to this change, but we should encourage as casts like this in stories. You could either define the entire items array as const, or possibly adding making the individual statuses as const in the object, like status: 'available' as const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bcf7dab

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I just realized I left out "not" in "should not encourage" 🤦‍♂️ but I think you figured it out 🙂

@@ -0,0 +1,28 @@
import * as React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there any real issue with including it in the react-avatar package? The rest of react-avatar should be tree shaken out of react-table if it's not used, right?

@ling1726 ling1726 requested a review from behowell September 28, 2022 13:32
Copy link
Contributor

@behowell behowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for adding this!

Comment on lines 5 to 8
/**
* Sizes for the avatar
*/
export type AvatarSizes = 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now in react-avatar, could you leave the AvatarSizes type in Avatar.types.ts, and import it here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d0a098d

Comment on lines 1 to 7
{
"type": "minor",
"comment": "feat: Implement AvatarContext",
"packageName": "@fluentui/react-shared-contexts",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in ef70cc8

@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: consume shared AvatarContext",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Update this description now that AvatarContext is implemented in react-avatar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ef70cc8

*/
export type TableCellLayoutState = ComponentState<TableCellLayoutSlots> & Pick<TableCellLayoutProps, 'appearance'>;
export type TableCellLayoutState = ComponentState<TableCellLayoutSlots> &
Pick<TableCellLayoutProps, 'appearance'> & { size: TableContextValue['size']; avatarSize: AvatarSizes | undefined };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) You don't seem to be using the new size state variable anywhere (unless I'm missing it). I suppose it doesn't hurt to have it, but is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 810164e

@ling1726 ling1726 merged commit 9357de4 into microsoft:master Sep 29, 2022
NotWoods pushed a commit to NotWoods/fluentui that referenced this pull request Nov 18, 2022
* feat: Implement shared AvatarContext

Done as part or RFC 24790. Creates a new context in
react-shared-contexts that will be consumed by the `Avatar` component.

This context provider can be used only internally and it is up to the
component author to make sure that the provider is located as close as
possible to where the overrides need to occur.

* update md

* changefiles

* improve types

* avatar sizes source of truth

* remove doc

* update mdn

* use react-avatar-context

* avatar context belongs in react-avatar

* be explicit about medium size

* avatar sizes exported from react-avatar

* remove casts for status

* update md

* update import

* define avatar size in avatar types

* update changefiles

* update table types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avatar size should update with Table size prop

6 participants