@workday/canvas-kit-react 15.0.0-alpha.0076-next.0 → 15.0.0-alpha.0077-next.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.
Files changed (57) hide show
  1. package/avatar/index.ts +4 -0
  2. package/avatar/lib/Avatar.tsx +85 -243
  3. package/avatar/lib/AvatarImage.tsx +20 -0
  4. package/avatar/lib/AvatarName.tsx +32 -0
  5. package/avatar/lib/BaseAvatar.tsx +127 -0
  6. package/avatar/lib/getInitialsFromName.ts +11 -0
  7. package/dist/commonjs/avatar/index.d.ts +4 -0
  8. package/dist/commonjs/avatar/index.d.ts.map +1 -1
  9. package/dist/commonjs/avatar/index.js +4 -0
  10. package/dist/commonjs/avatar/lib/Avatar.d.ts +183 -185
  11. package/dist/commonjs/avatar/lib/Avatar.d.ts.map +1 -1
  12. package/dist/commonjs/avatar/lib/Avatar.js +29 -113
  13. package/dist/commonjs/avatar/lib/AvatarImage.d.ts +6 -0
  14. package/dist/commonjs/avatar/lib/AvatarImage.d.ts.map +1 -0
  15. package/dist/commonjs/avatar/lib/AvatarImage.js +15 -0
  16. package/dist/commonjs/avatar/lib/AvatarName.d.ts +14 -0
  17. package/dist/commonjs/avatar/lib/AvatarName.d.ts.map +1 -0
  18. package/dist/commonjs/avatar/lib/AvatarName.js +16 -0
  19. package/dist/commonjs/avatar/lib/BaseAvatar.d.ts +148 -0
  20. package/dist/commonjs/avatar/lib/BaseAvatar.d.ts.map +1 -0
  21. package/dist/commonjs/avatar/lib/BaseAvatar.js +47 -0
  22. package/dist/commonjs/avatar/lib/getInitialsFromName.d.ts +2 -0
  23. package/dist/commonjs/avatar/lib/getInitialsFromName.d.ts.map +1 -0
  24. package/dist/commonjs/avatar/lib/getInitialsFromName.js +13 -0
  25. package/dist/commonjs/expandable/lib/ExpandableAvatar.d.ts +1 -1
  26. package/dist/commonjs/expandable/lib/ExpandableAvatar.d.ts.map +1 -1
  27. package/dist/commonjs/expandable/lib/ExpandableAvatar.js +3 -3
  28. package/dist/commonjs/pill/lib/PillAvatar.d.ts +1 -1
  29. package/dist/commonjs/pill/lib/PillAvatar.d.ts.map +1 -1
  30. package/dist/commonjs/pill/lib/PillAvatar.js +3 -3
  31. package/dist/es6/avatar/index.d.ts +4 -0
  32. package/dist/es6/avatar/index.d.ts.map +1 -1
  33. package/dist/es6/avatar/index.js +4 -0
  34. package/dist/es6/avatar/lib/Avatar.d.ts +183 -185
  35. package/dist/es6/avatar/lib/Avatar.d.ts.map +1 -1
  36. package/dist/es6/avatar/lib/Avatar.js +29 -93
  37. package/dist/es6/avatar/lib/AvatarImage.d.ts +6 -0
  38. package/dist/es6/avatar/lib/AvatarImage.d.ts.map +1 -0
  39. package/dist/es6/avatar/lib/AvatarImage.js +12 -0
  40. package/dist/es6/avatar/lib/AvatarName.d.ts +14 -0
  41. package/dist/es6/avatar/lib/AvatarName.d.ts.map +1 -0
  42. package/dist/es6/avatar/lib/AvatarName.js +13 -0
  43. package/dist/es6/avatar/lib/BaseAvatar.d.ts +148 -0
  44. package/dist/es6/avatar/lib/BaseAvatar.d.ts.map +1 -0
  45. package/dist/es6/avatar/lib/BaseAvatar.js +44 -0
  46. package/dist/es6/avatar/lib/getInitialsFromName.d.ts +2 -0
  47. package/dist/es6/avatar/lib/getInitialsFromName.d.ts.map +1 -0
  48. package/dist/es6/avatar/lib/getInitialsFromName.js +9 -0
  49. package/dist/es6/expandable/lib/ExpandableAvatar.d.ts +1 -1
  50. package/dist/es6/expandable/lib/ExpandableAvatar.d.ts.map +1 -1
  51. package/dist/es6/expandable/lib/ExpandableAvatar.js +3 -3
  52. package/dist/es6/pill/lib/PillAvatar.d.ts +1 -1
  53. package/dist/es6/pill/lib/PillAvatar.d.ts.map +1 -1
  54. package/dist/es6/pill/lib/PillAvatar.js +3 -3
  55. package/expandable/lib/ExpandableAvatar.tsx +1 -1
  56. package/package.json +5 -5
  57. package/pill/lib/PillAvatar.tsx +1 -1
package/avatar/index.ts CHANGED
@@ -1 +1,5 @@
1
1
  export * from './lib/Avatar';
2
+ export * from './lib/AvatarImage';
3
+ export * from './lib/AvatarName';
4
+ export * from './lib/BaseAvatar';
5
+ export * from './lib/getInitialsFromName';
@@ -1,55 +1,14 @@
1
- import React, {useState} from 'react';
2
- import {Property} from 'csstype';
3
- import {createComponent, focusRing} from '@workday/canvas-kit-react/common';
4
- import {createStencil, calc, CSProps, px2rem} from '@workday/canvas-kit-styling';
5
- import {mergeStyles} from '@workday/canvas-kit-react/layout';
6
- import {borderRadius} from '@workday/canvas-kit-react/tokens';
7
- import {SystemIcon, SystemIconCircleSize, systemIconStencil} from '@workday/canvas-kit-react/icon';
1
+ import React from 'react';
8
2
 
9
- import {userIcon} from '@workday/canvas-system-icons-web';
3
+ import {createComponent} from '@workday/canvas-kit-react/common';
4
+ import {Property} from 'csstype';
5
+ import {createStencil, handleCsProp} from '@workday/canvas-kit-styling';
10
6
  import {system} from '@workday/canvas-tokens-web';
11
7
 
12
- /**
13
- * @deprecated ⚠️ `AvatarVariant` is deprecated and will be removed in a future major version. Update your types and values to use the string literal of either `light` or `dark`.
14
- */
15
- export enum AvatarVariant {
16
- Light,
17
- Dark,
18
- }
8
+ import {BaseAvatarProps, BaseAvatar, baseAvatarStencil} from './BaseAvatar';
9
+ import {AvatarNameProps} from './AvatarName';
19
10
 
20
- /**
21
- * @deprecated ⚠️ `AvatarProps` is deprecated and will be removed in a future major version. Please use the `Avatar` component from the Preview package instead (@workday/canvas-kit-preview-react/avatar).
22
- */
23
- export interface AvatarProps extends CSProps {
24
- /**
25
- * The variant of the avatar. Use `light` on dark backgrounds and `dark` on light backgrounds.
26
- * @default "light"
27
- */
28
- variant?: 'light' | 'dark' | AvatarVariant;
29
- /**
30
- * The size of the Avatar.
31
- * - `extraExtraLarge`: 7.5rem x 7.5rem (120px x 120px)
32
- * - `extraLarge`: 4.5rem x 4.5rem (64px x 64px)
33
- * - `large`: 2.5rem x 2.5rem (40px x 40px)
34
- * - `medium`: 2rem x 2rem (32px x 32px)
35
- * - `small`: 1.5rem x 1.5rem (24px x 24px)
36
- * - `small`: 1rem x 1rem (16px x 16px)
37
- * @default "medium"
38
- */
39
- size?: /** size of small */
40
- | 'extraSmall'
41
- | 'small'
42
- | 'medium'
43
- | 'large'
44
- | 'extraLarge'
45
- | 'extraExtraLarge'
46
- | (string & {})
47
- | SystemIconCircleSize
48
- | number;
49
- /**
50
- * The alt text of the Avatar image. This prop is also used for the aria-label.
51
- */
52
- altText?: string;
11
+ export interface AvatarProps extends BaseAvatarProps, AvatarNameProps {
53
12
  /**
54
13
  * The URL of the user's photo. For best fit, use square images.
55
14
  */
@@ -59,256 +18,139 @@ export interface AvatarProps extends CSProps {
59
18
  * @default "contain"
60
19
  */
61
20
  objectFit?: Property.ObjectFit;
21
+ /**
22
+ * If true, the Avatar won't forward the `name` prop to the `alt` attribute of the image. This is useful when the Avatar is purely decorative and is rendered next to a name or text.
23
+ */
24
+ isDecorative?: boolean;
62
25
  }
63
26
 
64
- /**
65
- * @deprecated `avatarStencil` is deprecated and will be removed in a future major version. Please use `Avatar` from the Preview package instead (@workday/canvas-kit-preview-react/avatar).
66
- */
67
27
  export const avatarStencil = createStencil({
68
- vars: {
69
- size: '',
70
- },
28
+ extends: baseAvatarStencil,
71
29
  parts: {
72
- icon: 'avatar-icon',
73
- image: 'avatar-image',
30
+ avatarImage: 'avatar-image',
31
+ avatarName: 'avatar-name',
74
32
  },
75
- base: ({size, iconPart, imagePart}) => ({
76
- background: system.color.bg.caution.default,
77
- position: 'relative',
78
- display: 'flex',
79
- alignItems: 'center',
80
- justifyContent: 'center',
81
- padding: 0,
82
- border: 0,
83
- overflow: 'hidden',
84
- cursor: 'default',
85
- pointerEvents: 'none',
86
- borderRadius: system.shape.round,
87
- width: size,
88
- height: size,
89
- '&:focus-visible, &.focus': {
90
- outline: 'none',
91
- ...focusRing({separation: 2}),
92
- },
93
- ':is(button)': {
94
- cursor: 'pointer',
95
- pointerEvents: 'auto',
96
- },
97
- '&:disabled, &.disabled': {
98
- opacity: system.opacity.disabled,
99
- },
100
- [iconPart]: {
101
- transition: 'opacity 150ms linear',
102
- display: 'flex',
103
- alignItems: 'center',
104
- justifyContent: 'center',
105
- [systemIconStencil.vars.size]: calc.multiply(size, 0.625),
106
- opacity: 1,
107
- },
108
- [imagePart]: {
109
- position: 'absolute',
110
- width: '100%',
111
- height: '100%',
112
- borderRadius: borderRadius.circle,
113
- transition: 'opacity 150ms linear',
114
- opacity: 0,
115
- },
116
- }),
33
+ base: {},
117
34
  modifiers: {
118
- variant: {
119
- light: ({iconPart}) => ({
120
- backgroundColor: system.color.bg.alt.default,
121
- [iconPart]: {
122
- [systemIconStencil.vars.color]: system.color.fg.default,
123
- },
124
- }),
125
- dark: ({iconPart}) => ({
126
- backgroundColor: system.color.bg.primary.default,
127
- [iconPart]: {
128
- [systemIconStencil.vars.color]: system.color.fg.inverse,
129
- },
130
- }),
131
- },
132
- size: {
133
- extraSmall: ({iconPart}) => ({
134
- width: system.space.x4,
135
- height: system.space.x4,
136
- [iconPart]: {
137
- [systemIconStencil.vars.size]: calc.multiply(system.space.x4, 0.625),
138
- },
139
- }),
140
- small: ({iconPart}) => ({
141
- width: system.space.x6,
142
- height: system.space.x6,
143
- [iconPart]: {
144
- [systemIconStencil.vars.size]: calc.multiply(system.space.x6, 0.625),
145
- },
146
- }),
147
- medium: ({iconPart}) => ({
148
- width: system.space.x8,
149
- height: system.space.x8,
150
- [iconPart]: {
151
- [systemIconStencil.vars.size]: calc.multiply(system.space.x8, 0.625),
152
- },
153
- }),
154
- large: ({iconPart}) => ({
155
- width: system.space.x10,
156
- height: system.space.x10,
157
- [iconPart]: {
158
- [systemIconStencil.vars.size]: calc.multiply(system.space.x10, 0.625),
159
- },
160
- }),
161
- extraLarge: ({iconPart}) => ({
162
- width: system.space.x16,
163
- height: system.space.x16,
164
- [iconPart]: {
165
- [systemIconStencil.vars.size]: calc.multiply(system.space.x16, 0.625),
166
- },
167
- }),
168
- extraExtraLarge: ({iconPart}) => ({
169
- width: calc.multiply(system.space.x10, 3),
170
- height: calc.multiply(system.space.x10, 3),
171
- [iconPart]: {
172
- [systemIconStencil.vars.size]: calc.multiply(calc.multiply(system.space.x10, 3), 0.625),
35
+ imageLoaded: {
36
+ false: ({avatarImagePart}) => ({
37
+ [avatarImagePart]: {
38
+ display: 'none',
173
39
  },
174
40
  }),
41
+ true: {
42
+ backgroundColor: system.color.bg.default,
43
+ },
175
44
  },
176
45
  objectFit: {
177
- contain: ({imagePart}) => ({
178
- [imagePart]: {
46
+ contain: ({avatarImagePart}) => ({
47
+ [avatarImagePart]: {
179
48
  objectFit: 'contain',
180
49
  },
181
50
  }),
182
- fill: ({imagePart}) => ({
183
- [imagePart]: {
184
- objectFit: 'fill',
185
- },
186
- }),
187
- cover: ({imagePart}) => ({
188
- [imagePart]: {
51
+ cover: ({avatarImagePart}) => ({
52
+ [avatarImagePart]: {
189
53
  objectFit: 'cover',
190
54
  },
191
55
  }),
192
- ['scale-down']: ({imagePart}) => ({
193
- [imagePart]: {
194
- objectFit: 'scale-down',
56
+ fill: ({avatarImagePart}) => ({
57
+ [avatarImagePart]: {
58
+ objectFit: 'fill',
195
59
  },
196
60
  }),
197
- none: ({imagePart}) => ({
198
- [imagePart]: {
61
+ none: ({avatarImagePart}) => ({
62
+ [avatarImagePart]: {
199
63
  objectFit: 'none',
200
64
  },
201
65
  }),
202
- ['-moz-initial']: ({imagePart}) => ({
203
- [imagePart]: {
204
- objectFit: '-moz-initial',
66
+ ['scale-down']: ({avatarImagePart}) => ({
67
+ [avatarImagePart]: {
68
+ objectFit: 'scale-down',
205
69
  },
206
70
  }),
207
- ['initial']: ({imagePart}) => ({
208
- [imagePart]: {
71
+ initial: ({avatarImagePart}) => ({
72
+ [avatarImagePart]: {
209
73
  objectFit: 'initial',
210
74
  },
211
75
  }),
212
- ['inherit']: ({imagePart}) => ({
213
- [imagePart]: {
76
+
77
+ inherit: ({avatarImagePart}) => ({
78
+ [avatarImagePart]: {
214
79
  objectFit: 'inherit',
215
80
  },
216
81
  }),
217
- ['revert']: ({imagePart}) => ({
218
- [imagePart]: {
219
- objectFit: 'revert',
220
- },
221
- }),
222
- ['unset']: ({imagePart}) => ({
223
- [imagePart]: {
82
+ unset: ({avatarImagePart}) => ({
83
+ [avatarImagePart]: {
224
84
  objectFit: 'unset',
225
85
  },
226
86
  }),
227
- },
228
- isImageLoaded: {
229
- true: ({iconPart, imagePart}) => ({
230
- [iconPart]: {
231
- opacity: 0,
87
+ ['-moz-initial']: ({avatarImagePart}) => ({
88
+ [avatarImagePart]: {
89
+ objectFit: '-moz-initial',
232
90
  },
233
- [imagePart]: {
234
- opacity: 1,
91
+ }),
92
+ ['revert']: ({avatarImagePart}) => ({
93
+ [avatarImagePart]: {
94
+ objectFit: 'revert',
235
95
  },
236
96
  }),
237
97
  },
238
98
  },
239
- defaultModifiers: {
240
- variant: 'light',
241
- objectFit: 'contain',
242
- },
243
99
  });
244
100
 
245
101
  /**
246
- * @deprecated ⚠️ `Avatar` is deprecated and will be removed in a future major version. Please use `Avatar` from the Preview package instead (@workday/canvas-kit-preview-react/avatar).
102
+ * JSDoc for Avatar. Will be part of the Component API docs
247
103
  */
248
- export const Avatar = createComponent('button')({
104
+ export const Avatar = createComponent('div')({
249
105
  displayName: 'Avatar',
106
+
250
107
  Component: (
251
- {variant, size = 'medium', altText, url, objectFit, ...elemProps}: AvatarProps,
108
+ {
109
+ url,
110
+ name,
111
+ variant,
112
+ objectFit = 'contain',
113
+ preferredInitials,
114
+ isDecorative,
115
+ size,
116
+ ...elemProps
117
+ }: AvatarProps,
252
118
  ref,
253
119
  Element
254
120
  ) => {
255
- const [imageLoaded, setImageLoaded] = useState(false);
121
+ const [imageLoaded, setImageLoaded] = React.useState(false);
256
122
 
257
- const loadImage = () => {
123
+ const handleImageLoad = () => {
258
124
  if (!imageLoaded) {
259
125
  setImageLoaded(true);
260
126
  }
261
127
  };
262
128
 
263
- React.useLayoutEffect(() => {
264
- setImageLoaded(false);
265
- }, [url]);
266
-
267
- // TODO: Remove this warning for a hard breaking change in v13
268
- if (process.env.NODE_ENV === 'development') {
269
- if (typeof variant === 'number') {
270
- console.warn(
271
- 'Avatar: Avatar.Variant is deprecated and will be removed in v13. Please use a string literal of "light" or "dark"'
272
- );
273
- }
274
- if (typeof size === 'number') {
275
- console.warn(
276
- "Avatar: Avatar.Size is deprecated and will be removed in v13. Use the string literal values for size: 'extraSmall' | 'small | 'medium' | 'large' | 'extraLarge | 'extraExtraLarge' | (string & {})"
277
- );
278
- }
279
- }
280
-
281
129
  return (
282
- <Element
130
+ <BaseAvatar
131
+ as={Element}
283
132
  ref={ref}
284
- aria-label={Element === 'button' ? altText : undefined}
285
- {...mergeStyles(elemProps, [
286
- avatarStencil({
287
- variant:
288
- variant === AvatarVariant.Light
289
- ? 'light'
290
- : variant === AvatarVariant.Dark
291
- ? 'dark'
292
- : variant,
293
- size: typeof size === 'number' ? px2rem(size) : size,
294
- objectFit,
295
- isImageLoaded: imageLoaded,
296
- }),
297
- ])}
133
+ {...handleCsProp(elemProps, avatarStencil({variant, size, imageLoaded, objectFit}))}
298
134
  >
299
- <SystemIcon {...avatarStencil.parts.icon} icon={userIcon} />
300
- {url && <img {...avatarStencil.parts.image} src={url} alt={altText} onLoad={loadImage} />}
301
- </Element>
135
+ {url && (
136
+ <>
137
+ <BaseAvatar.Image
138
+ onLoad={handleImageLoad}
139
+ src={url}
140
+ alt={isDecorative ? undefined : name}
141
+ aria-hidden={isDecorative}
142
+ {...avatarStencil.parts.avatarImage}
143
+ />
144
+ </>
145
+ )}
146
+ {name && (!url || !imageLoaded) && (
147
+ <BaseAvatar.Name
148
+ name={name}
149
+ preferredInitials={preferredInitials}
150
+ {...avatarStencil.parts.avatarName}
151
+ />
152
+ )}
153
+ </BaseAvatar>
302
154
  );
303
155
  },
304
- subComponents: {
305
- /**
306
- * @deprecated ⚠️ `Avatar.Variant` is deprecated and will be removed in a future major version. Use the string literal of `light` or `dark`.
307
- */
308
- Variant: AvatarVariant,
309
- /**
310
- * @deprecated ⚠️ `Avatar.Size` is deprecated and will be removed in a future major version. Use the string literal values for size: 'extraSmall' | 'small | 'medium' | 'large' | 'extraLarge | 'extraExtraLarge' | (string & {})
311
- */
312
- Size: SystemIconCircleSize,
313
- },
314
156
  });
@@ -0,0 +1,20 @@
1
+ import {createComponent} from '@workday/canvas-kit-react/common';
2
+
3
+ import {handleCsProp, createStencil, CSProps} from '@workday/canvas-kit-styling';
4
+
5
+ export interface AvatarImageProps extends CSProps {}
6
+
7
+ export const avatarImageStencil = createStencil({
8
+ base: {
9
+ height: '100%',
10
+ width: '100%',
11
+ objectFit: 'cover',
12
+ },
13
+ });
14
+
15
+ export const AvatarImage = createComponent('img')({
16
+ displayName: 'AvatarImage',
17
+ Component: ({...elemProps}: AvatarImageProps, ref, Element) => {
18
+ return <Element ref={ref} {...handleCsProp(elemProps, avatarImageStencil())} />;
19
+ },
20
+ });
@@ -0,0 +1,32 @@
1
+ import {createComponent} from '@workday/canvas-kit-react/common';
2
+ import {CSProps, handleCsProp, createStencil} from '@workday/canvas-kit-styling';
3
+ import {getInitialsFromName} from './getInitialsFromName';
4
+
5
+ export interface AvatarNameProps extends CSProps {
6
+ /**
7
+ * The alt text of the Avatar image. This prop is also used for the initials. The first letter of the first name and the first letter of the second name are chosen for the initials.
8
+ */
9
+ name: string;
10
+ /**
11
+ * If you want full control over the initials, use `preferredInitials` instead.
12
+ */
13
+ preferredInitials?: string;
14
+ }
15
+
16
+ export const avatarNameStencil = createStencil({
17
+ base: {
18
+ textTransform: 'uppercase',
19
+ cursor: 'default',
20
+ },
21
+ });
22
+
23
+ export const AvatarName = createComponent('span')({
24
+ displayName: 'AvatarName',
25
+ Component: ({name, preferredInitials, ...elemProps}: AvatarNameProps, ref, Element) => {
26
+ return (
27
+ <Element ref={ref} {...handleCsProp(elemProps, avatarNameStencil())}>
28
+ {preferredInitials || getInitialsFromName(name)}
29
+ </Element>
30
+ );
31
+ },
32
+ });
@@ -0,0 +1,127 @@
1
+ import React from 'react';
2
+
3
+ import {createComponent} from '@workday/canvas-kit-react/common';
4
+
5
+ import {AvatarImage} from './AvatarImage';
6
+ import {AvatarName} from './AvatarName';
7
+ import {createStencil, cssVar, calc, handleCsProp, CSProps} from '@workday/canvas-kit-styling';
8
+ import {system, base} from '@workday/canvas-tokens-web';
9
+
10
+ export interface BaseAvatarProps extends CSProps {
11
+ /**
12
+ * Children of the BaseAvatar.
13
+ */
14
+ children?: React.ReactNode;
15
+ /**
16
+ * The variant of the Avatar.
17
+ * @default "blue"
18
+ */
19
+ variant?: 'blue' | 'amber' | 'teal' | 'purple';
20
+
21
+ /**
22
+ * The size of the Avatar.
23
+ * `extraExtraSmall` is 24px x 24px
24
+ * `extraSmall` is 32px x 32px
25
+ * `small` is 40px x 40px
26
+ * `medium` is 48px x 48px
27
+ * `large` is 72px x 72px
28
+ * `extraLarge` is 96px x 96px
29
+ * `extraExtraLarge` is 120px x 120px
30
+ * @default "medium"
31
+ */
32
+ size?:
33
+ | 'extraExtraSmall'
34
+ | 'extraSmall'
35
+ | 'small'
36
+ | 'medium'
37
+ | 'large'
38
+ | 'extraLarge'
39
+ | 'extraExtraLarge'
40
+ | (string & {});
41
+ }
42
+
43
+ export const baseAvatarStencil = createStencil({
44
+ vars: {
45
+ backgroundColor: '',
46
+ color: '',
47
+ size: '',
48
+ },
49
+ base: ({backgroundColor, color, size}) => ({
50
+ borderRadius: system.shape.round,
51
+ width: cssVar(size, calc.add(system.space.x10, system.space.x2)),
52
+ height: cssVar(size, calc.add(system.space.x10, system.space.x2)),
53
+ backgroundColor: cssVar(backgroundColor, base.blue300),
54
+ color: cssVar(color, base.blue800),
55
+ display: 'flex',
56
+ alignItems: 'center',
57
+ justifyContent: 'center',
58
+ overflow: 'hidden',
59
+ border: 'none',
60
+ ...system.type.body.medium,
61
+ }),
62
+ modifiers: {
63
+ variant: {
64
+ blue: ({backgroundColor, color}) => ({
65
+ backgroundColor: cssVar(backgroundColor, base.blue300),
66
+ color: cssVar(color, base.blue800),
67
+ }),
68
+ amber: ({backgroundColor, color}) => ({
69
+ backgroundColor: cssVar(backgroundColor, base.amber200),
70
+ color: cssVar(color, base.amber700),
71
+ }),
72
+
73
+ teal: ({backgroundColor, color}) => ({
74
+ backgroundColor: cssVar(backgroundColor, base.teal300),
75
+ color: cssVar(color, base.teal800),
76
+ }),
77
+ purple: ({backgroundColor, color}) => ({
78
+ backgroundColor: cssVar(backgroundColor, base.purple300),
79
+ color: cssVar(color, base.purple800),
80
+ }),
81
+ },
82
+ size: {
83
+ extraExtraSmall: ({size}) => ({
84
+ [size]: system.space.x6,
85
+ ...system.type.subtext.small,
86
+ }),
87
+ extraSmall: ({size}) => ({
88
+ [size]: system.space.x8,
89
+ ...system.type.subtext.medium,
90
+ }),
91
+ small: ({size}) => ({
92
+ [size]: system.space.x10,
93
+ ...system.type.body.small,
94
+ }),
95
+ medium: ({size}) => ({
96
+ [size]: calc.add(system.space.x10, system.space.x2),
97
+ ...system.type.body.medium,
98
+ }),
99
+ large: ({size}) => ({
100
+ [size]: calc.add(system.space.x16, system.space.x2),
101
+ ...system.type.heading.medium,
102
+ }),
103
+ extraLarge: ({size}) => ({
104
+ [size]: calc.add(system.space.x20, system.space.x4),
105
+ ...system.type.title.small,
106
+ }),
107
+ extraExtraLarge: ({size}) => ({
108
+ [size]: calc.multiply(system.space.x10, 3),
109
+ ...system.type.title.medium,
110
+ }),
111
+ },
112
+ },
113
+ });
114
+
115
+ /**
116
+ * JSDoc for Avatar. Will be part of the Component API docs
117
+ */
118
+ export const BaseAvatar = createComponent('div')({
119
+ displayName: 'BaseAvatar',
120
+ subComponents: {
121
+ Image: AvatarImage,
122
+ Name: AvatarName,
123
+ },
124
+ Component: ({variant, size, ...elemProps}: BaseAvatarProps, ref, Element) => {
125
+ return <Element ref={ref} {...handleCsProp(elemProps, baseAvatarStencil({variant, size}))} />;
126
+ },
127
+ });
@@ -0,0 +1,11 @@
1
+ export const getInitialsFromName = (name: string) => {
2
+ // Trim and split by one or more whitespace characters
3
+ const nameParts = name.trim().split(/\s+/).filter(Boolean);
4
+
5
+ const first = nameParts[0];
6
+ const firstInitial = first?.[0] || '';
7
+ const last = nameParts.length > 1 ? nameParts[nameParts.length - 1] : undefined;
8
+ const lastInitial = last?.[0] || '';
9
+
10
+ return `${firstInitial}${lastInitial}`;
11
+ };
@@ -1,2 +1,6 @@
1
1
  export * from './lib/Avatar';
2
+ export * from './lib/AvatarImage';
3
+ export * from './lib/AvatarName';
4
+ export * from './lib/BaseAvatar';
5
+ export * from './lib/getInitialsFromName';
2
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../avatar/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../avatar/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
@@ -15,3 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./lib/Avatar"), exports);
18
+ __exportStar(require("./lib/AvatarImage"), exports);
19
+ __exportStar(require("./lib/AvatarName"), exports);
20
+ __exportStar(require("./lib/BaseAvatar"), exports);
21
+ __exportStar(require("./lib/getInitialsFromName"), exports);