@bspk/ui 1.1.16 → 1.1.17
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/dist/Avatar.d.ts +31 -8
- package/dist/Avatar.js +20 -10
- package/dist/Avatar.js.map +1 -1
- package/package.json +1 -1
- package/src/Avatar.tsx +55 -29
package/dist/Avatar.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import './avatar.scss';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { ColorVariant } from './utils/colorVariants';
|
|
4
|
-
import { CommonProps } from '.';
|
|
5
4
|
export type SizeVariant = 'large' | 'medium' | 'small' | 'x-large' | 'x-small' | 'xx-large' | 'xxx-large' | 'xxxx-large' | 'xxxxx-large';
|
|
6
|
-
export type AvatarProps =
|
|
5
|
+
export type AvatarProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the person or entity represented by the avatar. This is used for accessibility purposes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* Jane Doe
|
|
11
|
+
*
|
|
12
|
+
* @required
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
7
15
|
/**
|
|
8
16
|
* The size of the avatar.
|
|
9
17
|
*
|
|
@@ -16,14 +24,29 @@ export type AvatarProps = CommonProps<'aria-label'> & {
|
|
|
16
24
|
* @default grey
|
|
17
25
|
*/
|
|
18
26
|
color?: ColorVariant;
|
|
19
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* The initials to display in the avatar limited to 2 characters.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* JD;
|
|
32
|
+
*/
|
|
20
33
|
initials?: string;
|
|
21
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* The icon to display in the avatar. This needs to be an icon from the @bspk/icons library.
|
|
36
|
+
*
|
|
37
|
+
* import { SvgPerson } from '@bspk/icons/Person';
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <SvgPerson />;
|
|
41
|
+
*/
|
|
22
42
|
icon?: ReactNode;
|
|
23
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* The url to the image to display in the avatar.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* '/user/e3232/avatar.jpg';
|
|
48
|
+
*/
|
|
24
49
|
image?: string;
|
|
25
|
-
/** The number of notifications not displayed in a list. */
|
|
26
|
-
overflowCount?: number;
|
|
27
50
|
};
|
|
28
51
|
/**
|
|
29
52
|
* An avatar is a visual representation of a user or entity. It can be used to display an initials, icon, image, or an
|
|
@@ -31,7 +54,7 @@ export type AvatarProps = CommonProps<'aria-label'> & {
|
|
|
31
54
|
*
|
|
32
55
|
* @name Avatar
|
|
33
56
|
*/
|
|
34
|
-
declare function Avatar({ initials, color, size, icon, image,
|
|
57
|
+
declare function Avatar({ initials: initialsProp, color, size, icon, image, name: ariaLabel }: AvatarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
35
58
|
declare namespace Avatar {
|
|
36
59
|
var bspkName: string;
|
|
37
60
|
}
|
package/dist/Avatar.js
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { styleAdd } from './utils/styleAdd';
|
|
3
3
|
styleAdd(`[data-bspk=avatar]{--height: var(--spacing-sizing-10);--font: var(--labels-base);--foreground: var(--foreground-neutral-on-surface);--background: var(--surface-neutral-t3-low);display:flex;flex-direction:column;justify-content:center;align-items:center;padding:0;height:var(--height);width:var(--height);aspect-ratio:1/1;border-radius:999px;background-color:var(--background);color:var(--foreground);font:var(--font)}[data-bspk=avatar]:has(img){overflow:hidden}[data-bspk=avatar] img{max-width:100%}[data-bspk=avatar][data-size=x-small]{--height: var(--spacing-sizing-06);--font: var(--labels-x-small)}[data-bspk=avatar][data-size=small]{--height: var(--spacing-sizing-08);--font: var(--labels-small)}[data-bspk=avatar][data-size=medium]{--height: var(--spacing-sizing-10);--font: var(--labels-base)}[data-bspk=avatar][data-size=large]{--height: var(--spacing-sizing-12);--font: var(--labels-large)}[data-bspk=avatar][data-size=x-large]{--height: var(--spacing-sizing-14);--font: var(--subheader-x-large)}[data-bspk=avatar][data-size=xx-large]{--height: var(--spacing-sizing-17);--font: var(--subheader-xx-large)}[data-bspk=avatar][data-size=xxx-large]{--height: var(--spacing-sizing-19);--font: var(--display-regular-small)}[data-bspk=avatar][data-size=xxxx-large]{--height: var(--spacing-sizing-21);--font: var(--display-regular-medium)}[data-bspk=avatar][data-size=xxxxx-large]{--height: var(--spacing-sizing-23);--font: var(--display-regular-large)}`);;
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
|
+
import { Tooltip } from './Tooltip';
|
|
5
6
|
/**
|
|
6
7
|
* An avatar is a visual representation of a user or entity. It can be used to display an initials, icon, image, or an
|
|
7
8
|
* overflowCount.
|
|
8
9
|
*
|
|
9
10
|
* @name Avatar
|
|
10
11
|
*/
|
|
11
|
-
function Avatar({ initials, color = 'grey', size = 'small', icon, image,
|
|
12
|
+
function Avatar({ initials: initialsProp, color = 'grey', size = 'small', icon, image, name: ariaLabel }) {
|
|
12
13
|
const children = useMemo(() => {
|
|
13
|
-
if (initials)
|
|
14
|
-
return _jsx("span", { "data-initials": true, children: initials });
|
|
15
|
-
if (icon)
|
|
16
|
-
return _jsx("span", { "data-icon": true, children: icon });
|
|
17
14
|
if (image)
|
|
18
15
|
return _jsx("img", { alt: ariaLabel, src: image });
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
16
|
+
if (icon)
|
|
17
|
+
return _jsx("span", { "data-icon": true, children: icon });
|
|
18
|
+
let initials = initialsProp;
|
|
19
|
+
if (ariaLabel && !initials)
|
|
20
|
+
initials = ariaLabel
|
|
21
|
+
.split(' ')
|
|
22
|
+
.map((word) => word.charAt(0))
|
|
23
|
+
.slice(0, 2)
|
|
24
|
+
.join('')
|
|
25
|
+
.toUpperCase();
|
|
26
|
+
if (initials)
|
|
27
|
+
return _jsx("span", { "data-initials": true, children: initials.slice(0, 2) });
|
|
28
|
+
return null;
|
|
29
|
+
}, [ariaLabel, icon, image, initialsProp]);
|
|
30
|
+
if (!children)
|
|
21
31
|
return null;
|
|
22
|
-
|
|
23
|
-
return
|
|
32
|
+
const avatar = (_jsx("div", { "aria-label": ariaLabel, "data-bspk": "avatar", "data-color": color, "data-size": size, children: children }));
|
|
33
|
+
return _jsx(Tooltip, { label: ariaLabel, children: avatar });
|
|
24
34
|
}
|
|
25
35
|
Avatar.bspkName = 'Avatar';
|
|
26
36
|
export { Avatar };
|
package/dist/Avatar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":";AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAa,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":";AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAa,OAAO,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6DpC;;;;;GAKG;AACH,SAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,GAAG,MAAM,EAAE,IAAI,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAe;IACjH,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE;QAC1B,IAAI,KAAK;YAAE,OAAO,cAAK,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,GAAI,CAAC;QACtD,IAAI,IAAI;YAAE,OAAO,4CAAiB,IAAI,GAAQ,CAAC;QAE/C,IAAI,QAAQ,GAAG,YAAY,CAAC;QAE5B,IAAI,SAAS,IAAI,CAAC,QAAQ;YACtB,QAAQ,GAAG,SAAS;iBACf,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAC7B,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;iBACX,IAAI,CAAC,EAAE,CAAC;iBACR,WAAW,EAAE,CAAC;QAEvB,IAAI,QAAQ;YAAE,OAAO,gDAAqB,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAQ,CAAC;QAEvE,OAAO,IAAI,CAAC;IAChB,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3C,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,MAAM,MAAM,GAAG,CACX,4BAAiB,SAAS,eAAY,QAAQ,gBAAa,KAAK,eAAa,IAAI,YAC5E,QAAQ,GACP,CACT,CAAC;IAEF,OAAO,KAAC,OAAO,IAAC,KAAK,EAAE,SAAS,YAAG,MAAM,GAAW,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/Avatar.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import './avatar.scss';
|
|
2
2
|
import { ReactNode, useMemo } from 'react';
|
|
3
3
|
|
|
4
|
+
import { Tooltip } from './Tooltip';
|
|
4
5
|
import { ColorVariant } from './utils/colorVariants';
|
|
5
6
|
|
|
6
|
-
import { CommonProps } from '.';
|
|
7
|
-
|
|
8
7
|
export type SizeVariant =
|
|
9
8
|
| 'large'
|
|
10
9
|
| 'medium'
|
|
@@ -16,7 +15,16 @@ export type SizeVariant =
|
|
|
16
15
|
| 'xxxx-large'
|
|
17
16
|
| 'xxxxx-large';
|
|
18
17
|
|
|
19
|
-
export type AvatarProps =
|
|
18
|
+
export type AvatarProps = {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the person or entity represented by the avatar. This is used for accessibility purposes.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* Jane Doe
|
|
24
|
+
*
|
|
25
|
+
* @required
|
|
26
|
+
*/
|
|
27
|
+
name: string;
|
|
20
28
|
/**
|
|
21
29
|
* The size of the avatar.
|
|
22
30
|
*
|
|
@@ -29,14 +37,29 @@ export type AvatarProps = CommonProps<'aria-label'> & {
|
|
|
29
37
|
* @default grey
|
|
30
38
|
*/
|
|
31
39
|
color?: ColorVariant;
|
|
32
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* The initials to display in the avatar limited to 2 characters.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* JD;
|
|
45
|
+
*/
|
|
33
46
|
initials?: string;
|
|
34
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* The icon to display in the avatar. This needs to be an icon from the @bspk/icons library.
|
|
49
|
+
*
|
|
50
|
+
* import { SvgPerson } from '@bspk/icons/Person';
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* <SvgPerson />;
|
|
54
|
+
*/
|
|
35
55
|
icon?: ReactNode;
|
|
36
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The url to the image to display in the avatar.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* '/user/e3232/avatar.jpg';
|
|
61
|
+
*/
|
|
37
62
|
image?: string;
|
|
38
|
-
/** The number of notifications not displayed in a list. */
|
|
39
|
-
overflowCount?: number;
|
|
40
63
|
};
|
|
41
64
|
|
|
42
65
|
/**
|
|
@@ -45,32 +68,35 @@ export type AvatarProps = CommonProps<'aria-label'> & {
|
|
|
45
68
|
*
|
|
46
69
|
* @name Avatar
|
|
47
70
|
*/
|
|
48
|
-
function Avatar({
|
|
49
|
-
initials,
|
|
50
|
-
color = 'grey',
|
|
51
|
-
size = 'small',
|
|
52
|
-
icon,
|
|
53
|
-
image,
|
|
54
|
-
'aria-label': ariaLabel,
|
|
55
|
-
overflowCount,
|
|
56
|
-
}: AvatarProps) {
|
|
71
|
+
function Avatar({ initials: initialsProp, color = 'grey', size = 'small', icon, image, name: ariaLabel }: AvatarProps) {
|
|
57
72
|
const children = useMemo(() => {
|
|
58
|
-
if (initials) return <span data-initials>{initials}</span>;
|
|
59
|
-
if (icon) return <span data-icon>{icon}</span>;
|
|
60
73
|
if (image) return <img alt={ariaLabel} src={image} />;
|
|
61
|
-
if (
|
|
74
|
+
if (icon) return <span data-icon>{icon}</span>;
|
|
75
|
+
|
|
76
|
+
let initials = initialsProp;
|
|
77
|
+
|
|
78
|
+
if (ariaLabel && !initials)
|
|
79
|
+
initials = ariaLabel
|
|
80
|
+
.split(' ')
|
|
81
|
+
.map((word) => word.charAt(0))
|
|
82
|
+
.slice(0, 2)
|
|
83
|
+
.join('')
|
|
84
|
+
.toUpperCase();
|
|
85
|
+
|
|
86
|
+
if (initials) return <span data-initials>{initials.slice(0, 2)}</span>;
|
|
87
|
+
|
|
62
88
|
return null;
|
|
63
|
-
}, [ariaLabel, icon, image,
|
|
89
|
+
}, [ariaLabel, icon, image, initialsProp]);
|
|
64
90
|
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)}
|
|
72
|
-
</>
|
|
91
|
+
if (!children) return null;
|
|
92
|
+
|
|
93
|
+
const avatar = (
|
|
94
|
+
<div aria-label={ariaLabel} data-bspk="avatar" data-color={color} data-size={size}>
|
|
95
|
+
{children}
|
|
96
|
+
</div>
|
|
73
97
|
);
|
|
98
|
+
|
|
99
|
+
return <Tooltip label={ariaLabel}>{avatar}</Tooltip>;
|
|
74
100
|
}
|
|
75
101
|
|
|
76
102
|
Avatar.bspkName = 'Avatar';
|