@automattic/vip-design-system 0.14.2 → 0.15.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 (34) hide show
  1. package/.prettierignore +1 -0
  2. package/README.md +26 -0
  3. package/build/system/Button/Button.js +9 -4
  4. package/build/system/NewDialog/DialogClose.js +26 -11
  5. package/build/system/NewDialog/DialogClose.test.js +1 -1
  6. package/build/system/NewDialog/DialogDescription.js +1 -1
  7. package/build/system/NewDialog/DialogTitle.js +1 -1
  8. package/build/system/NewDialog/NewDialog.js +3 -25
  9. package/build/system/NewDialog/NewDialog.stories.js +34 -9
  10. package/build/system/NewDialog/index.js +14 -1
  11. package/build/system/Notification/Notification.js +1 -1
  12. package/build/system/ScreenReaderText/ScreenReader.test.js +2 -2
  13. package/build/system/ScreenReaderText/ScreenReaderText.js +9 -4
  14. package/build/system/ScreenReaderText/index.js +8 -1
  15. package/build/system/theme/generated/valet-theme.json +2429 -0
  16. package/build/system/theme/getColor.js +3 -21
  17. package/build/system/theme/index.js +1 -1
  18. package/package.json +8 -5
  19. package/src/system/Button/Button.js +7 -3
  20. package/src/system/NewDialog/DialogClose.js +18 -4
  21. package/src/system/NewDialog/DialogClose.test.js +1 -1
  22. package/src/system/NewDialog/DialogDescription.js +1 -1
  23. package/src/system/NewDialog/DialogTitle.js +1 -1
  24. package/src/system/NewDialog/NewDialog.js +1 -19
  25. package/src/system/NewDialog/NewDialog.stories.jsx +21 -2
  26. package/src/system/NewDialog/index.js +7 -1
  27. package/src/system/Notification/Notification.js +1 -1
  28. package/src/system/ScreenReaderText/ScreenReader.test.js +1 -1
  29. package/src/system/ScreenReaderText/ScreenReaderText.js +24 -22
  30. package/src/system/ScreenReaderText/index.js +2 -0
  31. package/src/system/theme/generated/valet-theme.json +2429 -0
  32. package/src/system/theme/getColor.js +3 -19
  33. package/src/system/theme/index.js +1 -1
  34. package/tokens/valet-color.json +0 -6164
@@ -5,39 +5,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.getColor = void 0;
7
7
 
8
- var _valetColor = _interopRequireDefault(require("../../../tokens/valet-color.json"));
8
+ var _valetTheme = _interopRequireDefault(require("./generated/valet-theme.json"));
9
9
 
10
10
  /**
11
11
  * Internal dependencies
12
12
  */
13
- var ThemeColors = _valetColor["default"]['productive-color-wpvip'];
14
- var CoreColors = _valetColor["default"]['valet-core'];
15
-
16
13
  var getColor = function getColor(color, variant) {
17
14
  if (variant === void 0) {
18
15
  variant = 'default';
19
16
  }
20
17
 
21
- if (!ThemeColors[color]) {
18
+ if (!_valetTheme["default"][color]) {
22
19
  return '#000000';
23
20
  }
24
21
 
25
- var colorValue = ThemeColors[color][variant].value;
26
-
27
- if (colorValue.startsWith('{')) {
28
- var _colorValue$replace$s = colorValue.replace(/[{}]/g, '').split('.'),
29
- name = _colorValue$replace$s[0],
30
- number = _colorValue$replace$s[1]; // Some colors are flat, there is no sub values.
31
-
32
-
33
- if (CoreColors[name][number]) {
34
- return CoreColors[name][number].value;
35
- }
36
-
37
- return CoreColors[name].value;
38
- }
39
-
40
- return colorValue;
22
+ return _valetTheme["default"][color][variant].value;
41
23
  };
42
24
 
43
25
  exports.getColor = getColor;
@@ -65,7 +65,7 @@ var outline = {
65
65
  outlineStyle: 'solid',
66
66
  outlineColor: '#ffffff',
67
67
  outlineWidth: '1px',
68
- boxShadow: "0 0 0 1px #fff, 0 0 0 3px " + (0, _getColor.getColor)('focus')
68
+ boxShadow: "0 0 0 1px " + (0, _getColor.getColor)('focus', 'inset') + ", 0 0 0 3px " + (0, _getColor.getColor)('focus')
69
69
  };
70
70
  var _default = {
71
71
  outline: outline,
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
7
- "build": "cross-env NODE_ENV=production babel src --out-dir build",
7
+ "build": "npm run theme-update && cross-env NODE_ENV=production babel src --out-dir build && npm run theme-builder-copy",
8
8
  "format": "prettier --write \"src/**/*.{js,ts,tsx,md,mdx,json}\"",
9
- "format:check": "prettier --list-different -- \"src/**/*.{js,ts,tsx,md,mdx,json}\"",
9
+ "format:check": "prettier --list-different -- \"src/system/**/*.{js,ts,tsx,md,mdx,json}\"",
10
10
  "jest": "NODE_ENV=test jest --detectOpenHandles --env=jsdom",
11
11
  "jest:coverage": "npm run jest && open-cli ./coverage/index.html",
12
12
  "jest:watch": "npm run jest --watch",
13
+ "theme-builder-copy": "mkdir -p build/system/theme/generated/ && cp src/system/theme/generated/valet-theme.json build/system/theme/generated/valet-theme.json",
14
+ "theme-update": "token-transformer tokens/valet-core.json src/system/theme/generated/valet-theme.json valet-core,productive-color-wpvip",
13
15
  "lint": "eslint . --fix --max-warnings 0",
14
16
  "storybook": "start-storybook -p 6006",
15
17
  "dev": "npm run storybook",
@@ -18,7 +20,7 @@
18
20
  },
19
21
  "dependencies": {
20
22
  "@radix-ui/react-checkbox": "^0.1.5",
21
- "@radix-ui/react-dialog": "^0.1.7",
23
+ "@radix-ui/react-dialog": "^1.0.0",
22
24
  "@radix-ui/react-radio-group": "^0.1.5",
23
25
  "@radix-ui/react-switch": "^0.1.5",
24
26
  "@radix-ui/react-tooltip": "^0.1.7",
@@ -121,6 +123,7 @@
121
123
  "react-dom": "^17.0.2",
122
124
  "react-input-autosize": "^3.0.0",
123
125
  "react-refresh": "^0.9.0",
124
- "theme-ui": "0.10.0"
126
+ "theme-ui": "0.10.0",
127
+ "token-transformer": "^0.0.24"
125
128
  }
126
129
  }
@@ -3,11 +3,12 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
- import { Button as ThemeButton } from 'theme-ui';
6
+ import React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import classNames from 'classnames';
9
+ import { Button as ThemeButton } from 'theme-ui';
9
10
 
10
- const Button = ( { sx, ...props } ) => (
11
+ const Button = React.forwardRef( ( { sx, ...props }, forwardRef ) => (
11
12
  <ThemeButton
12
13
  sx={ {
13
14
  verticalAlign: 'middle',
@@ -27,8 +28,11 @@ const Button = ( { sx, ...props } ) => (
27
28
  } }
28
29
  className={ classNames( 'vip-button-component', props.className ) }
29
30
  { ...props }
31
+ ref={ forwardRef }
30
32
  />
31
- );
33
+ ) );
34
+
35
+ Button.displayName = 'Button';
32
36
 
33
37
  Button.propTypes = {
34
38
  sx: PropTypes.object,
@@ -4,14 +4,28 @@
4
4
  * External dependencies
5
5
  */
6
6
  import React from 'react';
7
+ import PropTypes from 'prop-types';
7
8
  import * as DialogPrimitive from '@radix-ui/react-dialog';
8
9
  import { IoClose } from 'react-icons/io5';
9
10
 
10
11
  /**
11
12
  * Internal dependencies
12
13
  */
13
- export const DialogClose = React.forwardRef( ( props, forwardedRef ) => (
14
- <DialogPrimitive.Close asChild { ...props } ref={ forwardedRef }>
14
+
15
+ export const DialogClose = React.forwardRef( ( { children, ...rest }, forwardedRef ) => (
16
+ <DialogPrimitive.Close asChild { ...rest } ref={ forwardedRef }>
17
+ { children }
18
+ </DialogPrimitive.Close>
19
+ ) );
20
+
21
+ DialogClose.propTypes = {
22
+ children: PropTypes.node,
23
+ };
24
+
25
+ DialogClose.displayName = 'DialogClose';
26
+
27
+ export const DialogCloseDefault = React.forwardRef( ( props, forwardedRef ) => (
28
+ <DialogClose { ...props } ref={ forwardedRef }>
15
29
  <button
16
30
  aria-label="Close"
17
31
  sx={ {
@@ -40,7 +54,7 @@ export const DialogClose = React.forwardRef( ( props, forwardedRef ) => (
40
54
  >
41
55
  <IoClose aria-hidden="true" />
42
56
  </button>
43
- </DialogPrimitive.Close>
57
+ </DialogClose>
44
58
  ) );
45
59
 
46
- DialogClose.displayName = 'DialogClose';
60
+ DialogCloseDefault.displayName = 'DialogCloseDefault';
@@ -8,7 +8,7 @@ import { axe } from 'jest-axe';
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
- import { DialogClose } from './DialogClose';
11
+ import { DialogCloseDefault as DialogClose } from './DialogClose';
12
12
 
13
13
  // If you render any Dialog child without the `<Dialog />` parent, it will throw an error.
14
14
  const Wrapper = props => <Dialog open={ true } { ...props } />;
@@ -6,7 +6,7 @@
6
6
  import React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import * as DialogPrimitive from '@radix-ui/react-dialog';
9
- import ScreenReaderText from '../ScreenReaderText/ScreenReaderText';
9
+ import ScreenReaderText from '../ScreenReaderText';
10
10
 
11
11
  /**
12
12
  * Internal dependencies
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import PropTypes from 'prop-types';
7
7
  import * as DialogPrimitive from '@radix-ui/react-dialog';
8
- import ScreenReaderText from '../ScreenReaderText/ScreenReaderText';
8
+ import ScreenReaderText from '../ScreenReaderText';
9
9
 
10
10
  /**
11
11
  * Internal dependencies
@@ -9,7 +9,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
9
9
  * Internal dependencies
10
10
  */
11
11
  import { DialogOverlay } from './DialogOverlay';
12
- import { DialogClose } from './DialogClose';
12
+ import { DialogCloseDefault as DialogClose } from './DialogClose';
13
13
  import { DialogTitle } from './DialogTitle';
14
14
  import { DialogDescription } from './DialogDescription';
15
15
  import { contentStyles } from './DialogContent';
@@ -26,11 +26,6 @@ export const NewDialog = ( {
26
26
  // Radix Specific Properties
27
27
  defaultOpen = false,
28
28
  allowPinchZoom = false,
29
- onOpenAutoFocus = null,
30
- onCloseAutoFocus = null,
31
- onEscapeKeyDown = null,
32
- onPointerDownOutside = null,
33
- onInteractOutside = null,
34
29
  } ) => {
35
30
  if ( disabled ) {
36
31
  return;
@@ -46,11 +41,6 @@ export const NewDialog = ( {
46
41
  <DialogPrimitive.Content
47
42
  className="vip-dialog-component"
48
43
  sx={ { ...contentStyles, ...extraStyles } }
49
- onOpenAutoFocus={ onOpenAutoFocus }
50
- onCloseAutoFocus={ onCloseAutoFocus }
51
- onEscapeKeyDown={ onEscapeKeyDown }
52
- onPointerDownOutside={ onPointerDownOutside }
53
- onInteractOutside={ onInteractOutside }
54
44
  >
55
45
  <DialogClose />
56
46
  <DialogTitle title={ title } hidden={ ! showHeading } />
@@ -76,12 +66,4 @@ NewDialog.propTypes = {
76
66
  // https://www.radix-ui.com/docs/primitives/components/dialog#root
77
67
  defaultOpen: PropTypes.bool,
78
68
  allowPinchZoom: PropTypes.bool,
79
-
80
- // Radix DialogPrimitive.Content properties
81
- // https://www.radix-ui.com/docs/primitives/components/dialog#content
82
- onOpenAutoFocus: PropTypes.func,
83
- onCloseAutoFocus: PropTypes.func,
84
- onEscapeKeyDown: PropTypes.func,
85
- onPointerDownOutside: PropTypes.func,
86
- onInteractOutside: PropTypes.func,
87
69
  };
@@ -5,8 +5,8 @@
5
5
  * Internal dependencies
6
6
  */
7
7
  import { Button, Text, Input, Label } from '../../system';
8
- import ScreenReaderText from '../ScreenReaderText/ScreenReaderText';
9
- import { NewDialog } from './NewDialog';
8
+ import ScreenReaderText from '../ScreenReaderText';
9
+ import { NewDialog, Close } from '.';
10
10
 
11
11
  export default {
12
12
  title: 'NewDialog',
@@ -112,3 +112,22 @@ export const CustomStyling = () => (
112
112
  />
113
113
  </>
114
114
  );
115
+
116
+ export const CustomClose = () => (
117
+ <>
118
+ <Text sx={ { fontSize: 3, mb: 3 } }>
119
+ This example shows how you can create a custom Close trigger to your dialog
120
+ </Text>
121
+ <NewDialog
122
+ { ...defaultProps }
123
+ trigger={ <Button>Trigger Dialog</Button> }
124
+ content={
125
+ <div>
126
+ <Close>
127
+ <Button>Close here instead</Button>
128
+ </Close>
129
+ </div>
130
+ }
131
+ />
132
+ </>
133
+ );
@@ -2,6 +2,12 @@
2
2
  * Internal dependencies
3
3
  */
4
4
 
5
+ import { DialogClose } from './DialogClose';
5
6
  import { NewDialog } from './NewDialog';
6
7
 
7
- export { NewDialog };
8
+ const Root = NewDialog;
9
+ const Close = DialogClose;
10
+
11
+ export { NewDialog, Root, Close };
12
+
13
+ export default NewDialog;
@@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
10
10
  * Internal dependencies
11
11
  */
12
12
  import { Box, Card, Flex, Text, Button } from '../';
13
- import ScreenReaderText from '../ScreenReaderText/ScreenReaderText';
13
+ import ScreenReaderText from '../ScreenReaderText';
14
14
 
15
15
  const Notification = ( { title, body, status = 'success', onClose } ) => (
16
16
  <Card
@@ -6,7 +6,7 @@ import '@testing-library/jest-dom';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import ScreenReaderText from './ScreenReaderText';
9
+ import ScreenReaderText from '.';
10
10
 
11
11
  describe( '<ScreenReaderText />', () => {
12
12
  it( 'should render correctly', () => {
@@ -3,34 +3,36 @@
3
3
  * External dependencies
4
4
  */
5
5
 
6
+ import React from 'react';
6
7
  import PropTypes from 'prop-types';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
10
11
  */
11
12
 
12
- export default function ScreenReaderText( props ) {
13
- return (
14
- <span
15
- className="screen-reader-text"
16
- sx={ {
17
- border: 'none',
18
- clip: 'rect(1px, 1px, 1px, 1px)',
19
- clipPath: 'inset(50%)',
20
- height: '1px',
21
- margin: '-1px',
22
- overflow: 'hidden',
23
- padding: '0',
24
- position: 'absolute',
25
- width: '1px',
26
- wordWrap: 'normal !important',
27
- } }
28
- { ...props }
29
- >
30
- { props.children }
31
- </span>
32
- );
33
- }
13
+ export const ScreenReaderText = React.forwardRef( ( props, forwardRef ) => (
14
+ <span
15
+ className="screen-reader-text"
16
+ sx={ {
17
+ border: 'none',
18
+ clip: 'rect(1px, 1px, 1px, 1px)',
19
+ clipPath: 'inset(50%)',
20
+ height: '1px',
21
+ margin: '-1px',
22
+ overflow: 'hidden',
23
+ padding: '0',
24
+ position: 'absolute',
25
+ width: '1px',
26
+ wordWrap: 'normal !important',
27
+ } }
28
+ { ...props }
29
+ ref={ forwardRef }
30
+ >
31
+ { props.children }
32
+ </span>
33
+ ) );
34
+
35
+ ScreenReaderText.displayName = 'ScreenReaderText';
34
36
 
35
37
  /**
36
38
  * propTypes
@@ -5,3 +5,5 @@
5
5
  import { ScreenReaderText } from './ScreenReaderText';
6
6
 
7
7
  export { ScreenReaderText };
8
+
9
+ export default ScreenReaderText;