@fluentui/react-avatar 9.2.4 → 9.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.json +179 -1
  2. package/CHANGELOG.md +42 -2
  3. package/README-AvatarGroup.md +0 -10
  4. package/lib/components/Avatar/useAvatarStyles.js +83 -87
  5. package/lib/components/Avatar/useAvatarStyles.js.map +1 -1
  6. package/lib/components/AvatarGroupItem/useAvatarGroupItemStyles.js +5 -96
  7. package/lib/components/AvatarGroupItem/useAvatarGroupItemStyles.js.map +1 -1
  8. package/lib/components/AvatarGroupPopover/renderAvatarGroupPopover.js +3 -1
  9. package/lib/components/AvatarGroupPopover/renderAvatarGroupPopover.js.map +1 -1
  10. package/lib/components/AvatarGroupPopover/useAvatarGroupPopoverStyles.js +1 -1
  11. package/lib/components/AvatarGroupPopover/useAvatarGroupPopoverStyles.js.map +1 -1
  12. package/lib/index.js +1 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib-commonjs/components/Avatar/useAvatarStyles.js +83 -87
  15. package/lib-commonjs/components/Avatar/useAvatarStyles.js.map +1 -1
  16. package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItemStyles.js +5 -96
  17. package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItemStyles.js.map +1 -1
  18. package/lib-commonjs/components/AvatarGroupPopover/renderAvatarGroupPopover.js +3 -1
  19. package/lib-commonjs/components/AvatarGroupPopover/renderAvatarGroupPopover.js.map +1 -1
  20. package/lib-commonjs/components/AvatarGroupPopover/useAvatarGroupPopoverStyles.js +1 -1
  21. package/lib-commonjs/components/AvatarGroupPopover/useAvatarGroupPopoverStyles.js.map +1 -1
  22. package/lib-commonjs/index.js +9 -9
  23. package/lib-commonjs/index.js.map +1 -1
  24. package/package.json +15 -14
  25. package/MIGRATION.md +0 -106
  26. package/SPEC-AvatarGroup.md +0 -203
  27. package/SPEC.md +0 -172
@@ -1,203 +0,0 @@
1
- # AvatarGroup Spec
2
-
3
- ## Background
4
-
5
- AvatarGroup represents a group of multiple people or entities by taking care of the arrangement of individual Avatars in a spread, stack, or pie layout.
6
-
7
- ## Prior Art
8
-
9
- ### OpenUI
10
-
11
- There's no current research in OpenUI's website.
12
-
13
- | Library | Name | Notes |
14
- | ------------------------------------------------------------------------------------- | ------------ | --------------------------------------------------------------------------------------------- |
15
- | [Fluent UI v8](https://developer.microsoft.com/en-us/fluentui#/controls/web/facepile) | Facepile | Receives list of `IFacepilePersona` to represent each avatar. |
16
- | [Attlassian](https://atlassian.design/components/avatar-group/examples) | Avatar group | Component uses data prop, which is a list of "entries" to represent each avatar in the group. |
17
- | [Ant Design](https://ant.design/components/avatar/) | Avatar.Group | Uses subcomponent `<Avatar.Group>` to group the avatars given as children. |
18
- | [Primer React](https://primer.style/react/AvatarStack) | AvatarStack | Acts similar to a FlexBox, avatars are given as children and grouped. |
19
-
20
- ### Comparison v8 and v0
21
-
22
- There's only one existent component similar to AvatarGroup in v8 `Facepile`. v0 doesn't have an equivalent of this component.
23
-
24
- - v8 [Facepile](https://developer.microsoft.com/en-us/fluentui#/controls/web/facepile): Only offers spread layout and offers three overflow indicator styles.
25
-
26
- ## Epic issue: [#22240](https://github.com/microsoft/fluentui/issues/22240)
27
-
28
- ## Sample Code
29
-
30
- ```jsx
31
- const names = [
32
- 'Johnie McConnell',
33
- 'Allan Munger',
34
- 'Erik Nason',
35
- 'Kristin Patterson',
36
- 'Daisy Phillips',
37
- 'Carole Poland',
38
- 'Carlos Slattery',
39
- 'Robert Tolbert',
40
- 'Kevin Sturgis',
41
- 'Charlotte Waltson',
42
- 'Elliot Woodward',
43
- ];
44
-
45
- const AvatarGroup = () => {
46
- const { inlineItems, overflowItems } = partitionAvatarGroupItems({ items: names });
47
-
48
- return (
49
- <AvatarGroup {...props}>
50
- {inlineItems.map(name => (
51
- <AvatarGroupItem name={name} key={name} />
52
- ))}
53
- <AvatarGroupPopover>
54
- {overflowItems.map(name => (
55
- <AvatarGroupItem name={name} key={name} />
56
- ))}
57
- </AvatarGroupPopover>
58
- </AvatarGroup>
59
- );
60
- };
61
- ```
62
-
63
- ## Variants
64
-
65
- There are three layout variants in AvatarGroup:
66
-
67
- - Spread layout (Default): Avatars are spaced evenly.
68
- - Stack layout: Avatars are overlapped evenly.
69
- - Pie layout: Avatars are "cut" in a pie design. When there are two Avatars inline, the Avatars will be cut in half and placed side by side. When there are three Avatars inline, the first Avatar will be cut in half and other two will be downscaled by 50%.
70
- - The pie layout must have 3 or less Avatars inline and all Avatars must repeat in the `AvatarGroupPopover`. This is handled by `partitionAvatarGroupItems`.
71
- - If `partitionAvatarGroupItems` is used, the `spread` and `stack` layouts will have a maximum of 5 avatars before overflowing by default. This can be overridden via the `maxAvatars` option in `partitionAvatarGroupItems`.
72
-
73
- ## API
74
-
75
- See [AvatarGroup.types.ts](./src/components/AvatarGroup/AvatarGroup.types.ts), [AvatarGroupPopover.types.ts](./src/components/AvatarGroupPopover/AvatarGroupPopover.types.ts) and [AvatarGroupItem.types.ts](./src/components/AvatarGroupItem/AvatarGroupItem.types.ts) for more details.
76
-
77
- - `size`: Group size will override the children's current size. This is to ensure that the `AvatarGroup`'s spacing is correct because it changes depending on the group size.
78
- - `AvatarGroupPopover`: All Avatars in `AvatarGroupPopover` will have a size of 24 and have a wrapper to apply stylings.
79
- - AvatarGroupItem `color`: Can be overridden by providing a specific color on a given avatar.
80
-
81
- #### Color override example:
82
-
83
- In this example, the first AvatarGroupItem will have a `darkRed` color, while all the other Avatars have their color assigned by Avatar.
84
-
85
- ```jsx
86
- <AvatarGroup>
87
- <AvatarGroupItem color="darkRed" name="Katri Athokas" />
88
- <AvatarGroupItem name="Elvia Atkins" />
89
- <AvatarGroupItem name="Cameron Evans" />
90
- <AvatarGroupItem name="Wanda Howard" />
91
- <AvatarGroupItem name="Mona Kane" />
92
- </AvatarGroup>
93
- ```
94
-
95
- ## Structure
96
-
97
- - _**Public**_
98
-
99
- ```jsx
100
- <AvatarGroup layout="spread" size={32}>
101
- <AvatarGroupItem name="Katri Athokas" />
102
- <AvatarGroupItem name="Elvia Atkins" />
103
- <AvatarGroupItem name="Cameron Evans" />
104
- <AvatarGroupItem name="Wanda Howard" />
105
- <AvatarGroupPopover>
106
- <AvatarGroupItem name="Mona Kane" />
107
- <AvatarGroupItem name="Kristin Patterson" />
108
- <AvatarGroupItem name="Elliot Woodward" />
109
- <AvatarGroupItem name="Charlotte Waltson" />
110
- </AvatarGroupPopover>
111
- </AvatarGroup>
112
- ```
113
-
114
- - _**Internal**_
115
-
116
- ```jsx
117
- // AvatarGroup
118
- <AvatarGroupProvider value={contextValues.avatarGroup}>
119
- <slots.root {...slotProps.root} />
120
- </AvatarGroupProvider>
121
-
122
- // AvatarGroupPopover
123
- <slots.root {...(slotProps.root as PopoverProps)}>
124
- <PopoverTrigger>
125
- <slots.tooltip {...(slotProps.tooltip as TooltipProps)}>
126
- <slots.triggerButton {...slotProps.triggerButton} />
127
- </slots.tooltip>
128
- </PopoverTrigger>
129
- <slots.popoverSurface {...slotProps.popoverSurface}>
130
- <AvatarGroupProvider value={contextValues.avatarGroup}>
131
- <slots.content {...slotProps.content} />
132
- </AvatarGroupProvider>
133
- </slots.popoverSurface>
134
- </slots.root>
135
-
136
- // AvatarGroupItem
137
- <slots.root {...slotProps.root}>
138
- <slots.avatar {...slotProps.avatar} />
139
- {state.isOverflowItem && <slots.overflowLabel {...slotProps.overflowLabel} />}
140
- </slots.root>
141
- ```
142
-
143
- - _**DOM** - how the component will be rendered as HTML elements_
144
-
145
- ```html
146
- <div className="fui-AvatarGroup" role="group">
147
- <div class="fui-AvatarGroupItem">
148
- <Avatar />
149
- </div>
150
- <div class="fui-AvatarGroupItem">
151
- <Avatar />
152
- </div>
153
- <button>+1</button>
154
- </div>
155
-
156
- // on document.body
157
- <div class="fui-AvatarGroupPopover" role="dialog" aria-label="Overflow">
158
- <ul>
159
- <li class="fui-AvatarGroupItem">
160
- <Avatar />
161
- <label />
162
- </li>
163
- <li class="fui-AvatarGroupItem">
164
- <Avatar />
165
- <label />
166
- </li>
167
- </ul>
168
- </div>
169
- ```
170
-
171
- ## Migration
172
-
173
- See [v8 to v9 migration guide](https://react.fluentui.dev/?path=/docs/concepts-upgrading-from-v8-components-avatargroup-upgrade--page) for details.
174
-
175
- ## Behaviors
176
-
177
- _Explain how the component will behave in use, including:_
178
-
179
- - _AvatarGroupPopover Component States_
180
-
181
- - _Keyboard_: `triggerButton` can be interacted with the keyboard and when enter is pressed a popover that traps focus on the PopoverSurface will be rendered.
182
- - _Cursor_ and _Touch_: When overflow indicator is clicked, the popover is displayed with the avatars that overflow. When the overflow indicator is hovered, a tooltip will read `View more people.`.
183
- - _Screen readers_:
184
- - When the `triggerButton` is focused, its content will be read.
185
-
186
- - _AvatarGroupItem Component States_
187
- - _Screen readers_:
188
- - When AvatarGroupItem is rendered inline, logic is handled by `Avatar` component.
189
- - When AvatarGroupItem is rendered inside AvatarGroupPopover, the label is disabled via `aria-label` and `Avatar` will handle the screen reader.
190
-
191
- ## Accessibility
192
-
193
- Base accessibility information is included in the design document. After the spec is filled and reviewed, outcomes from it need to be communicated to design and incorporated in the design document.
194
-
195
- - There's no native element for this component.
196
-
197
- - `AvatarGroup` will have a role of `group`.
198
- - Only the `popoverTrigger` will be focusable by the keyboard.
199
- - There are no live-regions in `AvatarGroup`.
200
- - A Tooltip will appear when the `popoverTrigger` is hovered or focused.
201
- - Focus will only be trapped when the `popoverTrigger` is triggered.
202
- - The label rendered along with the Avatar inside AvatarGroupPopover is disabled via `aria-label`.
203
- - A `<ul>` with role list is rendered inside the PopoverSurface.
package/SPEC.md DELETED
@@ -1,172 +0,0 @@
1
- # Avatar
2
-
3
- **GitHub Epic issue** - [Avatar Convergence #16373](https://github.com/microsoft/fluentui/issues/16373)
4
-
5
- ## Background
6
-
7
- The Avatar component represents a person or entity. It displays the person's image, initials, or an icon, and can be either circular or square.
8
-
9
- Note: The Avatar control has been mostly implemented already. Visit [Avatar Storybook Examples](https://fluentuipr.z22.web.core.windows.net/heads/master/react-components/storybook/index.html?path=/docs/components-avatar--default) to see the current state of the implementation.
10
-
11
- ## Prior Art
12
-
13
- ### Open UI
14
-
15
- The Open UI [Avatar Research](https://open-ui.org/components/avatar.research) page (currently in PR: https://github.com/WICG/open-ui/pull/250), shows how the Avatar component is used in UI platforms across the web. There is a good consensus about the basic features such as displaying an image, initials, or an icon; as well as the shape being either a square or circle.
16
-
17
- ### Comparison of v8 and v0
18
-
19
- The existing components are:
20
-
21
- - v8 - [Persona](https://developer.microsoft.com/en-us/fluentui#/controls/web/persona)
22
- - v0 - [Avatar](https://fluentsite.z22.web.core.windows.net/0.51.4/components/avatar/definition)
23
-
24
- #### Display
25
-
26
- Both the v8 and v0 components support displaying an image, initials, and an icon.
27
-
28
- The v8 `Persona` also supports the full name and extra detail text to the right of the image. The extra detail text is specifically out of scope for the `Avatar` control, and may be added to a future component that makes use of Avatar.
29
-
30
- The v8 `Persona` appears to not support a custom icon, and can only show the default person icon, or a "?" icon
31
-
32
- #### Status/Presence Badge
33
-
34
- Both components support showing a badge to indicate status, but they have different APIs. The v8 `Persona` has an enum of preset options for the presence badge. The v0 `Avatar` supports rendering a `Status` component, which is more customizable and can render an icon, and specify different sizes and colors.
35
-
36
- ## Sample Code
37
-
38
- Display a user's initials:
39
-
40
- ```jsx
41
- <Avatar name="Miguel Garcia" />
42
- ```
43
-
44
- Display a user's image:
45
-
46
- ```jsx
47
- <Avatar size={72} name="Mona Kane" image={{ src: './MonaKane.jpg' }} />
48
- ```
49
-
50
- Display an icon only:
51
-
52
- ```jsx
53
- <Avatar aria-label="Team" icon={<PeopleTeamRegular />} shape="square" />
54
- ```
55
-
56
- Display a badge:
57
-
58
- ```jsx
59
- <Avatar name="Allan Munger" badge={{ status: 'busy' }} />
60
- ```
61
-
62
- With active state indication:
63
-
64
- ```jsx
65
- <Avatar name="Daisy Phillips" active={isUserActive ? 'active' : 'inactive'} activeAppearance="ring-shadow" />
66
- ```
67
-
68
- ## Variants
69
-
70
- ### Color
71
-
72
- The Avatar supports color variants when displaying initials or an icon:
73
-
74
- - **Neutral** - Gray (default)
75
- - **Brand** - Brand colors from the theme
76
- - **Colorful** - Pick from a list of pre-defined Avatar colors. The color will be assigned based on a hash of the name
77
- (to "randomly" assign a person a color). The color name (like `darkRed`) can also be specified explicitly in case the use case
78
- requires a different algorithm to pick the color.
79
-
80
- ### Shape
81
-
82
- The Avatar supports a circular and square (with rounded corners) shape.
83
-
84
- ## API
85
-
86
- From [Avatar.types.tsx](https://github.com/microsoft/fluentui/blob/master/packages/react-avatar/src/components/Avatar/Avatar.types.tsx):
87
-
88
- ### Slots
89
-
90
- - `root` - The root element of the Avatar.
91
- - `image` - The Avatar's image, if provided.
92
- - `initials` - The text shown when there's no image. Defaults to the initials derived from `name`.
93
- - `icon` - Icon displayed when there's no image or intials available.
94
- - `badge` - PresenceBadge to show the avatar's status.
95
-
96
- ### Props
97
-
98
- See API at [Avatar.types.ts](./src/components/Avatar/Avatar.types.ts).
99
-
100
- ## Structure
101
-
102
- JSX Tree:
103
-
104
- ```jsx
105
- <slots.root {...slotProps.root}>
106
- {slots.initials && <slots.initials {...slotProps.initials} />}
107
- {slots.icon && <slots.icon {...slotProps.icon} />}
108
- {slots.image && <slots.image {...slotProps.image} />}
109
- {slots.badge && <slots.badge {...slotProps.badge} />}
110
- </slots.root>
111
- ```
112
-
113
- Resulting HTML (in this example, "avatar-42" is an ID generated by `useId`):
114
-
115
- ```html
116
- <span class="{root}" id="avatar-42" aria-label="Miguel Garcia" aria-labelledby="avatar-42 avatar-42__badge">
117
- <!-- Only one of initials OR icon will be rendered, never both -->
118
- <span class="{initials}" aria-hidden="true">MG</span>
119
- <span class="{icon}" aria-hidden="true"><svg>...</svg></span>
120
-
121
- <!-- The Image -->
122
- <img class="{image}" src="..." aria-hidden="true" role="presentation" alt="" />
123
-
124
- <!-- The PresenceBadge's HTML is rendered here -->
125
- <span class="{PresenceBadge}" id="avatar-42__badge" aria-hidden="true">...</span>
126
- </span>
127
- ```
128
-
129
- ## Migration
130
-
131
- See [MIGRATION.md](./MIGRATION.md).
132
-
133
- ## Behaviors
134
-
135
- ### States
136
-
137
- - **Display** - The Avatar will use the following priority:
138
-
139
- - The `image` property, if provided.
140
- - Initials derived from the `name` property (this is always displayed, so it is visible while the image is loading, and if the image fails to load).
141
- - The `icon` property, if provided.
142
- - If no `image`, `icon`, or `name` is provided, the default "person" icon will be used.
143
-
144
- - **Active** - The `active` property affects the display of the avatar if set. There will be an animation when switching between active and inactive.
145
- - `unset` - Display at normal size/opacity.
146
- - `inactive` - Reduce to 80% opacity, and 87.5% size.
147
- - `active` - Adorn with an extra visual such as a ring and/or shadow, based on the `activeAppearance` property.
148
-
149
- ### Interaction
150
-
151
- The Avatar is non-interactive.
152
-
153
- - **Keyboard** - Not keyboard focusable.
154
- - **Mouse** - Nothing
155
- - **Touch** - Nothing
156
-
157
- ## Accessibility
158
-
159
- The Avatar presents as a single img element to accessibility tools, regardless of what it is displaying (image, initials, or icon).
160
-
161
- - The Avatar's root has `role="img"`
162
- - All other slots have `aria-hidden="true"`.
163
- - The `<img>` additionally has `alt="" role="presentation"`
164
-
165
- The Avatar root's label is determined using the following priority:
166
-
167
- - If `aria-label` and/or `aria-labelledby` is provided on props, do not add anything else.
168
- - If `name` is provided, set the root's `aria-label={name}`.
169
- - If a badge is present, _also_ set the root's `aria-labelledby={root.id + ' ' + badge.id}`.
170
- - This means the Avatar is labelled by both its root and badge slots, and results in a label like "Miguel Garcia Busy".
171
- - If there's no `name`, but `initials` are provided, set the root's `aria-labelledby={initials.id}`.
172
- - If a badge is present, _instead_ set the root's `aria-labelledby={initials.id + ' ' + badge.id}`.