-
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 3 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": "esteban.230@hotmail.com", | ||
| "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
27 changes: 23 additions & 4 deletions
27
...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 { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { Label } from '@fluentui/react-label'; | ||
| import type { Avatar } from '../../Avatar'; | ||
|
|
||
| export type AvatarGroupItemSlots = { | ||
| root: Slot<'div'>; | ||
| root: NonNullable<Slot<'div'> | Slot<'li'>>; | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * 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. | ||
| */ | ||
| label?: Slot<typeof Label>; | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| /** | ||
| * 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
51 changes: 41 additions & 10 deletions
51
.../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,64 @@ | ||
| import { makeStyles, mergeClasses } 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', | ||
| label: 'fui-AvatarGroupItem__label', | ||
| }; | ||
|
|
||
| /** | ||
| * 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)': { | ||
| marginTop: tokens.spacingVerticalS, | ||
| }, | ||
|
sopranopillow marked this conversation as resolved.
|
||
| }, | ||
| }); | ||
|
|
||
| // TODO add additional classes for different states and/or slots | ||
| /** | ||
| * Styles for the label slot | ||
| */ | ||
| const useLabelStyles = makeStyles({ | ||
| overflowItem: { | ||
| marginLeft: tokens.spacingHorizontalS, | ||
| position: 'relative', | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * 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 labelStyles = useLabelStyles(); | ||
|
|
||
| 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.label) { | ||
| state.label.className = mergeClasses( | ||
| avatarGroupItemClassNames.label, | ||
| isOverflowItem && labelStyles.overflowItem, | ||
| state.label.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 '../AvatarGroup'; | ||
|
|
||
| /** | ||
| * AvatarGroupContext is provided by AvatarGroup, and is consumed by Avatar to determine default values of some props. | ||
| */ | ||
| export const AvatarGroupContext: Context<AvatarGroupContextValue> = createContext({}); |
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,2 @@ | ||
| export * from './AvatarGroupContext'; | ||
| export * from './useAvatarGroupContextValues'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-avatar/src/contexts/useAvatarGroupContextValues.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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { AvatarGroupContextValue, AvatarGroupContextValues, AvatarGroupState } from '../AvatarGroup'; | ||
|
|
||
| export const useAvatarGroupContextValues = (state: AvatarGroupState): AvatarGroupContextValues => { | ||
| const { size, layout } = state; | ||
|
|
||
| const avatarGroup: AvatarGroupContextValue = { | ||
| color: 'colorful', | ||
| layout, | ||
| size, | ||
| }; | ||
|
|
||
| return { avatarGroup }; | ||
| }; | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
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.