@fluentui/react-avatar 0.0.0-nightlyfc5cfdc52420220215.1 → 0.0.0
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.
- package/CHANGELOG.json +794 -13
- package/CHANGELOG.md +324 -133
- package/MIGRATION.md +71 -66
- package/SPEC-AvatarGroup.md +185 -0
- package/SPEC.md +160 -135
- package/dist/index.d.ts +306 -0
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/Avatar.js.map +1 -1
- package/lib/AvatarGroup.js +2 -0
- package/lib/AvatarGroup.js.map +1 -0
- package/lib/AvatarGroupItem.js +2 -0
- package/lib/AvatarGroupItem.js.map +1 -0
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/Avatar/Avatar.types.js.map +1 -1
- package/lib/components/Avatar/index.js.map +1 -1
- package/lib/components/Avatar/renderAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatar.js +7 -10
- package/lib/components/Avatar/useAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatarStyles.js +89 -74
- package/lib/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib/components/AvatarGroup/AvatarGroup.js +16 -0
- package/lib/components/AvatarGroup/AvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/AvatarGroup.types.js +2 -0
- package/lib/components/AvatarGroup/AvatarGroup.types.js.map +1 -0
- package/lib/components/AvatarGroup/index.js +6 -0
- package/lib/components/AvatarGroup/index.js.map +1 -0
- package/lib/components/AvatarGroup/renderAvatarGroup.js +43 -0
- package/lib/components/AvatarGroup/renderAvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/useAvatarGroup.js +91 -0
- package/lib/components/AvatarGroup/useAvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/useAvatarGroupStyles.js +296 -0
- package/lib/components/AvatarGroup/useAvatarGroupStyles.js.map +1 -0
- package/lib/components/AvatarGroupItem/AvatarGroupItem.js +16 -0
- package/lib/components/AvatarGroupItem/AvatarGroupItem.js.map +1 -0
- package/lib/components/AvatarGroupItem/AvatarGroupItem.types.js +2 -0
- package/lib/components/AvatarGroupItem/AvatarGroupItem.types.js.map +1 -0
- package/lib/components/AvatarGroupItem/index.js +6 -0
- package/lib/components/AvatarGroupItem/index.js.map +1 -0
- package/lib/components/AvatarGroupItem/renderAvatarGroupItem.js +17 -0
- package/lib/components/AvatarGroupItem/renderAvatarGroupItem.js.map +1 -0
- package/lib/components/AvatarGroupItem/useAvatarGroupItem.js +70 -0
- package/lib/components/AvatarGroupItem/useAvatarGroupItem.js.map +1 -0
- package/lib/components/AvatarGroupItem/useAvatarGroupItemStyles.js +356 -0
- package/lib/components/AvatarGroupItem/useAvatarGroupItemStyles.js.map +1 -0
- package/lib/contexts/AvatarGroupContext.js +7 -0
- package/lib/contexts/AvatarGroupContext.js.map +1 -0
- package/lib/contexts/AvatarGroupContext.types.js +2 -0
- package/lib/contexts/AvatarGroupContext.types.js.map +1 -0
- package/lib/contexts/index.js +2 -0
- package/lib/contexts/index.js.map +1 -0
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/utils/getInitials.js +16 -12
- package/lib/utils/getInitials.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib-commonjs/Avatar.js.map +1 -1
- package/lib-commonjs/AvatarGroup.js +10 -0
- package/lib-commonjs/AvatarGroup.js.map +1 -0
- package/lib-commonjs/AvatarGroupItem.js +10 -0
- package/lib-commonjs/AvatarGroupItem.js.map +1 -0
- package/lib-commonjs/components/Avatar/Avatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/Avatar.types.js.map +1 -1
- package/lib-commonjs/components/Avatar/index.js.map +1 -1
- package/lib-commonjs/components/Avatar/renderAvatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/useAvatar.js +7 -10
- package/lib-commonjs/components/Avatar/useAvatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/useAvatarStyles.js +91 -76
- package/lib-commonjs/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.js +27 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.types.js +6 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.types.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/index.js +18 -0
- package/lib-commonjs/components/AvatarGroup/index.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/renderAvatarGroup.js +57 -0
- package/lib-commonjs/components/AvatarGroup/renderAvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroup.js +105 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroupStyles.js +310 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroupStyles.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/AvatarGroupItem.js +27 -0
- package/lib-commonjs/components/AvatarGroupItem/AvatarGroupItem.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/AvatarGroupItem.types.js +6 -0
- package/lib-commonjs/components/AvatarGroupItem/AvatarGroupItem.types.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/index.js +18 -0
- package/lib-commonjs/components/AvatarGroupItem/index.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/renderAvatarGroupItem.js +28 -0
- package/lib-commonjs/components/AvatarGroupItem/renderAvatarGroupItem.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItem.js +84 -0
- package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItem.js.map +1 -0
- package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItemStyles.js +370 -0
- package/lib-commonjs/components/AvatarGroupItem/useAvatarGroupItemStyles.js.map +1 -0
- package/lib-commonjs/contexts/AvatarGroupContext.js +15 -0
- package/lib-commonjs/contexts/AvatarGroupContext.js.map +1 -0
- package/lib-commonjs/contexts/AvatarGroupContext.types.js +6 -0
- package/lib-commonjs/contexts/AvatarGroupContext.types.js.map +1 -0
- package/lib-commonjs/contexts/index.js +10 -0
- package/lib-commonjs/contexts/index.js.map +1 -0
- package/lib-commonjs/index.js +106 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/getInitials.js +16 -12
- package/lib-commonjs/utils/getInitials.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/package.json +26 -25
- package/dist/react-avatar.d.ts +0 -142
- package/lib/Avatar.d.ts +0 -1
- package/lib/components/Avatar/Avatar.d.ts +0 -3
- package/lib/components/Avatar/Avatar.types.d.ts +0 -107
- package/lib/components/Avatar/index.d.ts +0 -5
- package/lib/components/Avatar/renderAvatar.d.ts +0 -2
- package/lib/components/Avatar/useAvatar.d.ts +0 -3
- package/lib/components/Avatar/useAvatarStyles.d.ts +0 -3
- package/lib/index.d.ts +0 -2
- package/lib/utils/getInitials.d.ts +0 -14
- package/lib/utils/index.d.ts +0 -1
- package/lib-commonjs/Avatar.d.ts +0 -1
- package/lib-commonjs/components/Avatar/Avatar.d.ts +0 -3
- package/lib-commonjs/components/Avatar/Avatar.types.d.ts +0 -107
- package/lib-commonjs/components/Avatar/index.d.ts +0 -5
- package/lib-commonjs/components/Avatar/renderAvatar.d.ts +0 -2
- package/lib-commonjs/components/Avatar/useAvatar.d.ts +0 -3
- package/lib-commonjs/components/Avatar/useAvatarStyles.d.ts +0 -3
- package/lib-commonjs/index.d.ts +0 -2
- package/lib-commonjs/utils/getInitials.d.ts +0 -14
- package/lib-commonjs/utils/index.d.ts +0 -1
package/SPEC.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
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
8
|
|
|
9
|
-
Note: The Avatar control has been mostly implemented already. Visit [Avatar Storybook Examples](
|
|
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
10
|
|
|
11
11
|
## Prior Art
|
|
12
12
|
|
|
@@ -35,25 +35,34 @@ Both components support showing a badge to indicate status, but they have differ
|
|
|
35
35
|
|
|
36
36
|
## Sample Code
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Display a user's initials:
|
|
39
39
|
|
|
40
40
|
```jsx
|
|
41
41
|
<Avatar name="Miguel Garcia" />
|
|
42
|
-
<Avatar size={72} name="Mona Kane" image="./MonaKane.jpg" />
|
|
43
|
-
<Avatar shape="square" icon={<IDBadgeIcon />} />
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
Display a user's image:
|
|
47
45
|
|
|
48
46
|
```jsx
|
|
49
|
-
<Avatar name="
|
|
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' }} />
|
|
50
60
|
```
|
|
51
61
|
|
|
52
62
|
With active state indication:
|
|
53
63
|
|
|
54
64
|
```jsx
|
|
55
|
-
<Avatar name="Daisy Phillips" active=
|
|
56
|
-
<Avatar name="Robin Counts" active="inactive" />
|
|
65
|
+
<Avatar name="Daisy Phillips" active={isUserActive ? 'active' : 'inactive'} activeAppearance="ring-shadow" />
|
|
57
66
|
```
|
|
58
67
|
|
|
59
68
|
## Variants
|
|
@@ -65,37 +74,12 @@ The Avatar supports color variants when displaying initials or an icon:
|
|
|
65
74
|
- **Neutral** - Gray (default)
|
|
66
75
|
- **Brand** - Brand colors from the theme
|
|
67
76
|
- **Colorful** - Pick from a list of pre-defined Avatar colors. The color will be assigned based on a hash of the name
|
|
68
|
-
(to "randomly" assign a person a color). The color
|
|
77
|
+
(to "randomly" assign a person a color). The color name (like `darkRed`) can also be specified explicitly in case the use case
|
|
69
78
|
requires a different algorithm to pick the color.
|
|
70
79
|
|
|
71
80
|
### Shape
|
|
72
81
|
|
|
73
|
-
The Avatar
|
|
74
|
-
|
|
75
|
-
```jsx
|
|
76
|
-
<Avatar
|
|
77
|
-
icon={<ChatBotIcon />}
|
|
78
|
-
display="icon"
|
|
79
|
-
tokens={{
|
|
80
|
-
width: 'calc(var(--avatar-height) * 1.125)',
|
|
81
|
-
background: `url('${hexagonSvg}') 0px/contain no-repeat`,
|
|
82
|
-
borderRadius: '0',
|
|
83
|
-
}}
|
|
84
|
-
/>
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Where hexagonSvg is defined as:
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
hexagonSvg =
|
|
91
|
-
'data:image/svg+xml;utf8,' +
|
|
92
|
-
'<svg width="36" height="32" viewBox="0 0 36 32" fill="none" xmlns="http://www.w3.org/2000/svg">' +
|
|
93
|
-
'<path fill="rgb(232,232,232)" d="M0.407926 17.528C-0.135976 16.5859 -0.135975 15.4141 0.407926 14.472' +
|
|
94
|
-
'L7.91541 1.46793C8.44076 0.557947 9.39444 0 10.4245 0H25.5755C26.6056 0 27.5592 0.557951 28.0846 1.46793' +
|
|
95
|
-
'L35.5921 14.472C36.136 15.4141 36.136 16.5859 35.5921 17.528L28.0846 30.5321' +
|
|
96
|
-
'C27.5592 31.4421 26.6056 32 25.5755 32H10.4245C9.39443 32 8.44076 31.4421 7.91541 30.5321L0.407926 17.528Z"/>' +
|
|
97
|
-
'</svg>';
|
|
98
|
-
```
|
|
82
|
+
The Avatar supports a circular and square (with rounded corners) shape.
|
|
99
83
|
|
|
100
84
|
## API
|
|
101
85
|
|
|
@@ -104,97 +88,112 @@ From [Avatar.types.tsx](https://github.com/microsoft/fluentui/blob/master/packag
|
|
|
104
88
|
### Slots
|
|
105
89
|
|
|
106
90
|
- `root` - The root element of the Avatar.
|
|
107
|
-
- `image` - The Avatar's image, if
|
|
108
|
-
- `
|
|
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`.
|
|
109
93
|
- `icon` - Icon displayed when there's no image or intials available.
|
|
110
|
-
- `badge` -
|
|
94
|
+
- `badge` - PresenceBadge to show the avatar's status.
|
|
111
95
|
|
|
112
96
|
### Props
|
|
113
97
|
|
|
114
98
|
```ts
|
|
115
|
-
export type
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
99
|
+
export type AvatarSlots = {
|
|
100
|
+
root: Slot<'span'>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The Avatar's image.
|
|
104
|
+
*
|
|
105
|
+
* Usage e.g.: `image={{ src: '...' }}`
|
|
106
|
+
*/
|
|
107
|
+
image?: Slot<'img'>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* (optional) Custom initials.
|
|
111
|
+
*
|
|
112
|
+
* It is usually not necessary to specify custom initials; by default they will be derived from the `name` prop,
|
|
113
|
+
* using the `getInitials` function.
|
|
114
|
+
*
|
|
115
|
+
* The initials are displayed when there is no image (including while the image is loading).
|
|
116
|
+
*/
|
|
117
|
+
initials?: Slot<'span'>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Icon to be displayed when the avatar doesn't have an image or initials.
|
|
121
|
+
*
|
|
122
|
+
* @defaultvalue `PersonRegular` (the default icon's size depends on the Avatar's size)
|
|
123
|
+
*/
|
|
124
|
+
icon?: Slot<'span'>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Badge to show the avatar's presence status.
|
|
128
|
+
*/
|
|
129
|
+
badge?: Slot<typeof PresenceBadge>;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export type AvatarProps = Omit<ComponentProps<AvatarSlots>, 'color'> & {
|
|
133
|
+
/**
|
|
134
|
+
* The name of the person or entity represented by this Avatar. This should always be provided if it is available.
|
|
135
|
+
*
|
|
136
|
+
* The name will be used to determine the initials displayed when there is no icon, as well as provided to
|
|
137
|
+
* accessibility tools.
|
|
138
|
+
*/
|
|
139
|
+
name?: string;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Size of the avatar in pixels.
|
|
143
|
+
*
|
|
144
|
+
* Size is restricted to a limited set of supported values recommended for most uses (see `AvatarSizeValue`) and
|
|
145
|
+
* based on design guidelines for the Avatar control.
|
|
146
|
+
*
|
|
147
|
+
* If a non-supported size is neeeded, set `size` to the next-smaller supported size, and set `width` and `height`
|
|
148
|
+
* to override the rendered size.
|
|
149
|
+
*
|
|
150
|
+
* For example, to set the avatar to 45px in size:
|
|
151
|
+
* `<Avatar size={40} style={{ width: '45px', height: '45px' }} />`
|
|
152
|
+
*
|
|
153
|
+
* @defaultvalue 32
|
|
154
|
+
*/
|
|
155
|
+
size?: 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The avatar can have a circular or square shape.
|
|
159
|
+
* @defaultvalue circular
|
|
160
|
+
*/
|
|
161
|
+
shape?: 'circular' | 'square';
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Optional activity indicator
|
|
165
|
+
* * active: the avatar will be decorated according to activeAppearance
|
|
166
|
+
* * inactive: the avatar will be reduced in size and partially transparent
|
|
167
|
+
* * unset: normal display
|
|
168
|
+
*
|
|
169
|
+
* @defaultvalue unset
|
|
170
|
+
*/
|
|
171
|
+
active?: 'active' | 'inactive' | 'unset';
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The appearance when `active="active"`
|
|
175
|
+
*
|
|
176
|
+
* @defaultvalue ring
|
|
177
|
+
*/
|
|
178
|
+
activeAppearance?: 'ring' | 'shadow' | 'ring-shadow';
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The color when displaying either an icon or initials.
|
|
182
|
+
* * neutral (default): gray
|
|
183
|
+
* * brand: color from the brand palette
|
|
184
|
+
* * colorful: picks a color from a set of pre-defined colors, based on a hash of the name (or idForColor if provided)
|
|
185
|
+
* * [AvatarNamedColor]: a specific color from the theme
|
|
186
|
+
*
|
|
187
|
+
* @defaultvalue neutral
|
|
188
|
+
*/
|
|
189
|
+
color?: 'neutral' | 'brand' | 'colorful' | AvatarNamedColor;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Specify a string to be used instead of the name, to determine which color to use when color="colorful".
|
|
193
|
+
* Use this when a name is not available, but there is another unique identifier that can be used instead.
|
|
194
|
+
*/
|
|
195
|
+
idForColor?: string | undefined;
|
|
196
|
+
};
|
|
198
197
|
|
|
199
198
|
/**
|
|
200
199
|
* A specific named color for the Avatar
|
|
@@ -234,21 +233,36 @@ export type AvatarNamedColor =
|
|
|
234
233
|
|
|
235
234
|
## Structure
|
|
236
235
|
|
|
236
|
+
JSX Tree:
|
|
237
|
+
|
|
238
|
+
```jsx
|
|
239
|
+
<slots.root {...slotProps.root}>
|
|
240
|
+
{slots.initials && <slots.initials {...slotProps.initials} />}
|
|
241
|
+
{slots.icon && <slots.icon {...slotProps.icon} />}
|
|
242
|
+
{slots.image && <slots.image {...slotProps.image} />}
|
|
243
|
+
{slots.badge && <slots.badge {...slotProps.badge} />}
|
|
244
|
+
</slots.root>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Resulting HTML (in this example, "avatar-42" is an ID generated by `useId`):
|
|
248
|
+
|
|
237
249
|
```html
|
|
238
|
-
<span class="root">
|
|
239
|
-
<!--
|
|
240
|
-
<span class="
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
250
|
+
<span class="{root}" id="avatar-42" aria-label="Miguel Garcia" aria-labelledby="avatar-42 avatar-42__badge">
|
|
251
|
+
<!-- Only one of initials OR icon will be rendered, never both -->
|
|
252
|
+
<span class="{initials}" aria-hidden="true">MG</span>
|
|
253
|
+
<span class="{icon}" aria-hidden="true"><svg>...</svg></span>
|
|
254
|
+
|
|
255
|
+
<!-- The Image -->
|
|
256
|
+
<img class="{image}" src="..." aria-hidden="true" role="presentation" alt="" />
|
|
257
|
+
|
|
258
|
+
<!-- The PresenceBadge's HTML is rendered here -->
|
|
259
|
+
<span class="{PresenceBadge}" id="avatar-42__badge" aria-hidden="true">...</span>
|
|
246
260
|
</span>
|
|
247
261
|
```
|
|
248
262
|
|
|
249
263
|
## Migration
|
|
250
264
|
|
|
251
|
-
See [MIGRATION.md](
|
|
265
|
+
See [MIGRATION.md](./MIGRATION.md).
|
|
252
266
|
|
|
253
267
|
## Behaviors
|
|
254
268
|
|
|
@@ -257,8 +271,8 @@ See [MIGRATION.md](https://github.com/microsoft/fluentui/blob/master/packages/re
|
|
|
257
271
|
- **Display** - The Avatar will use the following priority:
|
|
258
272
|
|
|
259
273
|
- The `image` property, if provided.
|
|
274
|
+
- 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).
|
|
260
275
|
- The `icon` property, if provided.
|
|
261
|
-
- Initials derived from the `name` property (this is also displayed while the image is loading).
|
|
262
276
|
- If no `image`, `icon`, or `name` is provided, the default "person" icon will be used.
|
|
263
277
|
|
|
264
278
|
- **Active** - The `active` property affects the display of the avatar if set. There will be an animation when switching between active and inactive.
|
|
@@ -271,11 +285,22 @@ See [MIGRATION.md](https://github.com/microsoft/fluentui/blob/master/packages/re
|
|
|
271
285
|
The Avatar is non-interactive.
|
|
272
286
|
|
|
273
287
|
- **Keyboard** - Not keyboard focusable.
|
|
274
|
-
- **Mouse**
|
|
275
|
-
- Hover: Show tooltip (TODO: Need to figure out how the tooltip content will be generated based on the name and status).
|
|
276
|
-
- Click: No action
|
|
288
|
+
- **Mouse** - Nothing
|
|
277
289
|
- **Touch** - Nothing
|
|
278
290
|
|
|
279
291
|
## Accessibility
|
|
280
292
|
|
|
281
|
-
|
|
293
|
+
The Avatar presents as a single img element to accessibility tools, regardless of what it is displaying (image, initials, or icon).
|
|
294
|
+
|
|
295
|
+
- The Avatar's root has `role="img"`
|
|
296
|
+
- All other slots have `aria-hidden="true"`.
|
|
297
|
+
- The `<img>` additionally has `alt="" role="presentation"`
|
|
298
|
+
|
|
299
|
+
The Avatar root's label is determined using the following priority:
|
|
300
|
+
|
|
301
|
+
- If `aria-label` and/or `aria-labelledby` is provided on props, do not add anything else.
|
|
302
|
+
- If `name` is provided, set the root's `aria-label={name}`.
|
|
303
|
+
- If a badge is present, _also_ set the root's `aria-labelledby={root.id + ' ' + badge.id}`.
|
|
304
|
+
- This means the Avatar is labelled by both its root and badge slots, and results in a label like "Miguel Garcia Busy".
|
|
305
|
+
- If there's no `name`, but `initials` are provided, set the root's `aria-labelledby={initials.id}`.
|
|
306
|
+
- If a badge is present, _instead_ set the root's `aria-labelledby={initials.id + ' ' + badge.id}`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps } from '@fluentui/react-utilities';
|
|
4
|
+
import type { ComponentState } from '@fluentui/react-utilities';
|
|
5
|
+
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
6
|
+
import { PopoverSurface } from '@fluentui/react-popover';
|
|
7
|
+
import { PresenceBadge } from '@fluentui/react-badge';
|
|
8
|
+
import * as React_2 from 'react';
|
|
9
|
+
import type { Slot } from '@fluentui/react-utilities';
|
|
10
|
+
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
11
|
+
import { TooltipProps } from '@fluentui/react-tooltip';
|
|
12
|
+
|
|
13
|
+
export declare const Avatar: ForwardRefComponent<AvatarProps>;
|
|
14
|
+
|
|
15
|
+
export declare const avatarClassNames: SlotClassNames<AvatarSlots>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The AvatarGroup component represents a group of multiple people or entities by taking care of the arrangement
|
|
19
|
+
* of individual Avatars in a spread, stack, or pie layout.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AvatarGroup: ForwardRefComponent<AvatarGroupProps>;
|
|
22
|
+
|
|
23
|
+
export declare const avatarGroupClassNames: SlotClassNames<AvatarGroupSlots>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The AvatarGroupItem component represents a single person or entity.
|
|
27
|
+
* AvatarGroupItem should only be used in an AvatarGroup component.
|
|
28
|
+
*/
|
|
29
|
+
export declare const AvatarGroupItem: ForwardRefComponent<AvatarGroupItemProps>;
|
|
30
|
+
|
|
31
|
+
export declare const avatarGroupItemClassNames: SlotClassNames<AvatarGroupItemSlots>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* AvatarGroupItem Props
|
|
35
|
+
*/
|
|
36
|
+
export declare type AvatarGroupItemProps = Omit<ComponentProps<Partial<AvatarGroupItemSlots>, 'avatar'>, 'size' | 'shape'>;
|
|
37
|
+
|
|
38
|
+
export declare type AvatarGroupItemSlots = {
|
|
39
|
+
root: NonNullable<Slot<'div'>>;
|
|
40
|
+
/**
|
|
41
|
+
* Avatar that represents a person or entity.
|
|
42
|
+
*/
|
|
43
|
+
avatar: NonNullable<Slot<typeof Avatar>>;
|
|
44
|
+
/**
|
|
45
|
+
* Label used for the name of the AvatarGroupItem when rendered as an overflow item.
|
|
46
|
+
* The content of the label, by default, is the `name` prop from the `avatar` slot.
|
|
47
|
+
*/
|
|
48
|
+
overflowLabel: NonNullable<Slot<'span'>>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* State used in rendering AvatarGroupItem
|
|
53
|
+
*/
|
|
54
|
+
export declare type AvatarGroupItemState = ComponentState<AvatarGroupItemSlots> & {
|
|
55
|
+
/**
|
|
56
|
+
* Whether the Avatar is an overflow item.
|
|
57
|
+
*
|
|
58
|
+
* @default false
|
|
59
|
+
*/
|
|
60
|
+
isOverflowItem?: boolean;
|
|
61
|
+
nonOverflowAvatarsCount: number;
|
|
62
|
+
layout: AvatarGroupProps['layout'];
|
|
63
|
+
size: AvatarSizes;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* AvatarGroup Props
|
|
68
|
+
*/
|
|
69
|
+
export declare type AvatarGroupProps = ComponentProps<AvatarGroupSlots> & {
|
|
70
|
+
/**
|
|
71
|
+
* Layout the Avatars should be displayed as.
|
|
72
|
+
* @default spread
|
|
73
|
+
*/
|
|
74
|
+
layout?: 'spread' | 'stack' | 'pie';
|
|
75
|
+
/**
|
|
76
|
+
* Maximum number of Avatars to be displayed before overflowing.
|
|
77
|
+
* Note: if pie layout is used, `maxAvatars` will be ignored.
|
|
78
|
+
* @default 5
|
|
79
|
+
*/
|
|
80
|
+
maxAvatars?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Whether the overflow indicator should render an icon instead of the number of overflowed avatars.
|
|
83
|
+
* Note: The overflowIndicator will default to `icon` when the size is less than 24.
|
|
84
|
+
* @default count
|
|
85
|
+
*/
|
|
86
|
+
overflowIndicator?: 'count' | 'icon';
|
|
87
|
+
/**
|
|
88
|
+
* Size of the avatars.
|
|
89
|
+
* @default 32
|
|
90
|
+
*/
|
|
91
|
+
size?: AvatarSizes;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export declare type AvatarGroupSlots = {
|
|
95
|
+
root: NonNullable<Slot<'div'>>;
|
|
96
|
+
/**
|
|
97
|
+
* Popover trigger slot that can be used to change the overflow indicator.
|
|
98
|
+
*/
|
|
99
|
+
overflowButton?: NonNullable<Slot<'button'>>;
|
|
100
|
+
/**
|
|
101
|
+
* List that contains the overflow AvatarGroupItems.
|
|
102
|
+
*/
|
|
103
|
+
overflowContent?: NonNullable<Slot<typeof PopoverSurface>>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* State used in rendering AvatarGroup
|
|
108
|
+
*/
|
|
109
|
+
export declare type AvatarGroupState = ComponentState<AvatarGroupSlots> & Required<Pick<AvatarGroupProps, 'layout' | 'size' | 'overflowIndicator'>> & {
|
|
110
|
+
/**
|
|
111
|
+
* Whether there are more Avatars than `maxAvatars`.
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
hasOverflow: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Tooltip content for the overflow indicator.
|
|
117
|
+
*/
|
|
118
|
+
tooltipContent: TooltipProps['content'];
|
|
119
|
+
nonOverflowAvatarsCount: number;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A specific named color for the Avatar
|
|
124
|
+
*/
|
|
125
|
+
export declare type AvatarNamedColor = 'dark-red' | 'cranberry' | 'red' | 'pumpkin' | 'peach' | 'marigold' | 'gold' | 'brass' | 'brown' | 'forest' | 'seafoam' | 'dark-green' | 'light-teal' | 'teal' | 'steel' | 'blue' | 'royal-blue' | 'cornflower' | 'navy' | 'lavender' | 'purple' | 'grape' | 'lilac' | 'pink' | 'magenta' | 'plum' | 'beige' | 'mink' | 'platinum' | 'anchor';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Properties for Avatar
|
|
129
|
+
*/
|
|
130
|
+
export declare type AvatarProps = Omit<ComponentProps<AvatarSlots>, 'color'> & {
|
|
131
|
+
/**
|
|
132
|
+
* Optional activity indicator
|
|
133
|
+
* * active: the avatar will be decorated according to activeAppearance
|
|
134
|
+
* * inactive: the avatar will be reduced in size and partially transparent
|
|
135
|
+
* * unset: normal display
|
|
136
|
+
*
|
|
137
|
+
* @default unset
|
|
138
|
+
*/
|
|
139
|
+
active?: 'active' | 'inactive' | 'unset';
|
|
140
|
+
/**
|
|
141
|
+
* The appearance when `active="active"`
|
|
142
|
+
*
|
|
143
|
+
* @default ring
|
|
144
|
+
*/
|
|
145
|
+
activeAppearance?: 'ring' | 'shadow' | 'ring-shadow';
|
|
146
|
+
/**
|
|
147
|
+
* The color when displaying either an icon or initials.
|
|
148
|
+
* * neutral (default): gray
|
|
149
|
+
* * brand: color from the brand palette
|
|
150
|
+
* * colorful: picks a color from a set of pre-defined colors, based on a hash of the name (or idForColor if provided)
|
|
151
|
+
* * [AvatarNamedColor]: a specific color from the theme
|
|
152
|
+
*
|
|
153
|
+
* @default neutral
|
|
154
|
+
*/
|
|
155
|
+
color?: 'neutral' | 'brand' | 'colorful' | AvatarNamedColor;
|
|
156
|
+
/**
|
|
157
|
+
* Specify a string to be used instead of the name, to determine which color to use when color="colorful".
|
|
158
|
+
* Use this when a name is not available, but there is another unique identifier that can be used instead.
|
|
159
|
+
*/
|
|
160
|
+
idForColor?: string | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* The name of the person or entity represented by this Avatar. This should always be provided if it is available.
|
|
163
|
+
*
|
|
164
|
+
* The name will be used to determine the initials displayed when there is no icon, as well as provided to
|
|
165
|
+
* accessibility tools.
|
|
166
|
+
*/
|
|
167
|
+
name?: string;
|
|
168
|
+
/**
|
|
169
|
+
* The avatar can have a circular or square shape.
|
|
170
|
+
* @default circular
|
|
171
|
+
*/
|
|
172
|
+
shape?: 'circular' | 'square';
|
|
173
|
+
/**
|
|
174
|
+
* Size of the avatar in pixels.
|
|
175
|
+
*
|
|
176
|
+
* Size is restricted to a limited set of supported values recommended for most uses (see `AvatarSizeValue`) and
|
|
177
|
+
* based on design guidelines for the Avatar control.
|
|
178
|
+
*
|
|
179
|
+
* Note: At size 16, if initials are displayed, only the first initial will be rendered.
|
|
180
|
+
*
|
|
181
|
+
* If a non-supported size is neeeded, set `size` to the next-smaller supported size, and set `width` and `height`
|
|
182
|
+
* to override the rendered size.
|
|
183
|
+
*
|
|
184
|
+
* For example, to set the avatar to 45px in size:
|
|
185
|
+
* `<Avatar size={40} style={{ width: '45px', height: '45px' }} />`
|
|
186
|
+
*
|
|
187
|
+
* @default 32
|
|
188
|
+
*/
|
|
189
|
+
size?: AvatarSizes;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Sizes that can be used for the Avatar
|
|
194
|
+
*/
|
|
195
|
+
export declare type AvatarSizes = 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;
|
|
196
|
+
|
|
197
|
+
export declare type AvatarSlots = {
|
|
198
|
+
root: Slot<'span'>;
|
|
199
|
+
/**
|
|
200
|
+
* The Avatar's image.
|
|
201
|
+
*
|
|
202
|
+
* Usage e.g.: `image={{ src: '...' }}`
|
|
203
|
+
*/
|
|
204
|
+
image?: Slot<'img'>;
|
|
205
|
+
/**
|
|
206
|
+
* (optional) Custom initials.
|
|
207
|
+
*
|
|
208
|
+
* It is usually not necessary to specify custom initials; by default they will be derived from the `name` prop,
|
|
209
|
+
* using the `getInitials` function.
|
|
210
|
+
*
|
|
211
|
+
* The initials are displayed when there is no image (including while the image is loading).
|
|
212
|
+
*/
|
|
213
|
+
initials?: Slot<'span'>;
|
|
214
|
+
/**
|
|
215
|
+
* Icon to be displayed when the avatar doesn't have an image or initials.
|
|
216
|
+
*
|
|
217
|
+
* @default `PersonRegular` (the default icon's size depends on the Avatar's size)
|
|
218
|
+
*/
|
|
219
|
+
icon?: Slot<'span'>;
|
|
220
|
+
/**
|
|
221
|
+
* Badge to show the avatar's presence status.
|
|
222
|
+
*/
|
|
223
|
+
badge?: Slot<typeof PresenceBadge>;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* State used in rendering Avatar
|
|
228
|
+
*/
|
|
229
|
+
export declare type AvatarState = ComponentState<AvatarSlots> & Required<Pick<AvatarProps, 'active' | 'activeAppearance' | 'shape' | 'size'>> & {
|
|
230
|
+
/**
|
|
231
|
+
* The Avatar's color, it matches props.color but with `'colorful'` resolved to a named color
|
|
232
|
+
*/
|
|
233
|
+
color: NonNullable<Exclude<AvatarProps['color'], 'colorful'>>;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Regular expressions matching characters to ignore when calculating the initials.
|
|
238
|
+
*/
|
|
239
|
+
/**
|
|
240
|
+
* Get (up to 2 characters) initials based on display name of the persona.
|
|
241
|
+
*
|
|
242
|
+
* @param displayName - The full name of the person or entity
|
|
243
|
+
* @param isRtl - Whether the display is in RTL
|
|
244
|
+
* @param options - Extra options to control the behavior of getInitials
|
|
245
|
+
*
|
|
246
|
+
* @returns The 1 or 2 character initials based on the name. Or an empty string if no initials
|
|
247
|
+
* could be derived from the name.
|
|
248
|
+
*
|
|
249
|
+
* @internal
|
|
250
|
+
*/
|
|
251
|
+
export declare function getInitials(displayName: string | undefined | null, isRtl: boolean, options?: {
|
|
252
|
+
/** Should initials be generated from phone numbers (default false) */
|
|
253
|
+
allowPhoneInitials?: boolean;
|
|
254
|
+
/** Returns only the first initial */
|
|
255
|
+
firstInitialOnly?: boolean;
|
|
256
|
+
}): string;
|
|
257
|
+
|
|
258
|
+
export declare const renderAvatar_unstable: (state: AvatarState) => JSX.Element;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Render the final JSX of AvatarGroup
|
|
262
|
+
*/
|
|
263
|
+
export declare const renderAvatarGroup_unstable: (state: AvatarGroupState) => JSX.Element;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Render the final JSX of AvatarGroupItem
|
|
267
|
+
*/
|
|
268
|
+
export declare const renderAvatarGroupItem_unstable: (state: AvatarGroupItemState) => JSX.Element;
|
|
269
|
+
|
|
270
|
+
export declare const useAvatar_unstable: (props: AvatarProps, ref: React_2.Ref<HTMLElement>) => AvatarState;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Create the state required to render AvatarGroup.
|
|
274
|
+
*
|
|
275
|
+
* The returned state can be modified with hooks such as useAvatarGroupStyles_unstable,
|
|
276
|
+
* before being passed to renderAvatarGroup_unstable.
|
|
277
|
+
*
|
|
278
|
+
* @param props - props from this instance of AvatarGroup
|
|
279
|
+
* @param ref - reference to root HTMLElement of AvatarGroup
|
|
280
|
+
*/
|
|
281
|
+
export declare const useAvatarGroup_unstable: (props: AvatarGroupProps, ref: React_2.Ref<HTMLElement>) => AvatarGroupState;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Create the state required to render AvatarGroupItem.
|
|
285
|
+
*
|
|
286
|
+
* The returned state can be modified with hooks such as useAvatarGroupItemStyles_unstable,
|
|
287
|
+
* before being passed to renderAvatarGroupItem_unstable.
|
|
288
|
+
*
|
|
289
|
+
* @param props - props from this instance of AvatarGroupItem
|
|
290
|
+
* @param ref - reference to root HTMLElement of AvatarGroupItem
|
|
291
|
+
*/
|
|
292
|
+
export declare const useAvatarGroupItem_unstable: (props: AvatarGroupItemProps, ref: React_2.Ref<HTMLElement>) => AvatarGroupItemState;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Apply styling to the AvatarGroupItem slots based on the state
|
|
296
|
+
*/
|
|
297
|
+
export declare const useAvatarGroupItemStyles_unstable: (state: AvatarGroupItemState) => AvatarGroupItemState;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Apply styling to the AvatarGroup slots based on the state
|
|
301
|
+
*/
|
|
302
|
+
export declare const useAvatarGroupStyles_unstable: (state: AvatarGroupState) => AvatarGroupState;
|
|
303
|
+
|
|
304
|
+
export declare const useAvatarStyles_unstable: (state: AvatarState) => AvatarState;
|
|
305
|
+
|
|
306
|
+
export { }
|