@automattic/vip-design-system 2.1.0 → 2.2.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.
@@ -5,7 +5,6 @@
5
5
  import { Argument } from 'classnames';
6
6
  import { ImageProps, ThemeUIStyleObject } from 'theme-ui';
7
7
  export interface AvatarProps {
8
- isVIP?: boolean;
9
8
  size?: number;
10
9
  src?: string;
11
10
  name?: string;
@@ -7,7 +7,7 @@ var _react = require("react");
7
7
  var _themeUi = require("theme-ui");
8
8
  var _ = require("..");
9
9
  var _jsxRuntime = require("theme-ui/jsx-runtime");
10
- var _excluded = ["isVIP", "name", "size", "src", "className", "sx"];
10
+ var _excluded = ["name", "size", "src", "className", "sx"];
11
11
  /**
12
12
  * External dependencies
13
13
  */
@@ -18,9 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
18
18
  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); }
19
19
  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; }
20
20
  var Avatar = exports.Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
21
- var _ref$isVIP = _ref.isVIP,
22
- isVIP = _ref$isVIP === void 0 ? false : _ref$isVIP,
23
- name = _ref.name,
21
+ var name = _ref.name,
24
22
  _ref$size = _ref.size,
25
23
  size = _ref$size === void 0 ? 32 : _ref$size,
26
24
  src = _ref.src,
@@ -31,21 +29,15 @@ var Avatar = exports.Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
31
29
  return (0, _jsxRuntime.jsx)(_.Box, _extends({
32
30
  sx: _extends({
33
31
  borderRadius: '100%',
34
- height: size + 2,
35
- // +2 to compensate padding on both sides
36
- width: size + 2,
37
- // +2 to compensate padding on both sides
38
- borderWidth: '2px',
39
- borderStyle: 'solid',
40
- borderColor: isVIP || isVIP === undefined ? 'primary' : 'transparent',
32
+ height: size,
33
+ width: size,
41
34
  overflow: 'hidden',
42
- backgroundColor: 'primary',
35
+ border: 'none',
36
+ backgroundColor: 'icon.primary',
43
37
  display: 'inline-flex',
44
38
  alignItems: 'center',
45
39
  justifyContent: 'center',
46
- color: 'white',
47
- padding: '1px',
48
- // this should probably be replaced with a token
40
+ color: 'inverse',
49
41
  textAlign: 'center'
50
42
  }, sx),
51
43
  className: (0, _classnames["default"])('vip-avatar-component', className),
@@ -63,10 +55,10 @@ var Avatar = exports.Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (_ref
63
55
  }) : (0, _jsxRuntime.jsx)(_.Text, {
64
56
  as: "span",
65
57
  sx: {
66
- color: 'white',
58
+ color: 'icon.inverse',
67
59
  mb: 0,
68
60
  fontWeight: 'bold',
69
- fontSize: 0,
61
+ fontSize: 2,
70
62
  textTransform: 'uppercase'
71
63
  },
72
64
  children: name ? name.charAt(0) : null
@@ -13,4 +13,5 @@ declare const _default: {
13
13
  };
14
14
  export default _default;
15
15
  type Story = StoryObj<typeof Avatar>;
16
- export declare const Default: Story;
16
+ export declare const Default: () => import("react").JSX.Element;
17
+ export declare const WithName: Story;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports["default"] = exports.Default = void 0;
4
+ exports["default"] = exports.WithName = exports.Default = void 0;
5
5
  var _ = require("..");
6
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
6
7
  /**
7
8
  * External dependencies
8
9
  */
@@ -13,4 +14,20 @@ var _default = exports["default"] = {
13
14
  title: 'Avatar',
14
15
  component: _.Avatar
15
16
  };
16
- var Default = exports.Default = {};
17
+ var COMMON_SIZES = [128, 64, 48, 32, 24, 16];
18
+ var Default = exports.Default = function Default() {
19
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
20
+ children: COMMON_SIZES.map(function (size) {
21
+ return (0, _jsxRuntime.jsx)(_.Avatar, {
22
+ size: size,
23
+ src: "https://i.pravatar.cc/100"
24
+ }, size);
25
+ })
26
+ });
27
+ };
28
+ var WithName = exports.WithName = {
29
+ args: {
30
+ name: 'Kitty',
31
+ size: 30
32
+ }
33
+ };
@@ -39,9 +39,6 @@ var Checkbox = exports.Checkbox = function Checkbox(_ref3) {
39
39
  variant = 'disabled';
40
40
  }
41
41
  return (0, _jsxRuntime.jsx)(StyledCheckbox, _extends({
42
- sx: {
43
- opacity: disabled ? 0.4 : 1
44
- },
45
42
  onCheckedChange: disabled ? undefined : onCheckedChange,
46
43
  "aria-disabled": disabled,
47
44
  variant: variant
@@ -33,7 +33,7 @@ var Default = exports.Default = function Default() {
33
33
  checked2 = _useState2[0],
34
34
  setChecked2 = _useState2[1];
35
35
  return (0, _jsxRuntime.jsxs)(_.Form.Root, {
36
- children: [['primary', 'success', 'brand'].map(function (variant) {
36
+ children: [['primary', 'brand'].map(function (variant) {
37
37
  return (0, _jsxRuntime.jsxs)(_.Form.Fieldset, {
38
38
  children: [(0, _jsxRuntime.jsxs)(_.Form.Legend, {
39
39
  children: ["Tell me your ", variant, " prefereces"]
@@ -120,7 +120,7 @@ var Indeterminate = exports.Indeterminate = function Indeterminate() {
120
120
  }
121
121
  }, [checkRef]);
122
122
  return (0, _jsxRuntime.jsxs)(_.Form.Root, {
123
- children: [['primary', 'success', 'brand'].map(function (variant) {
123
+ children: [['primary', 'brand'].map(function (variant) {
124
124
  return (0, _jsxRuntime.jsxs)(_.Form.Fieldset, {
125
125
  children: [(0, _jsxRuntime.jsxs)(_.Form.Legend, {
126
126
  children: ["Indeterminate state ", variant]
@@ -7,6 +7,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
7
7
  // The output willl be 16px because of the 1px border.
8
8
  var CHECKBOX_SIZE = 14;
9
9
  var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
10
+ var variantColor = variant === 'disabled' ? 'input.background.disabled' : variant;
10
11
  return _extends({
11
12
  all: 'unset',
12
13
  position: 'relative',
@@ -14,7 +15,7 @@ var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
14
15
  }, _Input.baseControlBorderStyle, _Input.baseControlFocusStyle, {
15
16
  width: CHECKBOX_SIZE,
16
17
  height: CHECKBOX_SIZE,
17
- borderRadius: 1,
18
+ borderRadius: 0,
18
19
  display: 'flex',
19
20
  justifyContent: 'center',
20
21
  '&[aria-disabled="true"]': {
@@ -22,10 +23,10 @@ var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
22
23
  cursor: 'not-allowed',
23
24
  pointerEvents: 'none'
24
25
  },
25
- '&[data-state=checked]': {
26
- backgroundColor: variant,
27
- color: variant,
28
- borderColor: variant
26
+ '&[data-state=checked], &[data-state=indeterminate]': {
27
+ backgroundColor: variantColor,
28
+ color: variantColor,
29
+ borderColor: variantColor
29
30
  },
30
31
  '& ~ label': {
31
32
  fontWeight: 'regular',
@@ -35,23 +36,27 @@ var checkboxStyle = exports.checkboxStyle = function checkboxStyle(variant) {
35
36
  },
36
37
  svg: {
37
38
  position: 'absolute',
39
+ fill: 'currentColor',
38
40
  top: 0,
39
41
  left: 0
40
42
  }
41
43
  });
42
44
  };
43
45
  var checkboxIndicatorStyle = exports.checkboxIndicatorStyle = function checkboxIndicatorStyle(variant) {
46
+ var backgroundColor = variant === 'disabled' ? 'icon.inverse-disabled' : 'icon.inverse';
44
47
  return {
45
48
  width: 14,
46
49
  height: 14,
47
- backgroundImage: "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='1 1 14 14' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.9259 4.9995L6.15142 12.4008L2.92603 9.33023L4.2591 7.92994L6.15142 9.73143L12.5928 3.59921L13.9259 4.9995Z' fill='white'/%3E%3C/svg%3E\")",
50
+ backgroundColor: backgroundColor,
51
+ maskImage: "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='1 1 14 14' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.9259 4.9995L6.15142 12.4008L2.92603 9.33023L4.2591 7.92994L6.15142 9.73143L12.5928 3.59921L13.9259 4.9995Z' fill='currentcolor'/%3E%3C/svg%3E\")",
48
52
  '&[data-state=indeterminate]': {
49
- marginTop: '6px',
50
- backgroundImage: 'none',
51
- backgroundColor: variant,
53
+ maskImage: 'none',
54
+ backgroundColor: backgroundColor,
52
55
  position: 'absolute',
53
- width: 10,
54
- height: 2
56
+ top: '50%',
57
+ width: 8,
58
+ height: 2,
59
+ marginTop: '-1px'
55
60
  }
56
61
  };
57
62
  };
@@ -32,7 +32,7 @@ var Default = exports.Default = function Default() {
32
32
  setChecked(_extends({}, checked, (_extends2 = {}, _extends2[radioName] = value, _extends2)));
33
33
  };
34
34
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
35
- children: [['primary', 'success', 'brand'].map(function (variant) {
35
+ children: [['primary', 'brand'].map(function (variant) {
36
36
  return (0, _jsxRuntime.jsxs)(_2.Box, {
37
37
  children: [(0, _jsxRuntime.jsx)(_2.Heading, {
38
38
  as: "h2",
@@ -82,7 +82,6 @@ var VIPDashboardLike = exports.VIPDashboardLike = {
82
82
  children: [(0, _jsxRuntime.jsx)(_.Toolbar.Separator, {}), (0, _jsxRuntime.jsxs)("a", {
83
83
  href: "/",
84
84
  children: [(0, _jsxRuntime.jsx)(_system.Avatar, {
85
- isVIP: true,
86
85
  name: "John Doe",
87
86
  src: "https://i.pravatar.cc/80"
88
87
  }), (0, _jsxRuntime.jsx)(_ScreenReaderText["default"], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "storybook build",
@@ -16,4 +16,18 @@ export default {
16
16
 
17
17
  type Story = StoryObj< typeof Avatar >;
18
18
 
19
- export const Default: Story = {};
19
+ const COMMON_SIZES = [ 128, 64, 48, 32, 24, 16 ];
20
+
21
+ export const Default = () => (
22
+ <>
23
+ { COMMON_SIZES.map( size => (
24
+ <Avatar key={ size } size={ size } src="https://i.pravatar.cc/100" />
25
+ ) ) }
26
+ </>
27
+ );
28
+ export const WithName: Story = {
29
+ args: {
30
+ name: 'Kitty',
31
+ size: 30,
32
+ },
33
+ };
@@ -11,7 +11,6 @@ import { Image, ImageProps, ThemeUIStyleObject } from 'theme-ui';
11
11
  import { Box, Text } from '..';
12
12
 
13
13
  export interface AvatarProps {
14
- isVIP?: boolean;
15
14
  size?: number;
16
15
  src?: string;
17
16
  name?: string;
@@ -23,24 +22,21 @@ type AvatarImageProps = AvatarProps & ImageProps;
23
22
 
24
23
  export const Avatar = forwardRef< HTMLElement, AvatarImageProps >(
25
24
  (
26
- { isVIP = false, name, size = 32, src, className, sx = {}, ...props }: AvatarImageProps,
25
+ { name, size = 32, src, className, sx = {}, ...props }: AvatarImageProps,
27
26
  ref: Ref< HTMLElement >
28
27
  ) => (
29
28
  <Box
30
29
  sx={ {
31
30
  borderRadius: '100%',
32
- height: size + 2, // +2 to compensate padding on both sides
33
- width: size + 2, // +2 to compensate padding on both sides
34
- borderWidth: '2px',
35
- borderStyle: 'solid',
36
- borderColor: isVIP || isVIP === undefined ? 'primary' : 'transparent',
31
+ height: size,
32
+ width: size,
37
33
  overflow: 'hidden',
38
- backgroundColor: 'primary',
34
+ border: 'none',
35
+ backgroundColor: 'icon.primary',
39
36
  display: 'inline-flex',
40
37
  alignItems: 'center',
41
38
  justifyContent: 'center',
42
- color: 'white',
43
- padding: '1px', // this should probably be replaced with a token
39
+ color: 'inverse',
44
40
  textAlign: 'center',
45
41
  ...sx,
46
42
  } }
@@ -63,10 +59,10 @@ export const Avatar = forwardRef< HTMLElement, AvatarImageProps >(
63
59
  <Text
64
60
  as="span"
65
61
  sx={ {
66
- color: 'white',
62
+ color: 'icon.inverse',
67
63
  mb: 0,
68
64
  fontWeight: 'bold',
69
- fontSize: 0,
65
+ fontSize: 2,
70
66
  textTransform: 'uppercase',
71
67
  } }
72
68
  >
@@ -61,7 +61,7 @@ export const Default = () => {
61
61
 
62
62
  return (
63
63
  <Form.Root>
64
- { ( [ 'primary', 'success', 'brand' ] as CheckboxProps[ 'variant' ][] ).map( variant => (
64
+ { ( [ 'primary', 'brand' ] as CheckboxProps[ 'variant' ][] ).map( variant => (
65
65
  <Form.Fieldset key={ variant }>
66
66
  <Form.Legend>Tell me your { variant } prefereces</Form.Legend>
67
67
 
@@ -139,7 +139,7 @@ export const Indeterminate = () => {
139
139
 
140
140
  return (
141
141
  <Form.Root>
142
- { ( [ 'primary', 'success', 'brand' ] as CheckboxProps[ 'variant' ][] ).map( variant => (
142
+ { ( [ 'primary', 'brand' ] as CheckboxProps[ 'variant' ][] ).map( variant => (
143
143
  <Form.Fieldset key={ variant }>
144
144
  <Form.Legend>Indeterminate state { variant }</Form.Legend>
145
145
 
@@ -34,9 +34,6 @@ const Checkbox = ( {
34
34
 
35
35
  return (
36
36
  <StyledCheckbox
37
- sx={ {
38
- opacity: disabled ? 0.4 : 1,
39
- } }
40
37
  onCheckedChange={ disabled ? undefined : onCheckedChange }
41
38
  aria-disabled={ disabled }
42
39
  variant={ variant }
@@ -10,51 +10,62 @@ import {
10
10
  // The output willl be 16px because of the 1px border.
11
11
  const CHECKBOX_SIZE = 14;
12
12
 
13
- export const checkboxStyle = ( variant: string ): ThemeUIStyleObject => ( {
14
- all: 'unset',
15
- position: 'relative',
16
- backgroundColor: inputBaseBackground,
17
- ...baseControlBorderStyle,
18
- ...baseControlFocusStyle,
19
- width: CHECKBOX_SIZE,
20
- height: CHECKBOX_SIZE,
21
- borderRadius: 1,
22
- display: 'flex',
23
- justifyContent: 'center',
24
- '&[aria-disabled="true"]': {
25
- opacity: 0.7,
26
- cursor: 'not-allowed',
27
- pointerEvents: 'none',
28
- },
29
- '&[data-state=checked]': {
30
- backgroundColor: variant,
31
- color: variant,
32
- borderColor: variant,
33
- },
34
- '& ~ label': {
35
- fontWeight: 'regular',
36
- color: inputBaseText,
37
- m: 0,
38
- ml: 2,
39
- },
40
- svg: {
41
- position: 'absolute',
42
- top: 0,
43
- left: 0,
44
- },
45
- } );
13
+ export const checkboxStyle = ( variant: string ): ThemeUIStyleObject => {
14
+ const variantColor = variant === 'disabled' ? 'input.background.disabled' : variant;
46
15
 
47
- export const checkboxIndicatorStyle = ( variant: string ): ThemeUIStyleObject => ( {
48
- width: 14,
49
- height: 14,
50
- backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='1 1 14 14' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.9259 4.9995L6.15142 12.4008L2.92603 9.33023L4.2591 7.92994L6.15142 9.73143L12.5928 3.59921L13.9259 4.9995Z' fill='white'/%3E%3C/svg%3E")`,
16
+ return {
17
+ all: 'unset',
18
+ position: 'relative',
19
+ backgroundColor: inputBaseBackground,
20
+ ...baseControlBorderStyle,
21
+ ...baseControlFocusStyle,
22
+ width: CHECKBOX_SIZE,
23
+ height: CHECKBOX_SIZE,
24
+ borderRadius: 0,
25
+ display: 'flex',
26
+ justifyContent: 'center',
27
+ '&[aria-disabled="true"]': {
28
+ opacity: 0.7,
29
+ cursor: 'not-allowed',
30
+ pointerEvents: 'none',
31
+ },
32
+ '&[data-state=checked], &[data-state=indeterminate]': {
33
+ backgroundColor: variantColor,
34
+ color: variantColor,
35
+ borderColor: variantColor,
36
+ },
37
+ '& ~ label': {
38
+ fontWeight: 'regular',
39
+ color: inputBaseText,
40
+ m: 0,
41
+ ml: 2,
42
+ },
43
+ svg: {
44
+ position: 'absolute',
45
+ fill: 'currentColor',
46
+ top: 0,
47
+ left: 0,
48
+ },
49
+ };
50
+ };
51
51
 
52
- '&[data-state=indeterminate]': {
53
- marginTop: '6px',
54
- backgroundImage: 'none',
55
- backgroundColor: variant,
56
- position: 'absolute',
57
- width: 10,
58
- height: 2,
59
- },
60
- } );
52
+ export const checkboxIndicatorStyle = ( variant: string ): ThemeUIStyleObject => {
53
+ const backgroundColor = variant === 'disabled' ? 'icon.inverse-disabled' : 'icon.inverse';
54
+
55
+ return {
56
+ width: 14,
57
+ height: 14,
58
+ backgroundColor,
59
+ maskImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='1 1 14 14' fill='none'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.9259 4.9995L6.15142 12.4008L2.92603 9.33023L4.2591 7.92994L6.15142 9.73143L12.5928 3.59921L13.9259 4.9995Z' fill='currentcolor'/%3E%3C/svg%3E")`,
60
+
61
+ '&[data-state=indeterminate]': {
62
+ maskImage: 'none',
63
+ backgroundColor,
64
+ position: 'absolute',
65
+ top: '50%',
66
+ width: 8,
67
+ height: 2,
68
+ marginTop: '-1px',
69
+ },
70
+ };
71
+ };
@@ -62,7 +62,7 @@ export const Default = () => {
62
62
 
63
63
  return (
64
64
  <>
65
- { ( [ 'primary', 'success', 'brand' ] as RadioProps[ 'variant' ][] ).map( variant => (
65
+ { ( [ 'primary', 'brand' ] as RadioProps[ 'variant' ][] ).map( variant => (
66
66
  <Box key={ variant }>
67
67
  <Heading as="h2" sx={ { textTransform: 'capitalize' } }>
68
68
  { variant }
@@ -94,7 +94,7 @@ export const VIPDashboardLike: Story = {
94
94
  <Toolbar.Separator />
95
95
 
96
96
  <a href="/">
97
- <Avatar isVIP name="John Doe" src="https://i.pravatar.cc/80" />
97
+ <Avatar name="John Doe" src="https://i.pravatar.cc/80" />
98
98
  <ScreenReaderText>John Doe</ScreenReaderText>
99
99
  </a>
100
100
  </Toolbar.UtilNav>