@automattic/vip-design-system 2.13.0 → 2.13.2
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/build/system/Avatar/Avatar.d.ts +1 -0
- package/build/system/Avatar/Avatar.js +4 -2
- package/build/system/Avatar/Avatar.stories.d.ts +1 -0
- package/build/system/Avatar/Avatar.stories.js +14 -1
- package/build/system/theme/generated/valet-theme-light.json +1 -1
- package/package.json +1 -1
- package/src/system/Avatar/Avatar.stories.tsx +13 -0
- package/src/system/Avatar/Avatar.tsx +52 -47
- package/src/system/theme/generated/valet-theme-light.json +1 -1
- package/tokens/valet-core/wpvip-product-core.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["name", "size", "src", "className", "sx"];
|
|
1
|
+
var _excluded = ["name", "size", "src", "className", "sx", "abbr"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
4
|
/**
|
|
@@ -21,7 +21,9 @@ export var Avatar = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
21
21
|
className = _ref.className,
|
|
22
22
|
_ref$sx = _ref.sx,
|
|
23
23
|
sx = _ref$sx === void 0 ? {} : _ref$sx,
|
|
24
|
+
abbr = _ref.abbr,
|
|
24
25
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
26
|
+
var displayName = name && !abbr ? name.charAt(0) : abbr;
|
|
25
27
|
return _jsx(Box, _extends({
|
|
26
28
|
sx: _extends({
|
|
27
29
|
borderRadius: '100%',
|
|
@@ -56,7 +58,7 @@ export var Avatar = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
56
58
|
fontSize: 2,
|
|
57
59
|
textTransform: 'uppercase'
|
|
58
60
|
},
|
|
59
|
-
children:
|
|
61
|
+
children: displayName
|
|
60
62
|
})
|
|
61
63
|
}));
|
|
62
64
|
});
|
|
@@ -26,6 +26,19 @@ export var Default = function Default() {
|
|
|
26
26
|
export var WithName = {
|
|
27
27
|
args: {
|
|
28
28
|
name: 'Kitty',
|
|
29
|
-
size: 30
|
|
29
|
+
size: 30,
|
|
30
|
+
sx: {
|
|
31
|
+
backgroundColor: '#D8A45F'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export var WithAbbreviation = {
|
|
36
|
+
args: {
|
|
37
|
+
name: 'Taylor Swift',
|
|
38
|
+
abbr: 'TS',
|
|
39
|
+
size: 64,
|
|
40
|
+
sx: {
|
|
41
|
+
backgroundColor: '#D8A45F'
|
|
42
|
+
}
|
|
30
43
|
}
|
|
31
44
|
};
|
package/package.json
CHANGED
|
@@ -29,5 +29,18 @@ export const WithName: Story = {
|
|
|
29
29
|
args: {
|
|
30
30
|
name: 'Kitty',
|
|
31
31
|
size: 30,
|
|
32
|
+
sx: {
|
|
33
|
+
backgroundColor: '#D8A45F',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export const WithAbbreviation: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
name: 'Taylor Swift',
|
|
40
|
+
abbr: 'TS',
|
|
41
|
+
size: 64,
|
|
42
|
+
sx: {
|
|
43
|
+
backgroundColor: '#D8A45F',
|
|
44
|
+
},
|
|
32
45
|
},
|
|
33
46
|
};
|
|
@@ -14,6 +14,7 @@ export interface AvatarProps {
|
|
|
14
14
|
size?: number;
|
|
15
15
|
src?: string;
|
|
16
16
|
name?: string;
|
|
17
|
+
abbr?: string;
|
|
17
18
|
className?: Argument;
|
|
18
19
|
sx?: ThemeUIStyleObject;
|
|
19
20
|
}
|
|
@@ -22,54 +23,58 @@ type AvatarImageProps = AvatarProps & ImageProps;
|
|
|
22
23
|
|
|
23
24
|
export const Avatar = forwardRef< HTMLElement, AvatarImageProps >(
|
|
24
25
|
(
|
|
25
|
-
{ name, size = 32, src, className, sx = {}, ...props }: AvatarImageProps,
|
|
26
|
+
{ name, size = 32, src, className, sx = {}, abbr, ...props }: AvatarImageProps,
|
|
26
27
|
ref: Ref< HTMLElement >
|
|
27
|
-
) =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
28
|
+
) => {
|
|
29
|
+
const displayName = name && ! abbr ? name.charAt( 0 ) : abbr;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Box
|
|
33
|
+
sx={ {
|
|
34
|
+
borderRadius: '100%',
|
|
35
|
+
height: size,
|
|
36
|
+
width: size,
|
|
37
|
+
overflow: 'hidden',
|
|
38
|
+
border: 'none',
|
|
39
|
+
display: 'inline-flex',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
justifyContent: 'center',
|
|
42
|
+
color: 'inverse',
|
|
43
|
+
textAlign: 'center',
|
|
44
|
+
...sx,
|
|
45
|
+
} }
|
|
46
|
+
className={ classNames( 'vip-avatar-component', className ) }
|
|
47
|
+
aria-hidden="true"
|
|
48
|
+
ref={ ref }
|
|
49
|
+
{ ...props }
|
|
50
|
+
>
|
|
51
|
+
{ src ? (
|
|
52
|
+
<Image
|
|
53
|
+
src={ src }
|
|
54
|
+
alt={ `Avatar image from ${ name }` }
|
|
55
|
+
sx={ {
|
|
56
|
+
borderRadius: '100%',
|
|
57
|
+
width: '100%',
|
|
58
|
+
display: 'block',
|
|
59
|
+
} }
|
|
60
|
+
/>
|
|
61
|
+
) : (
|
|
62
|
+
<Text
|
|
63
|
+
as="span"
|
|
64
|
+
sx={ {
|
|
65
|
+
color: 'icon.inverse',
|
|
66
|
+
mb: 0,
|
|
67
|
+
fontWeight: 'bold',
|
|
68
|
+
fontSize: 2,
|
|
69
|
+
textTransform: 'uppercase',
|
|
70
|
+
} }
|
|
71
|
+
>
|
|
72
|
+
{ displayName }
|
|
73
|
+
</Text>
|
|
74
|
+
) }
|
|
75
|
+
</Box>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
73
78
|
);
|
|
74
79
|
|
|
75
80
|
Avatar.displayName = 'Avatar';
|