@fluentui/react-avatar 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.1
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 +373 -20
- package/CHANGELOG.md +79 -12
- package/dist/react-avatar.d.ts +46 -36
- package/lib/components/Avatar/Avatar.js +7 -7
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/Avatar/Avatar.types.d.ts +27 -32
- package/lib/components/Avatar/renderAvatar.d.ts +1 -1
- package/lib/components/Avatar/renderAvatar.js +11 -7
- package/lib/components/Avatar/renderAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatar.d.ts +1 -1
- package/lib/components/Avatar/useAvatar.js +103 -86
- package/lib/components/Avatar/useAvatar.js.map +1 -1
- package/lib/components/Avatar/useAvatarStyles.d.ts +2 -1
- package/lib/components/Avatar/useAvatarStyles.js +160 -102
- package/lib/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/getInitials.d.ts +6 -1
- package/lib/utils/getInitials.js +13 -8
- package/lib/utils/getInitials.js.map +1 -1
- package/lib-commonjs/Avatar.js +1 -1
- 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.d.ts +27 -32
- package/lib-commonjs/components/Avatar/index.js +1 -1
- package/lib-commonjs/components/Avatar/renderAvatar.d.ts +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.d.ts +1 -1
- package/lib-commonjs/components/Avatar/useAvatar.js +109 -93
- package/lib-commonjs/components/Avatar/useAvatar.js.map +1 -1
- package/lib-commonjs/components/Avatar/useAvatarStyles.d.ts +2 -1
- package/lib-commonjs/components/Avatar/useAvatarStyles.js +165 -107
- package/lib-commonjs/components/Avatar/useAvatarStyles.js.map +1 -1
- package/lib-commonjs/index.d.ts +1 -0
- package/lib-commonjs/index.js +3 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/getInitials.d.ts +6 -1
- package/lib-commonjs/utils/getInitials.js +13 -8
- package/lib-commonjs/utils/getInitials.js.map +1 -1
- package/package.json +11 -13
- 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-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/dist/react-avatar.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import type { ComponentProps } from '@fluentui/react-utilities';
|
|
2
2
|
import type { ComponentState } from '@fluentui/react-utilities';
|
|
3
3
|
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
|
4
|
-
import
|
|
5
|
-
import type { ObjectShorthandProps } from '@fluentui/react-utilities';
|
|
6
|
-
import type { PresenceBadgeProps } from '@fluentui/react-badge';
|
|
4
|
+
import { PresenceBadge } from '@fluentui/react-badge';
|
|
7
5
|
import * as React_2 from 'react';
|
|
8
|
-
import type {
|
|
6
|
+
import type { Slot } from '@fluentui/react-utilities';
|
|
9
7
|
|
|
10
8
|
export declare const Avatar: ForwardRefComponent<AvatarProps>;
|
|
11
9
|
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
name: string;
|
|
10
|
+
export declare const avatarClassName = "fui-Avatar";
|
|
11
|
+
|
|
12
|
+
declare type AvatarCommons = {
|
|
17
13
|
/**
|
|
18
|
-
*
|
|
14
|
+
* The name of the person or entity represented by this Avatar. This should always be provided if it is available.
|
|
15
|
+
*
|
|
16
|
+
* The name will be used to determine the initials displayed when there is no icon, as well as provided to
|
|
17
|
+
* accessibility tools.
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
name?: string;
|
|
21
20
|
/**
|
|
22
21
|
* Size of the avatar in pixels.
|
|
23
22
|
*
|
|
@@ -52,7 +51,7 @@ export declare type AvatarCommons = Omit<React_2.HTMLAttributes<HTMLElement>, 'c
|
|
|
52
51
|
*
|
|
53
52
|
* @defaultvalue ring
|
|
54
53
|
*/
|
|
55
|
-
activeAppearance: 'ring' | 'shadow' | '
|
|
54
|
+
activeAppearance: 'ring' | 'shadow' | 'ring-shadow';
|
|
56
55
|
/**
|
|
57
56
|
* The color when displaying either an icon or initials.
|
|
58
57
|
* * neutral (default): gray
|
|
@@ -78,39 +77,35 @@ export declare type AvatarNamedColor = 'darkRed' | 'cranberry' | 'red' | 'pumpki
|
|
|
78
77
|
/**
|
|
79
78
|
* Properties for Avatar
|
|
80
79
|
*/
|
|
81
|
-
export declare type AvatarProps = Omit<ComponentProps<AvatarSlots>, '
|
|
82
|
-
/**
|
|
83
|
-
* The Avatar's image. Cannot be typed as a normal slot since it should not accept any children
|
|
84
|
-
* but can accept a children render function.
|
|
85
|
-
*/
|
|
86
|
-
image?: Omit<IntrinsicShorthandProps<'img'>, 'children'> & {
|
|
87
|
-
children?: ShorthandRenderFunction<React_2.HTMLAttributes<HTMLImageElement>>;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
80
|
+
export declare type AvatarProps = Omit<ComponentProps<AvatarSlots>, 'color'> & Partial<AvatarCommons>;
|
|
90
81
|
|
|
91
82
|
export declare type AvatarSlots = {
|
|
92
|
-
root:
|
|
93
|
-
children?: never;
|
|
94
|
-
};
|
|
83
|
+
root: Slot<'span'>;
|
|
95
84
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
85
|
+
* The Avatar's image.
|
|
86
|
+
*
|
|
87
|
+
* Usage e.g.: `image={{ src: '...' }}`
|
|
98
88
|
*/
|
|
99
|
-
image?:
|
|
89
|
+
image?: Slot<'img'>;
|
|
100
90
|
/**
|
|
101
|
-
*
|
|
91
|
+
* (optional) Custom initials.
|
|
92
|
+
*
|
|
93
|
+
* It is usually not necessary to specify custom initials; by default they will be derived from the `name` prop,
|
|
94
|
+
* using the `getInitials` function.
|
|
95
|
+
*
|
|
96
|
+
* The initials are displayed when there is no image (including while the image is loading).
|
|
102
97
|
*/
|
|
103
|
-
|
|
98
|
+
initials?: Slot<'span'>;
|
|
104
99
|
/**
|
|
105
|
-
* Icon to be displayed when the avatar doesn't have an image or
|
|
100
|
+
* Icon to be displayed when the avatar doesn't have an image or initials.
|
|
106
101
|
*
|
|
107
|
-
* @defaultvalue `
|
|
102
|
+
* @defaultvalue `PersonRegular` (the default icon's size depends on the Avatar's size)
|
|
108
103
|
*/
|
|
109
|
-
icon?:
|
|
104
|
+
icon?: Slot<'span'>;
|
|
110
105
|
/**
|
|
111
106
|
* Badge to show the avatar's presence status.
|
|
112
107
|
*/
|
|
113
|
-
badge?:
|
|
108
|
+
badge?: Slot<typeof PresenceBadge>;
|
|
114
109
|
};
|
|
115
110
|
|
|
116
111
|
/**
|
|
@@ -123,10 +118,25 @@ export declare type AvatarState = ComponentState<AvatarSlots> & AvatarCommons &
|
|
|
123
118
|
color: Exclude<AvatarCommons['color'], 'colorful'>;
|
|
124
119
|
};
|
|
125
120
|
|
|
126
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Regular expressions matching characters to ignore when calculating the initials.
|
|
123
|
+
*/
|
|
124
|
+
/**
|
|
125
|
+
* Get (up to 2 characters) initials based on display name of the persona.
|
|
126
|
+
*
|
|
127
|
+
* @param displayName - The full name of the person or entity
|
|
128
|
+
* @param isRtl - Whether the display is in RTL
|
|
129
|
+
* @param allowPhoneInitials - Should initials be generated from phone numbers (default false)
|
|
130
|
+
*
|
|
131
|
+
* @returns The 1 or 2 character initials based on the name. Or an empty string if no initials
|
|
132
|
+
* could be derived from the name.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getInitials(displayName: string | undefined | null, isRtl: boolean, allowPhoneInitials?: boolean): string;
|
|
135
|
+
|
|
136
|
+
export declare const renderAvatar_unstable: (state: AvatarState) => JSX.Element;
|
|
127
137
|
|
|
128
|
-
export declare const
|
|
138
|
+
export declare const useAvatar_unstable: (props: AvatarProps, ref: React_2.Ref<HTMLElement>) => AvatarState;
|
|
129
139
|
|
|
130
|
-
export declare const
|
|
140
|
+
export declare const useAvatarStyles_unstable: (state: AvatarState) => AvatarState;
|
|
131
141
|
|
|
132
142
|
export { }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
2
|
+
import { renderAvatar_unstable } from './renderAvatar';
|
|
3
|
+
import { useAvatar_unstable } from './useAvatar';
|
|
4
|
+
import { useAvatarStyles_unstable } from './useAvatarStyles';
|
|
5
|
+
export const Avatar = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
6
|
+
const state = useAvatar_unstable(props, ref);
|
|
7
|
+
useAvatarStyles_unstable(state);
|
|
8
|
+
return renderAvatar_unstable(state);
|
|
9
9
|
});
|
|
10
10
|
Avatar.displayName = 'Avatar';
|
|
11
11
|
//# sourceMappingURL=Avatar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Avatar/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Avatar/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AACA,SAAS,kBAAT,QAAmC,aAAnC;AACA,SAAS,wBAAT,QAAyC,mBAAzC;AAIA,OAAO,MAAM,MAAM,gBAAqC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AACtF,QAAM,KAAK,GAAG,kBAAkB,CAAC,KAAD,EAAQ,GAAR,CAAhC;AAEA,EAAA,wBAAwB,CAAC,KAAD,CAAxB;AAEA,SAAO,qBAAqB,CAAC,KAAD,CAA5B;AACD,CANuD,CAAjD;AAQP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourceRoot":""}
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ComponentProps, ComponentState,
|
|
3
|
-
import type { PresenceBadgeProps } from '@fluentui/react-badge';
|
|
1
|
+
import { PresenceBadge } from '@fluentui/react-badge';
|
|
2
|
+
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
|
4
3
|
export declare type AvatarSlots = {
|
|
5
|
-
root:
|
|
6
|
-
children?: never;
|
|
7
|
-
};
|
|
4
|
+
root: Slot<'span'>;
|
|
8
5
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* The Avatar's image.
|
|
7
|
+
*
|
|
8
|
+
* Usage e.g.: `image={{ src: '...' }}`
|
|
11
9
|
*/
|
|
12
|
-
image?:
|
|
10
|
+
image?: Slot<'img'>;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* (optional) Custom initials.
|
|
13
|
+
*
|
|
14
|
+
* It is usually not necessary to specify custom initials; by default they will be derived from the `name` prop,
|
|
15
|
+
* using the `getInitials` function.
|
|
16
|
+
*
|
|
17
|
+
* The initials are displayed when there is no image (including while the image is loading).
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
initials?: Slot<'span'>;
|
|
17
20
|
/**
|
|
18
|
-
* Icon to be displayed when the avatar doesn't have an image or
|
|
21
|
+
* Icon to be displayed when the avatar doesn't have an image or initials.
|
|
19
22
|
*
|
|
20
|
-
* @defaultvalue `
|
|
23
|
+
* @defaultvalue `PersonRegular` (the default icon's size depends on the Avatar's size)
|
|
21
24
|
*/
|
|
22
|
-
icon?:
|
|
25
|
+
icon?: Slot<'span'>;
|
|
23
26
|
/**
|
|
24
27
|
* Badge to show the avatar's presence status.
|
|
25
28
|
*/
|
|
26
|
-
badge?:
|
|
29
|
+
badge?: Slot<typeof PresenceBadge>;
|
|
27
30
|
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The name used for displaying the initials of the avatar if the image is not provided
|
|
31
|
-
*/
|
|
32
|
-
name: string;
|
|
31
|
+
declare type AvatarCommons = {
|
|
33
32
|
/**
|
|
34
|
-
*
|
|
33
|
+
* The name of the person or entity represented by this Avatar. This should always be provided if it is available.
|
|
34
|
+
*
|
|
35
|
+
* The name will be used to determine the initials displayed when there is no icon, as well as provided to
|
|
36
|
+
* accessibility tools.
|
|
35
37
|
*/
|
|
36
|
-
|
|
38
|
+
name?: string;
|
|
37
39
|
/**
|
|
38
40
|
* Size of the avatar in pixels.
|
|
39
41
|
*
|
|
@@ -68,7 +70,7 @@ export declare type AvatarCommons = Omit<React.HTMLAttributes<HTMLElement>, 'chi
|
|
|
68
70
|
*
|
|
69
71
|
* @defaultvalue ring
|
|
70
72
|
*/
|
|
71
|
-
activeAppearance: 'ring' | 'shadow' | '
|
|
73
|
+
activeAppearance: 'ring' | 'shadow' | 'ring-shadow';
|
|
72
74
|
/**
|
|
73
75
|
* The color when displaying either an icon or initials.
|
|
74
76
|
* * neutral (default): gray
|
|
@@ -92,15 +94,7 @@ export declare type AvatarNamedColor = 'darkRed' | 'cranberry' | 'red' | 'pumpki
|
|
|
92
94
|
/**
|
|
93
95
|
* Properties for Avatar
|
|
94
96
|
*/
|
|
95
|
-
export declare type AvatarProps = Omit<ComponentProps<AvatarSlots>, '
|
|
96
|
-
/**
|
|
97
|
-
* The Avatar's image. Cannot be typed as a normal slot since it should not accept any children
|
|
98
|
-
* but can accept a children render function.
|
|
99
|
-
*/
|
|
100
|
-
image?: Omit<IntrinsicShorthandProps<'img'>, 'children'> & {
|
|
101
|
-
children?: ShorthandRenderFunction<React.HTMLAttributes<HTMLImageElement>>;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
97
|
+
export declare type AvatarProps = Omit<ComponentProps<AvatarSlots>, 'color'> & Partial<AvatarCommons>;
|
|
104
98
|
/**
|
|
105
99
|
* State used in rendering Avatar
|
|
106
100
|
*/
|
|
@@ -110,3 +104,4 @@ export declare type AvatarState = ComponentState<AvatarSlots> & AvatarCommons &
|
|
|
110
104
|
*/
|
|
111
105
|
color: Exclude<AvatarCommons['color'], 'colorful'>;
|
|
112
106
|
};
|
|
107
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { AvatarState } from './Avatar.types';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const renderAvatar_unstable: (state: AvatarState) => JSX.Element;
|
|
@@ -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":["../../../src/components/Avatar/renderAvatar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/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","sourceRoot":""}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { AvatarProps, AvatarState } from './Avatar.types';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const useAvatar_unstable: (props: AvatarProps, ref: React.Ref<HTMLElement>) => AvatarState;
|
|
@@ -1,100 +1,117 @@
|
|
|
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
|
-
export
|
|
9
|
-
var _a
|
|
7
|
+
export const useAvatar_unstable = (props, ref) => {
|
|
8
|
+
var _a;
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _k = props.color,
|
|
26
|
-
color = _k === void 0 ? 'neutral' : _k; // Resolve 'colorful' to a specific color name
|
|
10
|
+
const {
|
|
11
|
+
dir
|
|
12
|
+
} = useFluent();
|
|
13
|
+
const {
|
|
14
|
+
name,
|
|
15
|
+
size = 32,
|
|
16
|
+
shape = 'circular',
|
|
17
|
+
active = 'unset',
|
|
18
|
+
activeAppearance = 'ring',
|
|
19
|
+
idForColor
|
|
20
|
+
} = props;
|
|
21
|
+
let {
|
|
22
|
+
color = 'neutral'
|
|
23
|
+
} = props; // Resolve 'colorful' to a specific color name
|
|
27
24
|
|
|
28
25
|
if (color === 'colorful') {
|
|
29
|
-
color = avatarColors[getHashCode((
|
|
26
|
+
color = avatarColors[getHashCode((_a = idForColor !== null && idForColor !== void 0 ? idForColor : name) !== null && _a !== void 0 ? _a : '') % avatarColors.length];
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
const baseId = useId('avatar-');
|
|
30
|
+
const root = getNativeElementProps('span', {
|
|
31
|
+
role: 'img',
|
|
32
|
+
id: baseId,
|
|
33
|
+
// aria-label and/or aria-labelledby are resolved below
|
|
34
|
+
...props,
|
|
35
|
+
ref
|
|
36
|
+
},
|
|
37
|
+
/* excludedPropNames: */
|
|
38
|
+
['name']); // Resolve the initials slot, defaulted to getInitials.
|
|
39
|
+
|
|
40
|
+
let initials = resolveShorthand(props.initials, {
|
|
41
|
+
required: true,
|
|
42
|
+
defaultProps: {
|
|
43
|
+
children: getInitials(name, dir === 'rtl'),
|
|
44
|
+
'aria-hidden': true
|
|
45
|
+
}
|
|
46
|
+
}); // Render the icon slot *only if* there aren't any initials to display.
|
|
47
|
+
|
|
48
|
+
let icon = undefined;
|
|
49
|
+
|
|
50
|
+
if (!(initials === null || initials === void 0 ? void 0 : initials.children)) {
|
|
51
|
+
initials = undefined;
|
|
52
|
+
icon = resolveShorthand(props.icon, {
|
|
53
|
+
required: true,
|
|
55
54
|
defaultProps: {
|
|
56
|
-
|
|
55
|
+
children: /*#__PURE__*/React.createElement(PersonRegular, null),
|
|
56
|
+
'aria-hidden': true,
|
|
57
|
+
id: baseId + '__initials'
|
|
57
58
|
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!((_c = state.label) === null || _c === void 0 ? void 0 : _c.children)) {
|
|
62
|
-
var initials = state.getInitials(state.name, dir === 'rtl');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
state.icon = resolveShorthand(props.icon, {
|
|
70
|
-
required: true,
|
|
71
|
-
defaultProps: {
|
|
72
|
-
children: getDefaultIcon(state.size)
|
|
73
|
-
}
|
|
74
|
-
});
|
|
62
|
+
const image = resolveShorthand(props.image, {
|
|
63
|
+
defaultProps: {
|
|
64
|
+
alt: '',
|
|
65
|
+
role: 'presentation',
|
|
66
|
+
'aria-hidden': true
|
|
75
67
|
}
|
|
76
|
-
}
|
|
68
|
+
});
|
|
69
|
+
const badge = resolveShorthand(props.badge, {
|
|
70
|
+
defaultProps: {
|
|
71
|
+
size: getBadgeSize(size),
|
|
72
|
+
role: 'presentation',
|
|
73
|
+
'aria-hidden': true,
|
|
74
|
+
id: baseId + '__badge'
|
|
75
|
+
}
|
|
76
|
+
}); // Resolve aria-label and/or aria-labelledby if not provided by the user
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
if (!root['aria-label'] && !root['aria-labelledby']) {
|
|
79
|
+
if (name) {
|
|
80
|
+
root['aria-label'] = name; // Include the badge in labelledby if it exists
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else if (size <= 56) {
|
|
89
|
-
return /*#__PURE__*/React.createElement(Person28Regular, null);
|
|
90
|
-
} else if (size <= 72) {
|
|
91
|
-
return /*#__PURE__*/React.createElement(Person32Regular, null);
|
|
92
|
-
} else {
|
|
93
|
-
return /*#__PURE__*/React.createElement(Person48Regular, null);
|
|
82
|
+
if (badge) {
|
|
83
|
+
root['aria-labelledby'] = root.id + ' ' + badge.id;
|
|
84
|
+
}
|
|
85
|
+
} else if (initials) {
|
|
86
|
+
// root's aria-label should be the name, but fall back to being labelledby the initials if name is missing
|
|
87
|
+
root['aria-labelledby'] = initials.id + (badge ? ' ' + badge.id : '');
|
|
88
|
+
}
|
|
94
89
|
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
size,
|
|
93
|
+
name,
|
|
94
|
+
shape,
|
|
95
|
+
active,
|
|
96
|
+
activeAppearance,
|
|
97
|
+
color,
|
|
98
|
+
idForColor,
|
|
99
|
+
components: {
|
|
100
|
+
root: 'span',
|
|
101
|
+
initials: 'span',
|
|
102
|
+
icon: 'span',
|
|
103
|
+
image: 'img',
|
|
104
|
+
badge: PresenceBadge
|
|
105
|
+
},
|
|
106
|
+
root,
|
|
107
|
+
initials,
|
|
108
|
+
icon,
|
|
109
|
+
image,
|
|
110
|
+
badge
|
|
111
|
+
};
|
|
95
112
|
};
|
|
96
113
|
|
|
97
|
-
|
|
114
|
+
const getBadgeSize = size => {
|
|
98
115
|
if (size >= 96) {
|
|
99
116
|
return 'extra-large';
|
|
100
117
|
} else if (size >= 64) {
|
|
@@ -110,14 +127,14 @@ var getBadgeSize = function (size) {
|
|
|
110
127
|
}
|
|
111
128
|
};
|
|
112
129
|
|
|
113
|
-
|
|
130
|
+
const avatarColors = ['darkRed', 'cranberry', 'red', 'pumpkin', 'peach', 'marigold', 'gold', 'brass', 'brown', 'forest', 'seafoam', 'darkGreen', 'lightTeal', 'teal', 'steel', 'blue', 'royalBlue', 'cornflower', 'navy', 'lavender', 'purple', 'grape', 'lilac', 'pink', 'magenta', 'plum', 'beige', 'mink', 'platinum', 'anchor'];
|
|
114
131
|
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
const getHashCode = str => {
|
|
133
|
+
let hashCode = 0;
|
|
117
134
|
|
|
118
|
-
for (
|
|
119
|
-
|
|
120
|
-
|
|
135
|
+
for (let len = str.length - 1; len >= 0; len--) {
|
|
136
|
+
const ch = str.charCodeAt(len);
|
|
137
|
+
const shift = len % 8;
|
|
121
138
|
hashCode ^= (ch << shift) + (ch >> 8 - shift); // eslint-disable-line no-bitwise
|
|
122
139
|
}
|
|
123
140
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Avatar/useAvatar.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Avatar/useAvatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,KAAlD,QAA+D,2BAA/D;AAC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