@doist/reactist 31.3.0 → 32.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.md +10 -0
- package/dist/reactist.cjs.development.js +275 -111
- package/dist/reactist.cjs.development.js.map +1 -1
- package/dist/reactist.cjs.production.min.js +1 -1
- package/dist/reactist.cjs.production.min.js.map +1 -1
- package/es/avatar/avatar.js +164 -95
- package/es/avatar/avatar.js.map +1 -1
- package/es/avatar/avatar.module.css.js +1 -1
- package/es/avatar/utils.js +112 -16
- package/es/avatar/utils.js.map +1 -1
- package/es/utils/polymorphism.js.map +1 -1
- package/lib/avatar/avatar.d.ts +55 -17
- package/lib/avatar/avatar.js +164 -94
- package/lib/avatar/avatar.js.map +1 -1
- package/lib/avatar/avatar.module.css.js +1 -1
- package/lib/avatar/utils.d.ts +35 -3
- package/lib/avatar/utils.js +117 -16
- package/lib/avatar/utils.js.map +1 -1
- package/lib/utils/polymorphism.d.ts +1 -1
- package/lib/utils/polymorphism.js.map +1 -1
- package/package.json +1 -1
- package/styles/avatar.css +1 -1
- package/styles/avatar.module.css.css +1 -1
- package/styles/index.css +2 -4
- package/styles/reactist.css +1 -1
package/es/avatar/avatar.js
CHANGED
|
@@ -1,113 +1,182 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import { c } from 'react-compiler-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import { polymorphicComponent } from '../utils/polymorphism.js';
|
|
6
|
+
import { getAvatarImageIdentityKey, normalizeAvatarName, getSources, getAvailableImageSources, getInitials, getAvatarMetaColorIndex } from './utils.js';
|
|
6
7
|
import modules_08f3eeac from './avatar.module.css.js';
|
|
7
8
|
import { Box } from '../box/box.js';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Props for the `Avatar` component.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Displays an avatar from an image URL, a source map keyed by intrinsic
|
|
16
|
+
* image width, or initials derived from the provided name (with a background
|
|
17
|
+
* color).
|
|
18
|
+
*/
|
|
19
|
+
const Avatar = polymorphicComponent(function Avatar({
|
|
20
|
+
as,
|
|
21
|
+
size,
|
|
22
|
+
shape = 'circle',
|
|
23
|
+
name,
|
|
24
|
+
image,
|
|
25
|
+
alt,
|
|
26
|
+
exceptionallySetClassName,
|
|
27
|
+
'data-testid': testId,
|
|
28
|
+
'aria-hidden': ariaHidden,
|
|
29
|
+
'aria-label': ariaLabel,
|
|
30
|
+
...restProps
|
|
31
|
+
}, ref) {
|
|
32
|
+
const label = getAvatarLabel({
|
|
33
|
+
alt,
|
|
34
|
+
name,
|
|
35
|
+
'aria-label': ariaLabel
|
|
36
|
+
});
|
|
37
|
+
const isDecorative = Boolean(ariaHidden ?? label === '');
|
|
38
|
+
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
39
|
+
as: as,
|
|
40
|
+
ref: ref,
|
|
41
|
+
className: classNames(modules_08f3eeac.avatar, modules_08f3eeac[`size-${size}`], modules_08f3eeac[`shape-${shape}`], exceptionallySetClassName),
|
|
42
|
+
"data-testid": testId,
|
|
43
|
+
display: "inlineFlex",
|
|
44
|
+
alignItems: "center",
|
|
45
|
+
justifyContent: "center",
|
|
46
|
+
flexShrink: 0,
|
|
47
|
+
overflow: "hidden",
|
|
48
|
+
textAlign: "center"
|
|
49
|
+
}, restProps), /*#__PURE__*/React.createElement(AvatarImage
|
|
50
|
+
// Allows `AvatarImage` to remount when the image map changes,
|
|
51
|
+
// which resets error states without replacing the avatar root.
|
|
52
|
+
, {
|
|
53
|
+
key: getAvatarImageIdentityKey(image),
|
|
54
|
+
size: size,
|
|
55
|
+
name: name,
|
|
56
|
+
image: image,
|
|
57
|
+
label: label,
|
|
58
|
+
"aria-hidden": isDecorative
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
61
|
+
function getAvatarLabel({
|
|
62
|
+
alt,
|
|
63
|
+
name,
|
|
64
|
+
'aria-label': ariaLabel
|
|
65
|
+
}) {
|
|
66
|
+
return ariaLabel ?? alt ?? normalizeAvatarName(name);
|
|
67
|
+
}
|
|
68
|
+
function AvatarImage(t0) {
|
|
69
|
+
const $ = c(22);
|
|
70
|
+
const {
|
|
71
|
+
size,
|
|
72
|
+
name,
|
|
73
|
+
image,
|
|
74
|
+
label,
|
|
75
|
+
"aria-hidden": ariaHidden
|
|
76
|
+
} = t0;
|
|
77
|
+
const imageSources = getSources(image, size);
|
|
16
78
|
let t1;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
({
|
|
21
|
-
user,
|
|
22
|
-
avatarUrl,
|
|
23
|
-
size: t1,
|
|
24
|
-
className,
|
|
25
|
-
colorList: t2,
|
|
26
|
-
exceptionallySetClassName,
|
|
27
|
-
...props
|
|
28
|
-
} = t0);
|
|
29
|
-
$[0] = t0;
|
|
30
|
-
$[1] = avatarUrl;
|
|
31
|
-
$[2] = className;
|
|
32
|
-
$[3] = exceptionallySetClassName;
|
|
33
|
-
$[4] = props;
|
|
34
|
-
$[5] = t1;
|
|
35
|
-
$[6] = t2;
|
|
36
|
-
$[7] = user;
|
|
79
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
80
|
+
t1 = [];
|
|
81
|
+
$[0] = t1;
|
|
37
82
|
} else {
|
|
38
|
-
|
|
39
|
-
className = $[2];
|
|
40
|
-
exceptionallySetClassName = $[3];
|
|
41
|
-
props = $[4];
|
|
42
|
-
t1 = $[5];
|
|
43
|
-
t2 = $[6];
|
|
44
|
-
user = $[7];
|
|
83
|
+
t1 = $[0];
|
|
45
84
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
let
|
|
49
|
-
if ($[
|
|
50
|
-
|
|
51
|
-
$[
|
|
52
|
-
$[
|
|
53
|
-
$[
|
|
85
|
+
const [failedImageSources, setFailedImageSources] = React.useState(t1);
|
|
86
|
+
const availableImageSources = getAvailableImageSources(imageSources, failedImageSources);
|
|
87
|
+
let t2;
|
|
88
|
+
if ($[1] !== availableImageSources || $[2] !== name) {
|
|
89
|
+
t2 = availableImageSources ? "" : getInitials(name);
|
|
90
|
+
$[1] = availableImageSources;
|
|
91
|
+
$[2] = name;
|
|
92
|
+
$[3] = t2;
|
|
54
93
|
} else {
|
|
55
|
-
|
|
94
|
+
t2 = $[3];
|
|
56
95
|
}
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
t4
|
|
96
|
+
const initials = t2;
|
|
97
|
+
const hasInitials = initials !== "";
|
|
98
|
+
if (availableImageSources) {
|
|
99
|
+
let t3;
|
|
100
|
+
if ($[4] !== availableImageSources || $[5] !== setFailedImageSources) {
|
|
101
|
+
t3 = event => {
|
|
102
|
+
const failedSource = getFailedImageSource(availableImageSources, event.currentTarget);
|
|
103
|
+
setFailedImageSources(currentFailedSources => currentFailedSources.includes(failedSource) ? currentFailedSources : [...currentFailedSources, failedSource]);
|
|
104
|
+
};
|
|
105
|
+
$[4] = availableImageSources;
|
|
106
|
+
$[5] = setFailedImageSources;
|
|
107
|
+
$[6] = t3;
|
|
108
|
+
} else {
|
|
109
|
+
t3 = $[6];
|
|
110
|
+
}
|
|
111
|
+
let t4;
|
|
112
|
+
if ($[7] !== ariaHidden || $[8] !== availableImageSources.sizes || $[9] !== availableImageSources.src || $[10] !== availableImageSources.srcSet || $[11] !== label || $[12] !== t3) {
|
|
113
|
+
t4 = /*#__PURE__*/React.createElement("img", {
|
|
114
|
+
className: modules_08f3eeac.image,
|
|
115
|
+
src: availableImageSources.src,
|
|
116
|
+
srcSet: availableImageSources.srcSet,
|
|
117
|
+
sizes: availableImageSources.sizes,
|
|
118
|
+
alt: label,
|
|
119
|
+
"aria-hidden": ariaHidden,
|
|
120
|
+
onError: t3
|
|
121
|
+
});
|
|
122
|
+
$[7] = ariaHidden;
|
|
123
|
+
$[8] = availableImageSources.sizes;
|
|
124
|
+
$[9] = availableImageSources.src;
|
|
125
|
+
$[10] = availableImageSources.srcSet;
|
|
126
|
+
$[11] = label;
|
|
127
|
+
$[12] = t3;
|
|
128
|
+
$[13] = t4;
|
|
129
|
+
} else {
|
|
130
|
+
t4 = $[13];
|
|
131
|
+
}
|
|
132
|
+
return t4;
|
|
73
133
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
134
|
+
if (hasInitials) {
|
|
135
|
+
const t3 = modules_08f3eeac[`meta-color-${getAvatarMetaColorIndex(name)}`];
|
|
136
|
+
let t4;
|
|
137
|
+
if ($[14] !== t3) {
|
|
138
|
+
t4 = classNames(modules_08f3eeac.initials, t3);
|
|
139
|
+
$[14] = t3;
|
|
140
|
+
$[15] = t4;
|
|
141
|
+
} else {
|
|
142
|
+
t4 = $[15];
|
|
143
|
+
}
|
|
144
|
+
const t5 = label ? "img" : undefined;
|
|
145
|
+
let t6;
|
|
146
|
+
if ($[16] !== ariaHidden || $[17] !== initials || $[18] !== label || $[19] !== t4 || $[20] !== t5) {
|
|
147
|
+
t6 = /*#__PURE__*/React.createElement("div", {
|
|
148
|
+
className: t4,
|
|
149
|
+
role: t5,
|
|
150
|
+
"aria-label": label,
|
|
151
|
+
"aria-hidden": ariaHidden
|
|
152
|
+
}, initials);
|
|
153
|
+
$[16] = ariaHidden;
|
|
154
|
+
$[17] = initials;
|
|
155
|
+
$[18] = label;
|
|
156
|
+
$[19] = t4;
|
|
157
|
+
$[20] = t5;
|
|
158
|
+
$[21] = t6;
|
|
159
|
+
} else {
|
|
160
|
+
t6 = $[21];
|
|
161
|
+
}
|
|
162
|
+
return t6;
|
|
82
163
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
$[20] = t6;
|
|
91
|
-
} else {
|
|
92
|
-
t6 = $[20];
|
|
93
|
-
}
|
|
94
|
-
let t7;
|
|
95
|
-
if ($[21] !== props || $[22] !== style || $[23] !== t6 || $[24] !== userInitials) {
|
|
96
|
-
t7 = /*#__PURE__*/React.createElement(Box, _extends({
|
|
97
|
-
className: t6,
|
|
98
|
-
style: style
|
|
99
|
-
}, props), userInitials);
|
|
100
|
-
$[21] = props;
|
|
101
|
-
$[22] = style;
|
|
102
|
-
$[23] = t6;
|
|
103
|
-
$[24] = userInitials;
|
|
104
|
-
$[25] = t7;
|
|
105
|
-
} else {
|
|
106
|
-
t7 = $[25];
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
function getAbsoluteImageSource(src, image) {
|
|
167
|
+
try {
|
|
168
|
+
return new URL(src, image.ownerDocument.baseURI).href;
|
|
169
|
+
} catch {
|
|
170
|
+
return src;
|
|
107
171
|
}
|
|
108
|
-
return t7;
|
|
109
172
|
}
|
|
110
|
-
|
|
173
|
+
function getFailedImageSource(imageProps, image) {
|
|
174
|
+
const failedSrc = image.currentSrc || image.src || imageProps.src;
|
|
175
|
+
const matchingSource = imageProps.sources?.find(({
|
|
176
|
+
src
|
|
177
|
+
}) => src === failedSrc || getAbsoluteImageSource(src, image) === failedSrc);
|
|
178
|
+
return matchingSource?.src ?? imageProps.src;
|
|
179
|
+
}
|
|
111
180
|
|
|
112
181
|
export { Avatar };
|
|
113
182
|
//# sourceMappingURL=avatar.js.map
|
package/es/avatar/avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar.js","sources":["../../src/avatar/avatar.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport { Box } from '../box'\nimport { getClassNames } from '../utils/responsive-props'\n\nimport { emailToIndex, getInitials } from './utils'\n\nimport styles from './avatar.module.css'\n\nimport type { ObfuscatedClassName } from '../utils/common-types'\nimport type { ResponsiveProp } from '../utils/responsive-props'\n\nconst AVATAR_COLORS = [\n '#fcc652',\n '#e9952c',\n '#e16b2d',\n '#d84b40',\n '#e8435a',\n '#e5198a',\n '#ad3889',\n '#86389c',\n '#a8a8a8',\n '#98be2f',\n '#5d9d50',\n '#5f9f85',\n '#5bbcb6',\n '#32a3bf',\n '#2bafeb',\n '#2d88c3',\n '#3863cc',\n '#5e5e5e',\n]\n\ntype AvatarSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl'\n\ntype Props = ObfuscatedClassName & {\n /** @deprecated Please use `exceptionallySetClassName` */\n className?: string\n /** @deprecated */\n colorList?: string[]\n size?: ResponsiveProp<AvatarSize>\n avatarUrl?: string\n user: { name?: string; email: string }\n}\n\nfunction Avatar({\n user,\n avatarUrl,\n size = 'l',\n className,\n colorList = AVATAR_COLORS,\n exceptionallySetClassName,\n ...props\n}: Props) {\n const userInitials = getInitials(user.name) || getInitials(user.email)\n const avatarSize = size ? size : 'l'\n\n const style = avatarUrl\n ? {\n backgroundImage: `url(${avatarUrl})`,\n textIndent: '-9999px', // hide the initials\n }\n : {\n backgroundColor: colorList[emailToIndex(user.email, colorList.length)],\n }\n\n const sizeClassName = getClassNames(styles, 'size', avatarSize)\n\n return (\n <Box\n className={[className, styles.avatar, sizeClassName, exceptionallySetClassName]}\n style={style}\n {...props}\n >\n {userInitials}\n </Box>\n )\n}\nAvatar.displayName = 'Avatar'\n\nexport { Avatar }\n"],"names":["AVATAR_COLORS","Avatar","t0","$","_c","avatarUrl","className","exceptionallySetClassName","props","t1","t2","user","size","colorList","undefined","t3","email","name","getInitials","userInitials","avatarSize","t4","backgroundImage","textIndent","backgroundColor","emailToIndex","length","style","t5","getClassNames","styles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{"version":3,"file":"avatar.js","sources":["../../src/avatar/avatar.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport classNames from 'classnames'\n\nimport { Box } from '../box'\nimport { polymorphicComponent } from '../utils/polymorphism'\n\nimport {\n getAvailableImageSources,\n getAvatarImageIdentityKey,\n getAvatarMetaColorIndex,\n getInitials,\n getSources,\n normalizeAvatarName,\n} from './utils'\n\nimport styles from './avatar.module.css'\n\nimport type { ObfuscatedClassName } from '../utils/common-types'\nimport type { PolymorphicComponentProps } from '../utils/polymorphism'\nimport type { AvatarImage as AvatarImageProp, AvatarShape, AvatarSize, ImageSources } from './utils'\n\n/**\n * Props for the `Avatar` component.\n */\ntype AvatarOwnProps = ObfuscatedClassName & {\n /**\n * The rendered avatar size, in CSS pixels.\n */\n size: AvatarSize\n\n /**\n * The avatar shape.\n *\n * @default 'circle'\n */\n shape?: AvatarShape\n\n /**\n * The display name represented by the avatar.\n *\n * Used as the default accessible label, to generate fallback initials, and\n * to assign the deterministic background color when rendering initials.\n */\n name?: string\n\n /**\n * The avatar image.\n *\n * Pass a string for a single image URL, or a source map keyed by intrinsic\n * image width. Source maps render as native `srcSet`/`sizes` hints, with\n * the largest valid source used as the fallback `src`.\n */\n image?: AvatarImageProp\n\n /**\n * Accessible text for the avatar image.\n *\n * Defaults to `name`. Pass an empty string when the avatar is decorative.\n */\n alt?: string\n\n /**\n * Test identifier applied to the avatar root element.\n */\n 'data-testid'?: string\n\n /**\n * Avatar owns its root sizing styles. Use `exceptionallySetClassName` for the styling escape\n * hatch.\n */\n style?: never\n}\n\ntype AvatarProps<ComponentType extends React.ElementType = 'div'> = PolymorphicComponentProps<\n ComponentType,\n AvatarOwnProps,\n 'omitClassName'\n>\n\n/**\n * Displays an avatar from an image URL, a source map keyed by intrinsic\n * image width, or initials derived from the provided name (with a background\n * color).\n */\nconst Avatar = polymorphicComponent<'div', AvatarOwnProps, 'omitClassName'>(function Avatar(\n {\n as,\n size,\n shape = 'circle',\n name,\n image,\n alt,\n exceptionallySetClassName,\n 'data-testid': testId,\n 'aria-hidden': ariaHidden,\n 'aria-label': ariaLabel,\n ...restProps\n },\n ref,\n) {\n const label = getAvatarLabel({ alt, name, 'aria-label': ariaLabel })\n const isDecorative = Boolean(ariaHidden ?? label === '')\n\n return (\n <Box\n as={as}\n ref={ref}\n className={classNames(\n styles.avatar,\n styles[`size-${size}`],\n styles[`shape-${shape}`],\n exceptionallySetClassName,\n )}\n data-testid={testId}\n display=\"inlineFlex\"\n alignItems=\"center\"\n justifyContent=\"center\"\n flexShrink={0}\n overflow=\"hidden\"\n textAlign=\"center\"\n {...restProps}\n >\n <AvatarImage\n // Allows `AvatarImage` to remount when the image map changes,\n // which resets error states without replacing the avatar root.\n key={getAvatarImageIdentityKey(image)}\n size={size}\n name={name}\n image={image}\n label={label}\n aria-hidden={isDecorative}\n />\n </Box>\n )\n})\n\nfunction getAvatarLabel({\n alt,\n name,\n 'aria-label': ariaLabel,\n}: Pick<AvatarProps, 'alt' | 'name' | 'aria-label'>) {\n return ariaLabel ?? alt ?? normalizeAvatarName(name)\n}\n\ntype AvatarImageProps = {\n size: AvatarSize\n name?: string\n image?: AvatarImageProp\n label?: string\n 'aria-hidden'?: boolean\n}\n\nfunction AvatarImage({ size, name, image, label, 'aria-hidden': ariaHidden }: AvatarImageProps) {\n const imageSources = getSources(image, size)\n const [failedImageSources, setFailedImageSources] = React.useState<string[]>([])\n const availableImageSources = getAvailableImageSources(imageSources, failedImageSources)\n const initials = availableImageSources ? '' : getInitials(name)\n const hasInitials = initials !== ''\n\n if (availableImageSources) {\n return (\n <img\n className={styles.image}\n src={availableImageSources.src}\n srcSet={availableImageSources.srcSet}\n sizes={availableImageSources.sizes}\n alt={label}\n aria-hidden={ariaHidden}\n onError={(event) => {\n const failedSource = getFailedImageSource(\n availableImageSources,\n event.currentTarget,\n )\n\n setFailedImageSources((currentFailedSources) =>\n currentFailedSources.includes(failedSource)\n ? currentFailedSources\n : [...currentFailedSources, failedSource],\n )\n }}\n />\n )\n }\n if (hasInitials) {\n return (\n <div\n className={classNames(\n styles.initials,\n styles[`meta-color-${getAvatarMetaColorIndex(name)}`],\n )}\n role={label ? 'img' : undefined}\n aria-label={label}\n aria-hidden={ariaHidden}\n >\n {initials}\n </div>\n )\n }\n\n return null\n}\n\nfunction getAbsoluteImageSource(src: string, image: HTMLImageElement) {\n try {\n return new URL(src, image.ownerDocument.baseURI).href\n } catch {\n return src\n }\n}\n\nfunction getFailedImageSource(imageProps: ImageSources, image: HTMLImageElement) {\n const failedSrc = image.currentSrc || image.src || imageProps.src\n const matchingSource = imageProps.sources?.find(\n ({ src }) => src === failedSrc || getAbsoluteImageSource(src, image) === failedSrc,\n )\n\n return matchingSource?.src ?? imageProps.src\n}\n\nexport { Avatar }\nexport type { AvatarProps }\nexport type { AvatarImage, AvatarShape, AvatarSize } from './utils'\n"],"names":["Avatar","polymorphicComponent","as","size","shape","name","image","alt","exceptionallySetClassName","testId","ariaHidden","ariaLabel","restProps","ref","label","getAvatarLabel","isDecorative","Boolean","React","createElement","Box","_extends","className","classNames","styles","avatar","display","alignItems","justifyContent","flexShrink","overflow","textAlign","AvatarImage","key","getAvatarImageIdentityKey","normalizeAvatarName","t0","$","_c","imageSources","getSources","t1","Symbol","for","failedImageSources","setFailedImageSources","useState","availableImageSources","getAvailableImageSources","t2","getInitials","initials","hasInitials","t3","event","failedSource","getFailedImageSource","currentTarget","currentFailedSources","includes","t4","sizes","src","srcSet","onError","getAvatarMetaColorIndex","t5","undefined","t6","role","getAbsoluteImageSource","URL","ownerDocument","baseURI","href","imageProps","failedSrc","currentSrc","matchingSource","sources","find"],"mappings":";;;;;;;;;AAsBA;AACA;AACA;;AAwDA;AACA;AACA;AACA;AACA;AACA,MAAMA,MAAM,GAAGC,oBAAoB,CAAyC,SAASD,MAAMA,CACvF;EACIE,EAAE;EACFC,IAAI;AACJC,EAAAA,KAAK,GAAG,QAAQ;EAChBC,IAAI;EACJC,KAAK;EACLC,GAAG;EACHC,yBAAyB;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,IAAI,CAAA;AAAA,CAAA;AAGf,SAASE,sBAAsBA,CAACR,GAAW,EAAExD,KAAuB,EAAE;EAClE,IAAI;AACA,IAAA,OAAO,IAAIiE,GAAG,CAACT,GAAG,EAAExD,KAAK,CAACkE,aAAa,CAACC,OAAO,CAAC,CAACC,IAAI,CAAA;AACzD,GAAC,CAAC,MAAM;AACJ,IAAA,OAAOZ,GAAG,CAAA;AACd,GAAA;AACJ,CAAA;AAEA,SAASN,oBAAoBA,CAACmB,UAAwB,EAAErE,KAAuB,EAAE;AAC7E,EAAA,MAAMsE,SAAS,GAAGtE,KAAK,CAACuE,UAAU,IAAIvE,KAAK,CAACwD,GAAG,IAAIa,UAAU,CAACb,GAAG,CAAA;EACjE,MAAMgB,cAAc,GAAGH,UAAU,CAACI,OAAO,EAAEC,IAAI,CAC3C,CAAC;AAAElB,IAAAA,GAAAA;AAAI,GAAC,KAAKA,GAAG,KAAKc,SAAS,IAAIN,sBAAsB,CAACR,GAAG,EAAExD,KAAK,CAAC,KAAKsE,SAC7E,CAAC,CAAA;AAED,EAAA,OAAOE,cAAc,EAAEhB,GAAG,IAAIa,UAAU,CAACb,GAAG,CAAA;AAChD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var modules_08f3eeac = {"avatar":"
|
|
1
|
+
var modules_08f3eeac = {"avatar":"acf9ee3d","size-80":"_5b32f21b","size-72":"_5dd2ceae","size-62":"_0737423f","size-50":"_47744c53","size-40":"_087775aa","size-36":"_02c89bce","size-30":"_3ed61ce0","size-28":"c9fa2651","size-24":"_89506d0e","size-20":"d7ab9fd7","size-18":"_32fef877","size-16":"_8962c0a0","size-12":"a06fa349","initials":"_80b6bfbf","meta-color-0":"_64da0562","meta-color-1":"ee7c29c0","meta-color-2":"_70215fb1","meta-color-3":"_488b23cd","meta-color-4":"f6b3e824","meta-color-5":"_88b828ae","meta-color-6":"f931ad92","meta-color-7":"_504e515a","meta-color-8":"_277cc6cd","meta-color-9":"db85100e","meta-color-10":"c76af5ed","meta-color-11":"ab7368dc","meta-color-12":"c2a85a75","meta-color-13":"_0e942ae0","meta-color-14":"_2f79016f","meta-color-15":"_118f815d","meta-color-16":"_6e5574e6","meta-color-17":"_49d688e7","meta-color-18":"d5233bf3","meta-color-19":"_710699d5","shape-circle":"_2b4e8069","shape-rounded":"_28fdd710","image":"bda7eadb"};
|
|
2
2
|
|
|
3
3
|
export { modules_08f3eeac as default };
|
|
4
4
|
//# sourceMappingURL=avatar.module.css.js.map
|
package/es/avatar/utils.js
CHANGED
|
@@ -1,24 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported avatar sizes, in CSS pixels.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supported avatar clipping shapes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Avatar image source.
|
|
11
|
+
*
|
|
12
|
+
* Use a string for a single image URL, or a source map keyed by intrinsic image width. Source maps
|
|
13
|
+
* are converted to native `srcSet` width descriptors.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const AVATAR_META_COLOR_COUNT = 20;
|
|
17
|
+
const WHITESPACE_REGEXP = new RegExp('\\p{White_Space}+', 'gu');
|
|
18
|
+
const GRAPHEME_SEGMENTER = typeof Intl !== 'undefined' && 'Segmenter' in Intl ? new Intl.Segmenter('und', {
|
|
19
|
+
granularity: 'grapheme'
|
|
20
|
+
}) : undefined;
|
|
21
|
+
function normalizeAvatarName(name) {
|
|
22
|
+
return name?.normalize('NFC').trim().replace(WHITESPACE_REGEXP, ' ') ?? '';
|
|
23
|
+
}
|
|
24
|
+
function getGraphemeClusters(value) {
|
|
25
|
+
if (GRAPHEME_SEGMENTER) {
|
|
26
|
+
return Array.from(GRAPHEME_SEGMENTER.segment(value), ({
|
|
27
|
+
segment
|
|
28
|
+
}) => segment);
|
|
29
|
+
}
|
|
30
|
+
return Array.from(value);
|
|
31
|
+
}
|
|
32
|
+
function getInitialGrapheme(value) {
|
|
33
|
+
return getGraphemeClusters(value?.toUpperCase() ?? '')[0] ?? '';
|
|
34
|
+
}
|
|
1
35
|
function getInitials(name) {
|
|
2
|
-
|
|
36
|
+
const nameParts = normalizeAvatarName(name).split(' ').filter(Boolean);
|
|
37
|
+
if (nameParts.length === 0) {
|
|
3
38
|
return '';
|
|
4
39
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
40
|
+
if (nameParts.length === 1) {
|
|
41
|
+
return getGraphemeClusters(nameParts[0].toUpperCase()).slice(0, 2).join('');
|
|
42
|
+
}
|
|
43
|
+
return `${getInitialGrapheme(nameParts[0])}${getInitialGrapheme(nameParts[nameParts.length - 1])}`;
|
|
44
|
+
}
|
|
45
|
+
function getSortedImageSources(image) {
|
|
46
|
+
return Object.entries(image).map(([sourceSize, src]) => ({
|
|
47
|
+
sourceSize: Number(sourceSize),
|
|
48
|
+
src
|
|
49
|
+
})).filter(({
|
|
50
|
+
sourceSize,
|
|
51
|
+
src
|
|
52
|
+
}) => Number.isFinite(sourceSize) && sourceSize > 0 && src).sort((a, b) => a.sourceSize - b.sourceSize);
|
|
53
|
+
}
|
|
54
|
+
function getImagePropsFromSources(sources, sizes) {
|
|
55
|
+
if (sources.length === 0) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
src: sources[sources.length - 1].src,
|
|
60
|
+
srcSet: sources.map(({
|
|
61
|
+
sourceSize,
|
|
62
|
+
src
|
|
63
|
+
}) => `${src} ${sourceSize}w`).join(', '),
|
|
64
|
+
sizes,
|
|
65
|
+
sources
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function getSources(image, size) {
|
|
69
|
+
if (!image) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
if (typeof image === 'string') {
|
|
73
|
+
return {
|
|
74
|
+
src: image
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const sources = getSortedImageSources(image);
|
|
78
|
+
return getImagePropsFromSources(sources, `${size}px`);
|
|
79
|
+
}
|
|
80
|
+
function getAvatarImageIdentityKey(image) {
|
|
81
|
+
if (!image) {
|
|
82
|
+
return 'fallback';
|
|
83
|
+
}
|
|
84
|
+
if (typeof image === 'string') {
|
|
85
|
+
return image;
|
|
86
|
+
}
|
|
87
|
+
const sources = getSortedImageSources(image);
|
|
88
|
+
if (sources.length === 0) {
|
|
89
|
+
return 'fallback';
|
|
14
90
|
}
|
|
15
|
-
return
|
|
91
|
+
return sources.map(({
|
|
92
|
+
sourceSize,
|
|
93
|
+
src
|
|
94
|
+
}) => `${sourceSize}:${src}`).join('|');
|
|
16
95
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
96
|
+
function getAvailableImageSources(imageProps, failedSources) {
|
|
97
|
+
if (!imageProps) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (failedSources.length === 0) {
|
|
101
|
+
return imageProps;
|
|
102
|
+
}
|
|
103
|
+
if (!imageProps.sources) {
|
|
104
|
+
return failedSources.includes(imageProps.src) ? undefined : imageProps;
|
|
105
|
+
}
|
|
106
|
+
return getImagePropsFromSources(imageProps.sources.filter(({
|
|
107
|
+
src
|
|
108
|
+
}) => !failedSources.includes(src)), imageProps.sizes);
|
|
109
|
+
}
|
|
110
|
+
function getAvatarMetaColorIndex(name) {
|
|
111
|
+
const normalizedName = normalizeAvatarName(name);
|
|
112
|
+
let hash = 0;
|
|
113
|
+
for (const char of normalizedName) {
|
|
114
|
+
hash = hash * 31 + (char.codePointAt(0) ?? 0) >>> 0;
|
|
115
|
+
}
|
|
116
|
+
return hash % AVATAR_META_COLOR_COUNT;
|
|
21
117
|
}
|
|
22
118
|
|
|
23
|
-
export {
|
|
119
|
+
export { AVATAR_META_COLOR_COUNT, getAvailableImageSources, getAvatarImageIdentityKey, getAvatarMetaColorIndex, getInitials, getSources, normalizeAvatarName };
|
|
24
120
|
//# sourceMappingURL=utils.js.map
|
package/es/avatar/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/avatar/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/avatar/utils.ts"],"sourcesContent":["const AVATAR_SIZES = [80, 72, 62, 50, 40, 36, 30, 28, 24, 20, 18, 16, 12] as const\n\n/**\n * Supported avatar sizes, in CSS pixels.\n */\ntype AvatarSize = (typeof AVATAR_SIZES)[number]\n\n/**\n * Supported avatar clipping shapes.\n */\ntype AvatarShape = 'circle' | 'rounded'\n\n/**\n * Avatar image source.\n *\n * Use a string for a single image URL, or a source map keyed by intrinsic image width. Source maps\n * are converted to native `srcSet` width descriptors.\n */\ntype AvatarImage = string | Record<number, string>\n\ntype AvatarImageSource = {\n sourceSize: number\n src: string\n}\n\ntype ImageSources = {\n src: string\n srcSet?: string\n sizes?: string\n sources?: AvatarImageSource[]\n}\n\nconst AVATAR_META_COLOR_COUNT = 20\n\nconst WHITESPACE_REGEXP = new RegExp('\\\\p{White_Space}+', 'gu')\nconst GRAPHEME_SEGMENTER =\n typeof Intl !== 'undefined' && 'Segmenter' in Intl\n ? new Intl.Segmenter('und', { granularity: 'grapheme' })\n : undefined\n\nfunction normalizeAvatarName(name?: string) {\n return name?.normalize('NFC').trim().replace(WHITESPACE_REGEXP, ' ') ?? ''\n}\n\nfunction getGraphemeClusters(value: string) {\n if (GRAPHEME_SEGMENTER) {\n return Array.from(GRAPHEME_SEGMENTER.segment(value), ({ segment }) => segment)\n }\n\n return Array.from(value)\n}\n\nfunction getInitialGrapheme(value?: string) {\n return getGraphemeClusters(value?.toUpperCase() ?? '')[0] ?? ''\n}\n\nfunction getInitials(name?: string) {\n const nameParts = normalizeAvatarName(name).split(' ').filter(Boolean)\n\n if (nameParts.length === 0) {\n return ''\n }\n\n if (nameParts.length === 1) {\n return getGraphemeClusters(nameParts[0]!.toUpperCase()).slice(0, 2).join('')\n }\n\n return `${getInitialGrapheme(nameParts[0])}${getInitialGrapheme(nameParts[nameParts.length - 1])}`\n}\n\nfunction getSortedImageSources(image: Record<number, string>): AvatarImageSource[] {\n return Object.entries(image)\n .map(([sourceSize, src]) => ({ sourceSize: Number(sourceSize), src }))\n .filter(({ sourceSize, src }) => Number.isFinite(sourceSize) && sourceSize > 0 && src)\n .sort((a, b) => a.sourceSize - b.sourceSize)\n}\n\nfunction getImagePropsFromSources(\n sources: AvatarImageSource[],\n sizes?: string,\n): ImageSources | undefined {\n if (sources.length === 0) {\n return undefined\n }\n\n return {\n src: sources[sources.length - 1]!.src,\n srcSet: sources.map(({ sourceSize, src }) => `${src} ${sourceSize}w`).join(', '),\n sizes,\n sources,\n }\n}\n\nfunction getSources(image: AvatarImage | undefined, size: AvatarSize): ImageSources | undefined {\n if (!image) {\n return undefined\n }\n\n if (typeof image === 'string') {\n return { src: image }\n }\n\n const sources = getSortedImageSources(image)\n return getImagePropsFromSources(sources, `${size}px`)\n}\n\nfunction getAvatarImageIdentityKey(image?: AvatarImage) {\n if (!image) {\n return 'fallback'\n }\n\n if (typeof image === 'string') {\n return image\n }\n\n const sources = getSortedImageSources(image)\n if (sources.length === 0) {\n return 'fallback'\n }\n\n return sources.map(({ sourceSize, src }) => `${sourceSize}:${src}`).join('|')\n}\n\nfunction getAvailableImageSources(\n imageProps: ImageSources | undefined,\n failedSources: readonly string[],\n) {\n if (!imageProps) {\n return undefined\n }\n\n if (failedSources.length === 0) {\n return imageProps\n }\n\n if (!imageProps.sources) {\n return failedSources.includes(imageProps.src) ? undefined : imageProps\n }\n\n return getImagePropsFromSources(\n imageProps.sources.filter(({ src }) => !failedSources.includes(src)),\n imageProps.sizes,\n )\n}\n\nfunction getAvatarMetaColorIndex(name?: string) {\n const normalizedName = normalizeAvatarName(name)\n let hash = 0\n\n for (const char of normalizedName) {\n hash = (hash * 31 + (char.codePointAt(0) ?? 0)) >>> 0\n }\n\n return hash % AVATAR_META_COLOR_COUNT\n}\n\nexport {\n AVATAR_META_COLOR_COUNT,\n AVATAR_SIZES,\n getAvailableImageSources,\n getAvatarImageIdentityKey,\n getAvatarMetaColorIndex,\n getInitials,\n getSources,\n normalizeAvatarName,\n}\nexport type { AvatarImage, AvatarImageSource, AvatarShape, AvatarSize, ImageSources }\n"],"names":["AVATAR_META_COLOR_COUNT","WHITESPACE_REGEXP","RegExp","GRAPHEME_SEGMENTER","Intl","Segmenter","granularity","undefined","normalizeAvatarName","name","normalize","trim","replace","getGraphemeClusters","value","Array","from","segment","getInitialGrapheme","toUpperCase","getInitials","nameParts","split","filter","Boolean","length","slice","join","getSortedImageSources","image","Object","entries","map","sourceSize","src","Number","isFinite","sort","a","b","getImagePropsFromSources","sources","sizes","srcSet","getSources","size","getAvatarImageIdentityKey","getAvailableImageSources","imageProps","failedSources","includes","getAvatarMetaColorIndex","normalizedName","hash","char","codePointAt"],"mappings":"AAEA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAeMA,MAAAA,uBAAuB,GAAG,GAAE;AAElC,MAAMC,iBAAiB,GAAG,IAAIC,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAA;AAC/D,MAAMC,kBAAkB,GACpB,OAAOC,IAAI,KAAK,WAAW,IAAI,WAAW,IAAIA,IAAI,GAC5C,IAAIA,IAAI,CAACC,SAAS,CAAC,KAAK,EAAE;AAAEC,EAAAA,WAAW,EAAE,UAAA;AAAW,CAAC,CAAC,GACtDC,SAAS,CAAA;AAEnB,SAASC,mBAAmBA,CAACC,IAAa,EAAE;AACxC,EAAA,OAAOA,IAAI,EAAEC,SAAS,CAAC,KAAK,CAAC,CAACC,IAAI,EAAE,CAACC,OAAO,CAACX,iBAAiB,EAAE,GAAG,CAAC,IAAI,EAAE,CAAA;AAC9E,CAAA;AAEA,SAASY,mBAAmBA,CAACC,KAAa,EAA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,CAAC,CAAC,EACpEc,UAAU,CAACN,KACf,CAAC,CAAA;AACL,CAAA;AAEA,SAASS,uBAAuBA,CAAC1C,IAAa,EAAE;AAC5C,EAAA,MAAM2C,cAAc,GAAG5C,mBAAmB,CAACC,IAAI,CAAC,CAAA;EAChD,IAAI4C,IAAI,GAAG,CAAC,CAAA;AAEZ,EAAA,KAAK,MAAMC,IAAI,IAAIF,cAAc,EAAE;AAC/BC,IAAAA,IAAI,GAAIA,IAAI,GAAG,EAAE,IAAIC,IAAI,CAACC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAM,CAAC,CAAA;AACzD,GAAA;EAEA,OAAOF,IAAI,GAAGrD,uBAAuB,CAAA;AACzC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polymorphism.js","sources":["../../src/utils/polymorphism.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport * as React from 'react'\n\nimport type { ObfuscatedClassName } from './common-types'\n\ntype Merge<P1, P2> = Omit<P1, keyof P2> & P2\n\ntype EmptyObject = {\n [K in any]: never\n}\n\ntype ObfuscateClassNameMode = 'keepClassName' | 'obfuscateClassName' | 'omitClassName'\n\n/**\n * If a set of props include the `className` prop, we replace it with a `exceptionallySetClassName`\n * prop instead.\n *\n * This can be customized via the second generic parameter, as there are cases where it may be\n * needed to omit this behaviour and keep the `className`. You can also instruct it to remove the\n * `className` prop while not replacing it with the `exceptionallySetClassName` one.\n *\n * @see ObfuscatedClassName['exceptionallySetClassName'] for details about this prop\n * @see PolymorphicComponent for details about this feature\n */\ntype WithObfuscatedClassName<\n Props,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> = 'className' extends keyof Props\n ? ShouldObfuscateClassName extends 'obfuscateClassName'\n ? Omit<Props, 'className'> & ObfuscatedClassName\n : ShouldObfuscateClassName extends 'omitClassName'\n ? Omit<Props, 'className'>\n : ShouldObfuscateClassName extends 'keepClassName'\n ? Props\n : never\n : Props\n\ntype PolymorphicProp<ComponentType extends React.ElementType> = {\n /**\n * Used to instruct this component what React element to render as. It can be both a string\n * representing a HTML tag name, or a React component.\n *\n * When using this prop, the component you apply it to will also recognize in its props types\n * all the props from the component or HTML element you are rendering it as.\n *\n * Some uses for this feature:\n *\n * - Using some of our layout components, while at the same time being able to set them to use\n * semantic HTML elements needed for accessibility purposes (e.g. `nav`, `main`, etc).\n * - Using a design system link component, but have it internally use a client-side router link\n * implemented via a React component (e.g. react-router's `Link`).\n *\n * Keep in mind that not all compositions of this kind may work well, especially when composing\n * with another React component and not with a HTML tag name. In particular, if the components\n * being composed have opposing concerns of clashing features (e.g. they have contradicting\n * styles applied to them) things may not go well. In those cases prefer to nest them instead.\n *\n * @see PolymorphicComponent\n */\n as?: ComponentType\n}\n\n/**\n * Given a component or element type, and a set of additional props, this builds the entire set of\n * props for a polymorphic component.\n *\n * It does three things:\n *\n * 1. it merges the element type props with the `OwnProps`\n * 2. it adds the `as` prop to allow for polymorphism to happen\n * 3. it optionally obfuscates or omits the className prop if present\n *\n * @see PolymorphicProp\n * @see WithObfuscatedClassName\n */\ntype PolymorphicComponentProps<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> = Merge<\n WithObfuscatedClassName<React.ComponentProps<ComponentType>, ShouldObfuscateClassName>,\n OwnProps & PolymorphicProp<ComponentType>\n>\n\ntype ElementTagNameMap = HTMLElementTagNameMap &\n Pick<SVGElementTagNameMap, Exclude<keyof SVGElementTagNameMap, keyof HTMLElementTagNameMap>>\n\ntype ElementByTag<TagName extends keyof ElementTagNameMap> = ElementTagNameMap[TagName]\n\ntype ElementByTagOrAny<ComponentType extends React.ElementType> =\n ComponentType extends keyof ElementTagNameMap ? ElementByTag<ComponentType> : any\n\n/**\n * The function passed to React.forwardRef, but typed in a way that's prepared for polymorphism via\n * the `as` prop. It also allows to specify if the `className` prop should be obfuscated or omitted.\n *\n * @see PolymorphicComponentProps\n * @see WithObfuscatedClassName\n */\ninterface ForwardRefFunction<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> {\n (\n props: PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>,\n ref:\n | ((instance: ElementByTagOrAny<ComponentType> | null) => void)\n | React.MutableRefObject<ElementByTagOrAny<ComponentType> | null>\n | null,\n ): React.ReactElement | null\n displayName?: string\n}\n\n/**\n * A component that can customize the React element type that it renders (a.k.a. a polymorphic\n * component). This is achieved by passing a prop `as={ElementType}` or `as=\"html-tag-name\"`.\n *\n * It transparently takes care of forwarding refs, and properly sets the ref type depending on the\n * element type.\n *\n * ## Recognizing props based on the polymorphic type\n *\n * The `ComponentType` argument sets the default type for the `as` prop. Whatever the `as` prop\n * component or HTML element is, the type system will automatically allow you to pass props that are\n * not explicitly defined by you, but that are recognized as valid props to be passed to the\n * component you are rendering.\n *\n * For instance, see the following example:\n *\n * ```jsx\n * <Box as=\"label\" htmlFor=\"field-id\">Hello</Box>\n * ```\n *\n * The `htmlFor` prop is exclusive to label elements. If you omit the `as=\"label\"` prop, the type\n * system will consider the `htmlFor` prop to be an error. The same happens if you pass a value of\n * an incorrect type to such prop. For instance, the example below will issue a type error:\n *\n * ```jsx\n * <Box as=\"label\" htmlFor={123}>Hello</Box>\n * ```\n *\n * ## Omitting or obfuscating the `className` prop\n *\n * If a set of props include the `className` prop, we replace it with a `exceptionallySetClassName`\n * prop instead.\n *\n * This is to discourage customizing design system components via custom styling, while still\n * leaving the door open to do it as an escape hatch when the design system still has shortcomings\n * with respect to the product designs we want to achieve.\n *\n * The cumbersome name also serves the purpose of aiding in easily searching for the places in the\n * code where this escape hatch was needed, in order to identify areas where the design system\n * components need to improve to better match our needs.\n *\n * This behaviour can be customized via an optional second generic argument that allows to disable\n * this feature, or to omit the `className` altogether without replacing it with the obfuscated prop\n * name.\n *\n * @deprecated Use Ariakit's composition instead (https://ariakit.org/guide/composition)\n */\ninterface PolymorphicComponent<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode = 'obfuscateClassName',\n> {\n <TT extends React.ElementType = ComponentType>(\n props: PolymorphicComponentProps<TT, OwnProps, ShouldObfuscateClassName>,\n ): React.ReactElement | null\n readonly $$typeof: symbol\n defaultProps?: Partial<\n PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>\n >\n propTypes?: React.WeakValidationMap<\n PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>\n >\n displayName?: string\n}\n\n/**\n * A wrapper to use React.forwardRef with polymorphic components in a type-safe manner. This is a\n * convenience over merely using React.forwardRef directly, and then manually forcing the resulting\n * value to be typed using `as PolymorphicComponent<…>`.\n *\n * @deprecated Use Ariakit's composition instead (https://ariakit.org/guide/composition)\n */\nfunction polymorphicComponent<\n ComponentType extends React.ElementType = 'div',\n OwnProps = EmptyObject,\n ShouldObfuscateClassName extends ObfuscateClassNameMode = 'obfuscateClassName',\n>(render: ForwardRefFunction<ComponentType, OwnProps, ShouldObfuscateClassName>) {\n return React.forwardRef(render) as PolymorphicComponent<\n ComponentType,\n OwnProps,\n ShouldObfuscateClassName\n >\n}\n\nexport type { PolymorphicComponent }\nexport { polymorphicComponent }\n"],"names":["polymorphicComponent","render","React","forwardRef"],"mappings":";;AAAA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,oBAAoBA,CAI3BC,MAA6E,EAAE;AAC7E,EAAA,oBAAOC,KAAK,CAACC,UAAU,CAACF,MAAM,CAAC,CAAA;AAKnC;;;;"}
|
|
1
|
+
{"version":3,"file":"polymorphism.js","sources":["../../src/utils/polymorphism.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport * as React from 'react'\n\nimport type { ObfuscatedClassName } from './common-types'\n\ntype Merge<P1, P2> = Omit<P1, keyof P2> & P2\n\ntype EmptyObject = {\n [K in any]: never\n}\n\ntype ObfuscateClassNameMode = 'keepClassName' | 'obfuscateClassName' | 'omitClassName'\n\n/**\n * If a set of props include the `className` prop, we replace it with a `exceptionallySetClassName`\n * prop instead.\n *\n * This can be customized via the second generic parameter, as there are cases where it may be\n * needed to omit this behaviour and keep the `className`. You can also instruct it to remove the\n * `className` prop while not replacing it with the `exceptionallySetClassName` one.\n *\n * @see ObfuscatedClassName['exceptionallySetClassName'] for details about this prop\n * @see PolymorphicComponent for details about this feature\n */\ntype WithObfuscatedClassName<\n Props,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> = 'className' extends keyof Props\n ? ShouldObfuscateClassName extends 'obfuscateClassName'\n ? Omit<Props, 'className'> & ObfuscatedClassName\n : ShouldObfuscateClassName extends 'omitClassName'\n ? Omit<Props, 'className'>\n : ShouldObfuscateClassName extends 'keepClassName'\n ? Props\n : never\n : Props\n\ntype PolymorphicProp<ComponentType extends React.ElementType> = {\n /**\n * Used to instruct this component what React element to render as. It can be both a string\n * representing a HTML tag name, or a React component.\n *\n * When using this prop, the component you apply it to will also recognize in its props types\n * all the props from the component or HTML element you are rendering it as.\n *\n * Some uses for this feature:\n *\n * - Using some of our layout components, while at the same time being able to set them to use\n * semantic HTML elements needed for accessibility purposes (e.g. `nav`, `main`, etc).\n * - Using a design system link component, but have it internally use a client-side router link\n * implemented via a React component (e.g. react-router's `Link`).\n *\n * Keep in mind that not all compositions of this kind may work well, especially when composing\n * with another React component and not with a HTML tag name. In particular, if the components\n * being composed have opposing concerns of clashing features (e.g. they have contradicting\n * styles applied to them) things may not go well. In those cases prefer to nest them instead.\n *\n * @see PolymorphicComponent\n */\n as?: ComponentType\n}\n\n/**\n * Given a component or element type, and a set of additional props, this builds the entire set of\n * props for a polymorphic component.\n *\n * It does three things:\n *\n * 1. it merges the element type props with the `OwnProps`\n * 2. it adds the `as` prop to allow for polymorphism to happen\n * 3. it optionally obfuscates or omits the className prop if present\n *\n * @see PolymorphicProp\n * @see WithObfuscatedClassName\n */\ntype PolymorphicComponentProps<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> = Merge<\n WithObfuscatedClassName<React.ComponentProps<ComponentType>, ShouldObfuscateClassName>,\n OwnProps & PolymorphicProp<ComponentType>\n>\n\ntype ElementTagNameMap = HTMLElementTagNameMap &\n Pick<SVGElementTagNameMap, Exclude<keyof SVGElementTagNameMap, keyof HTMLElementTagNameMap>>\n\ntype ElementByTag<TagName extends keyof ElementTagNameMap> = ElementTagNameMap[TagName]\n\ntype ElementByTagOrAny<ComponentType extends React.ElementType> =\n ComponentType extends keyof ElementTagNameMap ? ElementByTag<ComponentType> : any\n\n/**\n * The function passed to React.forwardRef, but typed in a way that's prepared for polymorphism via\n * the `as` prop. It also allows to specify if the `className` prop should be obfuscated or omitted.\n *\n * @see PolymorphicComponentProps\n * @see WithObfuscatedClassName\n */\ninterface ForwardRefFunction<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode,\n> {\n (\n props: PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>,\n ref:\n | ((instance: ElementByTagOrAny<ComponentType> | null) => void)\n | React.MutableRefObject<ElementByTagOrAny<ComponentType> | null>\n | null,\n ): React.ReactElement | null\n displayName?: string\n}\n\n/**\n * A component that can customize the React element type that it renders (a.k.a. a polymorphic\n * component). This is achieved by passing a prop `as={ElementType}` or `as=\"html-tag-name\"`.\n *\n * It transparently takes care of forwarding refs, and properly sets the ref type depending on the\n * element type.\n *\n * ## Recognizing props based on the polymorphic type\n *\n * The `ComponentType` argument sets the default type for the `as` prop. Whatever the `as` prop\n * component or HTML element is, the type system will automatically allow you to pass props that are\n * not explicitly defined by you, but that are recognized as valid props to be passed to the\n * component you are rendering.\n *\n * For instance, see the following example:\n *\n * ```jsx\n * <Box as=\"label\" htmlFor=\"field-id\">Hello</Box>\n * ```\n *\n * The `htmlFor` prop is exclusive to label elements. If you omit the `as=\"label\"` prop, the type\n * system will consider the `htmlFor` prop to be an error. The same happens if you pass a value of\n * an incorrect type to such prop. For instance, the example below will issue a type error:\n *\n * ```jsx\n * <Box as=\"label\" htmlFor={123}>Hello</Box>\n * ```\n *\n * ## Omitting or obfuscating the `className` prop\n *\n * If a set of props include the `className` prop, we replace it with a `exceptionallySetClassName`\n * prop instead.\n *\n * This is to discourage customizing design system components via custom styling, while still\n * leaving the door open to do it as an escape hatch when the design system still has shortcomings\n * with respect to the product designs we want to achieve.\n *\n * The cumbersome name also serves the purpose of aiding in easily searching for the places in the\n * code where this escape hatch was needed, in order to identify areas where the design system\n * components need to improve to better match our needs.\n *\n * This behaviour can be customized via an optional second generic argument that allows to disable\n * this feature, or to omit the `className` altogether without replacing it with the obfuscated prop\n * name.\n *\n * @deprecated Use Ariakit's composition instead (https://ariakit.org/guide/composition)\n */\ninterface PolymorphicComponent<\n ComponentType extends React.ElementType,\n OwnProps,\n ShouldObfuscateClassName extends ObfuscateClassNameMode = 'obfuscateClassName',\n> {\n <TT extends React.ElementType = ComponentType>(\n props: PolymorphicComponentProps<TT, OwnProps, ShouldObfuscateClassName>,\n ): React.ReactElement | null\n readonly $$typeof: symbol\n defaultProps?: Partial<\n PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>\n >\n propTypes?: React.WeakValidationMap<\n PolymorphicComponentProps<ComponentType, OwnProps, ShouldObfuscateClassName>\n >\n displayName?: string\n}\n\n/**\n * A wrapper to use React.forwardRef with polymorphic components in a type-safe manner. This is a\n * convenience over merely using React.forwardRef directly, and then manually forcing the resulting\n * value to be typed using `as PolymorphicComponent<…>`.\n *\n * @deprecated Use Ariakit's composition instead (https://ariakit.org/guide/composition)\n */\nfunction polymorphicComponent<\n ComponentType extends React.ElementType = 'div',\n OwnProps = EmptyObject,\n ShouldObfuscateClassName extends ObfuscateClassNameMode = 'obfuscateClassName',\n>(render: ForwardRefFunction<ComponentType, OwnProps, ShouldObfuscateClassName>) {\n return React.forwardRef(render) as PolymorphicComponent<\n ComponentType,\n OwnProps,\n ShouldObfuscateClassName\n >\n}\n\nexport type { PolymorphicComponent, PolymorphicComponentProps }\nexport { polymorphicComponent }\n"],"names":["polymorphicComponent","render","React","forwardRef"],"mappings":";;AAAA;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,oBAAoBA,CAI3BC,MAA6E,EAAE;AAC7E,EAAA,oBAAOC,KAAK,CAACC,UAAU,CAACF,MAAM,CAAC,CAAA;AAKnC;;;;"}
|
package/lib/avatar/avatar.d.ts
CHANGED
|
@@ -1,21 +1,59 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ObfuscatedClassName } from '../utils/common-types';
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
import type { PolymorphicComponentProps } from '../utils/polymorphism';
|
|
4
|
+
import type { AvatarImage as AvatarImageProp, AvatarShape, AvatarSize } from './utils';
|
|
5
|
+
/**
|
|
6
|
+
* Props for the `Avatar` component.
|
|
7
|
+
*/
|
|
8
|
+
type AvatarOwnProps = ObfuscatedClassName & {
|
|
9
|
+
/**
|
|
10
|
+
* The rendered avatar size, in CSS pixels.
|
|
11
|
+
*/
|
|
12
|
+
size: AvatarSize;
|
|
13
|
+
/**
|
|
14
|
+
* The avatar shape.
|
|
15
|
+
*
|
|
16
|
+
* @default 'circle'
|
|
17
|
+
*/
|
|
18
|
+
shape?: AvatarShape;
|
|
19
|
+
/**
|
|
20
|
+
* The display name represented by the avatar.
|
|
21
|
+
*
|
|
22
|
+
* Used as the default accessible label, to generate fallback initials, and
|
|
23
|
+
* to assign the deterministic background color when rendering initials.
|
|
24
|
+
*/
|
|
25
|
+
name?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The avatar image.
|
|
28
|
+
*
|
|
29
|
+
* Pass a string for a single image URL, or a source map keyed by intrinsic
|
|
30
|
+
* image width. Source maps render as native `srcSet`/`sizes` hints, with
|
|
31
|
+
* the largest valid source used as the fallback `src`.
|
|
32
|
+
*/
|
|
33
|
+
image?: AvatarImageProp;
|
|
34
|
+
/**
|
|
35
|
+
* Accessible text for the avatar image.
|
|
36
|
+
*
|
|
37
|
+
* Defaults to `name`. Pass an empty string when the avatar is decorative.
|
|
38
|
+
*/
|
|
39
|
+
alt?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Test identifier applied to the avatar root element.
|
|
42
|
+
*/
|
|
43
|
+
'data-testid'?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Avatar owns its root sizing styles. Use `exceptionallySetClassName` for the styling escape
|
|
46
|
+
* hatch.
|
|
47
|
+
*/
|
|
48
|
+
style?: never;
|
|
16
49
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
50
|
+
type AvatarProps<ComponentType extends React.ElementType = 'div'> = PolymorphicComponentProps<ComponentType, AvatarOwnProps, 'omitClassName'>;
|
|
51
|
+
/**
|
|
52
|
+
* Displays an avatar from an image URL, a source map keyed by intrinsic
|
|
53
|
+
* image width, or initials derived from the provided name (with a background
|
|
54
|
+
* color).
|
|
55
|
+
*/
|
|
56
|
+
declare const Avatar: import("../utils/polymorphism").PolymorphicComponent<"div", AvatarOwnProps, "omitClassName">;
|
|
21
57
|
export { Avatar };
|
|
58
|
+
export type { AvatarProps };
|
|
59
|
+
export type { AvatarImage, AvatarShape, AvatarSize } from './utils';
|