@fluentui/react-avatar 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
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 +891 -19
- package/CHANGELOG.md +336 -131
- package/MIGRATION.md +71 -66
- package/SPEC-AvatarGroup.md +185 -0
- package/SPEC.md +160 -135
- package/dist/index.d.ts +242 -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/components/Avatar/Avatar.js +7 -7
- 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 +11 -7
- package/lib/components/Avatar/renderAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatar.js +115 -87
- package/lib/components/Avatar/useAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatarStyles.js +185 -112
- package/lib/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib/components/AvatarGroup/AvatarGroup.js +15 -0
- package/lib/components/AvatarGroup/AvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/AvatarGroup.strings.js +4 -0
- package/lib/components/AvatarGroup/AvatarGroup.strings.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 +16 -0
- package/lib/components/AvatarGroup/renderAvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/useAvatarGroup.js +51 -0
- package/lib/components/AvatarGroup/useAvatarGroup.js.map +1 -0
- package/lib/components/AvatarGroup/useAvatarGroupStyles.js +37 -0
- package/lib/components/AvatarGroup/useAvatarGroupStyles.js.map +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/getInitials.js +26 -19
- package/lib/utils/getInitials.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib-commonjs/Avatar.js +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/components/Avatar/Avatar.js +8 -8
- 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 +1 -1
- package/lib-commonjs/components/Avatar/index.js.map +1 -1
- package/lib-commonjs/components/Avatar/renderAvatar.js +15 -12
- package/lib-commonjs/components/Avatar/renderAvatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/useAvatar.js +120 -92
- package/lib-commonjs/components/Avatar/useAvatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/useAvatarStyles.js +188 -115
- package/lib-commonjs/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.js +26 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.strings.js +10 -0
- package/lib-commonjs/components/AvatarGroup/AvatarGroup.strings.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 +27 -0
- package/lib-commonjs/components/AvatarGroup/renderAvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroup.js +64 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroup.js.map +1 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroupStyles.js +47 -0
- package/lib-commonjs/components/AvatarGroup/useAvatarGroupStyles.js.map +1 -0
- package/lib-commonjs/index.js +74 -2
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/getInitials.js +26 -19
- package/lib-commonjs/utils/getInitials.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/package.json +24 -25
- package/dist/react-avatar.d.ts +0 -132
- package/lib/Avatar.d.ts +0 -1
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -12
- package/lib/common/isConformant.js.map +0 -1
- package/lib/components/Avatar/Avatar.d.ts +0 -3
- package/lib/components/Avatar/Avatar.types.d.ts +0 -112
- 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 -2
- package/lib/index.d.ts +0 -1
- package/lib/utils/getInitials.d.ts +0 -9
- package/lib/utils/index.d.ts +0 -1
- package/lib-commonjs/Avatar.d.ts +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -23
- package/lib-commonjs/common/isConformant.js.map +0 -1
- package/lib-commonjs/components/Avatar/Avatar.d.ts +0 -3
- package/lib-commonjs/components/Avatar/Avatar.types.d.ts +0 -112
- 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 -2
- package/lib-commonjs/index.d.ts +0 -1
- package/lib-commonjs/utils/getInitials.d.ts +0 -9
- package/lib-commonjs/utils/index.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.types.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"Avatar.types.js","sourceRoot":"../src/","sources":["components/Avatar/Avatar.types.ts"],"names":[],"mappings":"","sourcesContent":["import { PresenceBadge } from '@fluentui/react-badge';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type AvatarSlots = {\n root: Slot<'span'>;\n\n /**\n * The Avatar's image.\n *\n * Usage e.g.: `image={{ src: '...' }}`\n */\n image?: Slot<'img'>;\n\n /**\n * (optional) Custom initials.\n *\n * It is usually not necessary to specify custom initials; by default they will be derived from the `name` prop,\n * using the `getInitials` function.\n *\n * The initials are displayed when there is no image (including while the image is loading).\n */\n initials?: Slot<'span'>;\n\n /**\n * Icon to be displayed when the avatar doesn't have an image or initials.\n *\n * @default `PersonRegular` (the default icon's size depends on the Avatar's size)\n */\n icon?: Slot<'span'>;\n\n /**\n * Badge to show the avatar's presence status.\n */\n badge?: Slot<typeof PresenceBadge>;\n};\n\n/**\n * A specific named color for the Avatar\n */\nexport type AvatarNamedColor =\n | 'dark-red'\n | 'cranberry'\n | 'red'\n | 'pumpkin'\n | 'peach'\n | 'marigold'\n | 'gold'\n | 'brass'\n | 'brown'\n | 'forest'\n | 'seafoam'\n | 'dark-green'\n | 'light-teal'\n | 'teal'\n | 'steel'\n | 'blue'\n | 'royal-blue'\n | 'cornflower'\n | 'navy'\n | 'lavender'\n | 'purple'\n | 'grape'\n | 'lilac'\n | 'pink'\n | 'magenta'\n | 'plum'\n | 'beige'\n | 'mink'\n | 'platinum'\n | 'anchor';\n\n/**\n * Sizes that can be used for the Avatar\n */\nexport type AvatarSizes = 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;\n\n/**\n * Properties for Avatar\n */\nexport type AvatarProps = Omit<ComponentProps<AvatarSlots>, 'color'> & {\n /**\n * Optional activity indicator\n * * active: the avatar will be decorated according to activeAppearance\n * * inactive: the avatar will be reduced in size and partially transparent\n * * unset: normal display\n *\n * @default unset\n */\n active?: 'active' | 'inactive' | 'unset';\n\n /**\n * The appearance when `active=\"active\"`\n *\n * @default ring\n */\n activeAppearance?: 'ring' | 'shadow' | 'ring-shadow';\n\n /**\n * The color when displaying either an icon or initials.\n * * neutral (default): gray\n * * brand: color from the brand palette\n * * colorful: picks a color from a set of pre-defined colors, based on a hash of the name (or idForColor if provided)\n * * [AvatarNamedColor]: a specific color from the theme\n *\n * @default neutral\n */\n color?: 'neutral' | 'brand' | 'colorful' | AvatarNamedColor;\n\n /**\n * Specify a string to be used instead of the name, to determine which color to use when color=\"colorful\".\n * Use this when a name is not available, but there is another unique identifier that can be used instead.\n */\n idForColor?: string | undefined;\n\n /**\n * The name of the person or entity represented by this Avatar. This should always be provided if it is available.\n *\n * The name will be used to determine the initials displayed when there is no icon, as well as provided to\n * accessibility tools.\n */\n name?: string;\n\n /**\n * The avatar can have a circular or square shape.\n * @default circular\n */\n shape?: 'circular' | 'square';\n\n /**\n * Size of the avatar in pixels.\n *\n * Size is restricted to a limited set of supported values recommended for most uses (see `AvatarSizeValue`) and\n * based on design guidelines for the Avatar control.\n *\n * Note: At size 16, if initials are displayed, only the first initial will be rendered.\n *\n * If a non-supported size is neeeded, set `size` to the next-smaller supported size, and set `width` and `height`\n * to override the rendered size.\n *\n * For example, to set the avatar to 45px in size:\n * `<Avatar size={40} style={{ width: '45px', height: '45px' }} />`\n *\n * @default 32\n */\n size?: AvatarSizes;\n};\n\n/**\n * State used in rendering Avatar\n */\nexport type AvatarState = ComponentState<AvatarSlots> &\n Required<Pick<AvatarProps, 'active' | 'activeAppearance' | 'shape' | 'size'>> & {\n /**\n * The Avatar's color, it matches props.color but with `'colorful'` resolved to a named color\n */\n color: NonNullable<Exclude<AvatarProps['color'], 'colorful'>>;\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Avatar/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Avatar.types';\nexport * from './Avatar';\nexport * from './renderAvatar';\nexport * from './useAvatar';\nexport * from './useAvatarStyles';\n"]}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { getSlots } from '@fluentui/react-utilities';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return /*#__PURE__*/React.createElement(slots.root,
|
|
3
|
+
export const renderAvatar_unstable = state => {
|
|
4
|
+
const {
|
|
5
|
+
slots,
|
|
6
|
+
slotProps
|
|
7
|
+
} = getSlots(state);
|
|
8
|
+
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
9
|
+
}, slots.initials && /*#__PURE__*/React.createElement(slots.initials, { ...slotProps.initials
|
|
10
|
+
}), slots.icon && /*#__PURE__*/React.createElement(slots.icon, { ...slotProps.icon
|
|
11
|
+
}), slots.image && /*#__PURE__*/React.createElement(slots.image, { ...slotProps.image
|
|
12
|
+
}), slots.badge && /*#__PURE__*/React.createElement(slots.badge, { ...slotProps.badge
|
|
13
|
+
}));
|
|
10
14
|
};
|
|
11
15
|
//# sourceMappingURL=renderAvatar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["components/Avatar/renderAvatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAuB;AAC1D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAc,KAAd,CAArC;AAEA,sBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,EACG,KAAK,CAAC,QAAN,iBAAkB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,QAAP,EAAe,EAAA,GAAK,SAAS,CAAC;AAAf,GAAf,CADrB,EAEG,KAAK,CAAC,IAAN,iBAAc,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,CAFjB,EAGG,KAAK,CAAC,KAAN,iBAAe,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAHlB,EAIG,KAAK,CAAC,KAAN,iBAAe,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;AAAf,GAAZ,CAJlB,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { AvatarSlots, AvatarState } from './Avatar.types';\n\nexport const renderAvatar_unstable = (state: AvatarState) => {\n const { slots, slotProps } = getSlots<AvatarSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n {slots.initials && <slots.initials {...slotProps.initials} />}\n {slots.icon && <slots.icon {...slotProps.icon} />}\n {slots.image && <slots.image {...slotProps.image} />}\n {slots.badge && <slots.badge {...slotProps.badge} />}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
|
|
@@ -1,100 +1,128 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities';
|
|
4
|
-
import { getInitials
|
|
5
|
-
import {
|
|
2
|
+
import { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';
|
|
3
|
+
import { getInitials } from '../../utils/index';
|
|
4
|
+
import { PersonRegular } from '@fluentui/react-icons';
|
|
6
5
|
import { PresenceBadge } from '@fluentui/react-badge';
|
|
7
6
|
import { useFluent } from '@fluentui/react-shared-contexts';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
color = _k === void 0 ? 'neutral' : _k; // Resolve 'colorful' to a specific color name
|
|
7
|
+
import { useMergedEventCallbacks } from '@fluentui/react-utilities';
|
|
8
|
+
export const useAvatar_unstable = (props, ref) => {
|
|
9
|
+
var _a;
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
dir
|
|
13
|
+
} = useFluent();
|
|
14
|
+
const {
|
|
15
|
+
name,
|
|
16
|
+
size = 32,
|
|
17
|
+
shape = 'circular',
|
|
18
|
+
active = 'unset',
|
|
19
|
+
activeAppearance = 'ring',
|
|
20
|
+
idForColor
|
|
21
|
+
} = props;
|
|
22
|
+
let {
|
|
23
|
+
color = 'neutral'
|
|
24
|
+
} = props; // Resolve 'colorful' to a specific color name
|
|
27
25
|
|
|
28
26
|
if (color === 'colorful') {
|
|
29
|
-
color = avatarColors[getHashCode((
|
|
27
|
+
color = avatarColors[getHashCode((_a = idForColor !== null && idForColor !== void 0 ? idForColor : name) !== null && _a !== void 0 ? _a : '') % avatarColors.length];
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
30
|
+
const baseId = useId('avatar-');
|
|
31
|
+
const root = getNativeElementProps('span', {
|
|
32
|
+
role: 'img',
|
|
33
|
+
id: baseId,
|
|
34
|
+
// aria-label and/or aria-labelledby are resolved below
|
|
35
|
+
...props,
|
|
36
|
+
ref
|
|
37
|
+
},
|
|
38
|
+
/* excludedPropNames: */
|
|
39
|
+
['name']); // Resolve the initials slot, defaulted to getInitials.
|
|
40
|
+
|
|
41
|
+
let initials = resolveShorthand(props.initials, {
|
|
42
|
+
required: true,
|
|
43
|
+
defaultProps: {
|
|
44
|
+
children: getInitials(name, dir === 'rtl', {
|
|
45
|
+
firstInitialOnly: size <= 16
|
|
46
|
+
}),
|
|
47
|
+
id: baseId + '__initials'
|
|
48
|
+
}
|
|
49
|
+
}); // Render the icon slot *only if* there aren't any initials to display.
|
|
50
|
+
|
|
51
|
+
let icon = undefined;
|
|
52
|
+
|
|
53
|
+
if (!(initials === null || initials === void 0 ? void 0 : initials.children)) {
|
|
54
|
+
initials = undefined;
|
|
55
|
+
icon = resolveShorthand(props.icon, {
|
|
56
|
+
required: true,
|
|
55
57
|
defaultProps: {
|
|
56
|
-
|
|
58
|
+
children: /*#__PURE__*/React.createElement(PersonRegular, null),
|
|
59
|
+
'aria-hidden': true
|
|
57
60
|
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
-
state.icon = resolveShorthand(props.icon, {
|
|
70
|
-
required: true,
|
|
71
|
-
defaultProps: {
|
|
72
|
-
children: getDefaultIcon(state.size)
|
|
73
|
-
}
|
|
74
|
-
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const [imageHidden, setImageHidden] = React.useState(undefined);
|
|
65
|
+
const image = resolveShorthand(props.image, {
|
|
66
|
+
defaultProps: {
|
|
67
|
+
alt: '',
|
|
68
|
+
role: 'presentation',
|
|
69
|
+
'aria-hidden': true,
|
|
70
|
+
hidden: imageHidden
|
|
75
71
|
}
|
|
72
|
+
}); // Hide the image if it fails to load and restore it on a successful load
|
|
73
|
+
|
|
74
|
+
const imageOnError = useMergedEventCallbacks(image === null || image === void 0 ? void 0 : image.onError, () => setImageHidden(true));
|
|
75
|
+
const imageOnLoad = useMergedEventCallbacks(image === null || image === void 0 ? void 0 : image.onLoad, () => setImageHidden(undefined));
|
|
76
|
+
|
|
77
|
+
if (image) {
|
|
78
|
+
image.onError = imageOnError;
|
|
79
|
+
image.onLoad = imageOnLoad;
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
const badge = resolveShorthand(props.badge, {
|
|
83
|
+
defaultProps: {
|
|
84
|
+
size: getBadgeSize(size),
|
|
85
|
+
role: 'presentation',
|
|
86
|
+
'aria-hidden': true,
|
|
87
|
+
id: baseId + '__badge'
|
|
88
|
+
}
|
|
89
|
+
}); // Resolve aria-label and/or aria-labelledby if not provided by the user
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} else {
|
|
93
|
-
return /*#__PURE__*/React.createElement(Person48Regular, null);
|
|
91
|
+
if (!root['aria-label'] && !root['aria-labelledby']) {
|
|
92
|
+
if (name) {
|
|
93
|
+
root['aria-label'] = name; // Include the badge in labelledby if it exists
|
|
94
|
+
|
|
95
|
+
if (badge) {
|
|
96
|
+
root['aria-labelledby'] = root.id + ' ' + badge.id;
|
|
97
|
+
}
|
|
98
|
+
} else if (initials) {
|
|
99
|
+
// root's aria-label should be the name, but fall back to being labelledby the initials if name is missing
|
|
100
|
+
root['aria-labelledby'] = initials.id + (badge ? ' ' + badge.id : '');
|
|
101
|
+
}
|
|
94
102
|
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
size,
|
|
106
|
+
shape,
|
|
107
|
+
active,
|
|
108
|
+
activeAppearance,
|
|
109
|
+
color,
|
|
110
|
+
components: {
|
|
111
|
+
root: 'span',
|
|
112
|
+
initials: 'span',
|
|
113
|
+
icon: 'span',
|
|
114
|
+
image: 'img',
|
|
115
|
+
badge: PresenceBadge
|
|
116
|
+
},
|
|
117
|
+
root,
|
|
118
|
+
initials,
|
|
119
|
+
icon,
|
|
120
|
+
image,
|
|
121
|
+
badge
|
|
122
|
+
};
|
|
95
123
|
};
|
|
96
124
|
|
|
97
|
-
|
|
125
|
+
const getBadgeSize = size => {
|
|
98
126
|
if (size >= 96) {
|
|
99
127
|
return 'extra-large';
|
|
100
128
|
} else if (size >= 64) {
|
|
@@ -110,14 +138,14 @@ var getBadgeSize = function (size) {
|
|
|
110
138
|
}
|
|
111
139
|
};
|
|
112
140
|
|
|
113
|
-
|
|
141
|
+
const avatarColors = ['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'];
|
|
114
142
|
|
|
115
|
-
|
|
116
|
-
|
|
143
|
+
const getHashCode = str => {
|
|
144
|
+
let hashCode = 0;
|
|
117
145
|
|
|
118
|
-
for (
|
|
119
|
-
|
|
120
|
-
|
|
146
|
+
for (let len = str.length - 1; len >= 0; len--) {
|
|
147
|
+
const ch = str.charCodeAt(len);
|
|
148
|
+
const shift = len % 8;
|
|
121
149
|
hashCode ^= (ch << shift) + (ch >> 8 - shift); // eslint-disable-line no-bitwise
|
|
122
150
|
}
|
|
123
151
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["components/Avatar/useAvatar.tsx"],"names":[],"mappings":"AAAA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AuC,GAAG,IAAI,CAA9C,EAAiD,GAAG,EAApD,EAAwD;AACtD,UAAM,EAAE,GAAG,GAAG,CAAC,UAAJ,CAAe,GAAf,CAAX;AACA,UAAM,KAAK,GAAG,GAAG,GAAG,CAApB;AACA,IAAA,QAAQ,IAAI,CAAC,EAAE,IAAI,KAAP,KAAiB,EAAE,IAAK,IAAI,KAA5B,CAAZ,CAHsD,CAGL;AAClD;;AAED,SAAO,QAAP;AACD,CATD","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { getInitials } from '../../utils/index';\nimport type { AvatarNamedColor, AvatarProps, AvatarState } from './Avatar.types';\nimport { PersonRegular } from '@fluentui/react-icons';\nimport { PresenceBadge } from '@fluentui/react-badge';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport { useMergedEventCallbacks } from '@fluentui/react-utilities';\n\nexport const useAvatar_unstable = (props: AvatarProps, ref: React.Ref<HTMLElement>): AvatarState => {\n const { dir } = useFluent();\n const { name, size = 32, shape = 'circular', active = 'unset', activeAppearance = 'ring', idForColor } = props;\n let { color = 'neutral' } = props;\n\n // Resolve 'colorful' to a specific color name\n if (color === 'colorful') {\n color = avatarColors[getHashCode(idForColor ?? name ?? '') % avatarColors.length];\n }\n\n const baseId = useId('avatar-');\n\n const root: AvatarState['root'] = getNativeElementProps(\n 'span',\n {\n role: 'img',\n id: baseId,\n // aria-label and/or aria-labelledby are resolved below\n ...props,\n ref,\n },\n /* excludedPropNames: */ ['name'],\n );\n\n // Resolve the initials slot, defaulted to getInitials.\n let initials: AvatarState['initials'] = resolveShorthand(props.initials, {\n required: true,\n defaultProps: {\n children: getInitials(name, dir === 'rtl', { firstInitialOnly: size <= 16 }),\n id: baseId + '__initials',\n },\n });\n\n // Render the icon slot *only if* there aren't any initials to display.\n let icon: AvatarState['icon'] = undefined;\n if (!initials?.children) {\n initials = undefined;\n icon = resolveShorthand(props.icon, {\n required: true,\n defaultProps: {\n children: <PersonRegular />,\n 'aria-hidden': true,\n },\n });\n }\n\n const [imageHidden, setImageHidden] = React.useState<true | undefined>(undefined);\n const image: AvatarState['image'] = resolveShorthand(props.image, {\n defaultProps: {\n alt: '',\n role: 'presentation',\n 'aria-hidden': true,\n hidden: imageHidden,\n },\n });\n\n // Hide the image if it fails to load and restore it on a successful load\n const imageOnError = useMergedEventCallbacks(image?.onError, () => setImageHidden(true));\n const imageOnLoad = useMergedEventCallbacks(image?.onLoad, () => setImageHidden(undefined));\n if (image) {\n image.onError = imageOnError;\n image.onLoad = imageOnLoad;\n }\n\n const badge: AvatarState['badge'] = resolveShorthand(props.badge, {\n defaultProps: {\n size: getBadgeSize(size),\n role: 'presentation',\n 'aria-hidden': true,\n id: baseId + '__badge',\n },\n });\n\n // Resolve aria-label and/or aria-labelledby if not provided by the user\n if (!root['aria-label'] && !root['aria-labelledby']) {\n if (name) {\n root['aria-label'] = name;\n\n // Include the badge in labelledby if it exists\n if (badge) {\n root['aria-labelledby'] = root.id + ' ' + badge.id;\n }\n } else if (initials) {\n // root's aria-label should be the name, but fall back to being labelledby the initials if name is missing\n root['aria-labelledby'] = initials.id + (badge ? ' ' + badge.id : '');\n }\n }\n\n return {\n size,\n shape,\n active,\n activeAppearance,\n color,\n\n components: {\n root: 'span',\n initials: 'span',\n icon: 'span',\n image: 'img',\n badge: PresenceBadge,\n },\n\n root,\n initials,\n icon,\n image,\n badge,\n };\n};\n\nconst getBadgeSize = (size: AvatarState['size']) => {\n if (size >= 96) {\n return 'extra-large';\n } else if (size >= 64) {\n return 'large';\n } else if (size >= 56) {\n return 'medium';\n } else if (size >= 40) {\n return 'small';\n } else if (size >= 28) {\n return 'extra-small';\n } else {\n return 'tiny';\n }\n};\n\nconst avatarColors: AvatarNamedColor[] = [\n 'dark-red',\n 'cranberry',\n 'red',\n 'pumpkin',\n 'peach',\n 'marigold',\n 'gold',\n 'brass',\n 'brown',\n 'forest',\n 'seafoam',\n 'dark-green',\n 'light-teal',\n 'teal',\n 'steel',\n 'blue',\n 'royal-blue',\n 'cornflower',\n 'navy',\n 'lavender',\n 'purple',\n 'grape',\n 'lilac',\n 'pink',\n 'magenta',\n 'plum',\n 'beige',\n 'mink',\n 'platinum',\n 'anchor',\n];\n\nconst getHashCode = (str: string): number => {\n let hashCode = 0;\n for (let len: number = str.length - 1; len >= 0; len--) {\n const ch = str.charCodeAt(len);\n const shift = len % 8;\n hashCode ^= (ch << shift) + (ch >> (8 - shift)); // eslint-disable-line no-bitwise\n }\n\n return hashCode;\n};\n"],"sourceRoot":"../src/"}
|