-
Notifications
You must be signed in to change notification settings - Fork 2.9k
react-avatar: Adding AvatarGroupItem implementation and AvatarGroup context #23310
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
Merged
sopranopillow
merged 9 commits into
microsoft:master
from
sopranopillow:avatargroupitem-implementation
Jun 2, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10e93fa
Adding AvatarGroupItem implementation and AvatarGroup context.
sopranopillow 78b4225
change files
sopranopillow 5dff855
fixing lint errors
sopranopillow 9a014a7
adding requested changes
sopranopillow 9cdc2fb
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
sopranopillow db59743
updating types for root slot
sopranopillow e2acba4
updating name of overflowlabel styles
sopranopillow 560f107
Merge branch 'master' of https://github.com/microsoft/fluentui into a…
sopranopillow 525bd0e
Adding requested changes
sopranopillow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-avatar-1ab0ce5a-6046-4069-8ac6-496201496645.json
This file contains hidden or 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,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Adding AvatarGroupItem implementation and AvatarGroup context.", | ||
| "packageName": "@fluentui/react-avatar", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
25 changes: 22 additions & 3 deletions
25
...ges/react-components/react-avatar/src/components/AvatarGroupItem/AvatarGroupItem.types.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,34 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import type { Avatar } from '../../Avatar'; | ||
|
|
||
| export type AvatarGroupItemSlots = { | ||
| root: Slot<'div'>; | ||
| root: NonNullable<Slot<'div', 'li'>>; | ||
|
|
||
| /** | ||
| * Avatar that represents a person or entity. | ||
| */ | ||
| avatar: NonNullable<Slot<typeof Avatar>>; | ||
|
|
||
| /** | ||
| * Label used for the name of the AvatarGroupItem when rendered as an overflow item. | ||
| * The content of the label, by default, is the `name` prop from the `avatar` slot. | ||
| */ | ||
| overflowLabel: NonNullable<Slot<'span'>>; | ||
| }; | ||
|
|
||
| /** | ||
| * AvatarGroupItem Props | ||
| */ | ||
| export type AvatarGroupItemProps = ComponentProps<AvatarGroupItemSlots> & {}; | ||
| export type AvatarGroupItemProps = ComponentProps<Partial<AvatarGroupItemSlots>, 'avatar'>; | ||
|
|
||
| /** | ||
| * State used in rendering AvatarGroupItem | ||
| */ | ||
| export type AvatarGroupItemState = ComponentState<AvatarGroupItemSlots>; | ||
| export type AvatarGroupItemState = ComponentState<AvatarGroupItemSlots> & { | ||
| /** | ||
| * Whether the Avatar is an overflow item. | ||
| * | ||
| * @default false | ||
| */ | ||
| isOverflowItem?: boolean; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
52 changes: 41 additions & 11 deletions
52
.../react-components/react-avatar/src/components/AvatarGroupItem/useAvatarGroupItemStyles.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,33 +1,63 @@ | ||
| import { makeStyles, mergeClasses } from '@griffel/react'; | ||
| import { makeStyles, mergeClasses, shorthands } from '@griffel/react'; | ||
| import { tokens } from '@fluentui/react-theme'; | ||
| import type { AvatarGroupItemSlots, AvatarGroupItemState } from './AvatarGroupItem.types'; | ||
| import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
|
||
| export const avatarGroupItemClassNames: SlotClassNames<AvatarGroupItemSlots> = { | ||
| root: 'fui-AvatarGroupItem', | ||
| // TODO: add class names for all slots on AvatarGroupItemSlots. | ||
| // Should be of the form `<slotName>: 'fui-AvatarGroupItem__<slotName>` | ||
| avatar: 'fui-AvatarGroupItem__avatar', | ||
| overflowLabel: 'fui-AvatarGroupItem__overflowLabel', | ||
| }; | ||
|
|
||
| /** | ||
| * Styles for the root slot | ||
| */ | ||
| const useStyles = makeStyles({ | ||
| root: { | ||
| // TODO Add default styles for the root element | ||
| const useRootStyles = makeStyles({ | ||
| base: { | ||
| alignItems: 'center', | ||
| display: 'flex', | ||
| }, | ||
| overflowItem: { | ||
| '&:not(:first-child)': { | ||
| ...shorthands.padding(tokens.spacingVerticalXS, tokens.spacingVerticalXS), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // TODO add additional classes for different states and/or slots | ||
| /** | ||
| * Styles for the label slot | ||
| */ | ||
| const useOverflowLabelStyles = makeStyles({ | ||
| overflowItem: { | ||
| marginLeft: tokens.spacingHorizontalS, | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Apply styling to the AvatarGroupItem slots based on the state | ||
| */ | ||
| export const useAvatarGroupItemStyles_unstable = (state: AvatarGroupItemState): AvatarGroupItemState => { | ||
| const styles = useStyles(); | ||
| state.root.className = mergeClasses(avatarGroupItemClassNames.root, styles.root, state.root.className); | ||
| const { isOverflowItem } = state; | ||
|
|
||
| const rootStyles = useRootStyles(); | ||
| const overflowLabelStyles = useOverflowLabelStyles(); | ||
|
|
||
| state.root.className = mergeClasses( | ||
| avatarGroupItemClassNames.root, | ||
| rootStyles.base, | ||
| isOverflowItem && rootStyles.overflowItem, | ||
| state.root.className, | ||
| ); | ||
|
|
||
| state.avatar.className = mergeClasses(avatarGroupItemClassNames.avatar, state.avatar.className); | ||
|
|
||
| // TODO Add class names to slots, for example: | ||
| // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
| if (state.overflowLabel) { | ||
| state.overflowLabel.className = mergeClasses( | ||
| avatarGroupItemClassNames.overflowLabel, | ||
| isOverflowItem && overflowLabelStyles.overflowItem, | ||
| state.overflowLabel.className, | ||
| ); | ||
| } | ||
|
|
||
| return state; | ||
| }; |
8 changes: 8 additions & 0 deletions
8
packages/react-components/react-avatar/src/contexts/AvatarGroupContext.ts
This file contains hidden or 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,8 @@ | ||
| import { createContext } from '@fluentui/react-context-selector'; | ||
| import type { Context } from '@fluentui/react-context-selector'; | ||
| import type { AvatarGroupContextValue } from './AvatarGroupContext.types'; | ||
|
|
||
| /** | ||
| * AvatarGroupContext is provided by AvatarGroup, and is consumed by Avatar to determine default values of some props. | ||
| */ | ||
| export const AvatarGroupContext: Context<AvatarGroupContextValue> = createContext({}); |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-avatar/src/contexts/AvatarGroupContext.types.ts
This file contains hidden or 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,5 @@ | ||
| import type { AvatarGroupProps } from '../AvatarGroup'; | ||
|
|
||
| export type AvatarGroupContextValue = Pick<AvatarGroupProps, 'size' | 'layout'> & { | ||
| isOverflow?: boolean; | ||
| }; |
This file contains hidden or 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 @@ | ||
| export * from './AvatarGroupContext'; |
2 changes: 1 addition & 1 deletion
2
packages/react-components/react-avatar/src/stories/AvatarGroupItemDefault.stories.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import * as React from 'react'; | ||
| import { AvatarGroupItem, AvatarGroupItemProps } from '../index'; | ||
|
|
||
| export const Default = (props: Partial<AvatarGroupItemProps>) => <AvatarGroupItem {...props} />; | ||
| export const Default = (props: Partial<AvatarGroupItemProps>) => <AvatarGroupItem name="Katri Athokas" {...props} />; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.