@automattic/vip-design-system 0.12.0 → 0.13.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 (35) hide show
  1. package/.storybook/decorators/withBoundingBox.jsx +11 -4
  2. package/.storybook/decorators/withThemeProvider.jsx +4 -6
  3. package/build/system/Form/Toggle.js +19 -11
  4. package/build/system/Form/Toggle.stories.js +46 -6
  5. package/build/system/NewDialog/DialogClose.js +75 -0
  6. package/build/system/NewDialog/DialogClose.test.js +67 -0
  7. package/build/system/NewDialog/DialogContent.js +26 -0
  8. package/build/system/NewDialog/DialogDescription.js +54 -0
  9. package/build/system/NewDialog/DialogDescription.test.js +95 -0
  10. package/build/system/NewDialog/DialogOverlay.js +48 -0
  11. package/build/system/NewDialog/DialogOverlay.test.js +63 -0
  12. package/build/system/NewDialog/DialogTitle.js +50 -0
  13. package/build/system/NewDialog/DialogTitle.test.js +95 -0
  14. package/build/system/NewDialog/NewDialog.js +117 -0
  15. package/build/system/NewDialog/NewDialog.stories.js +159 -0
  16. package/build/system/NewDialog/index.js +7 -0
  17. package/build/system/Notice/Notice.js +4 -4
  18. package/build/system/index.js +4 -0
  19. package/package.json +6 -4
  20. package/src/system/Form/Toggle.js +28 -10
  21. package/src/system/Form/Toggle.stories.jsx +43 -1
  22. package/src/system/NewDialog/DialogClose.js +45 -0
  23. package/src/system/NewDialog/DialogClose.test.js +32 -0
  24. package/src/system/NewDialog/DialogContent.js +17 -0
  25. package/src/system/NewDialog/DialogDescription.js +36 -0
  26. package/src/system/NewDialog/DialogDescription.test.js +47 -0
  27. package/src/system/NewDialog/DialogOverlay.js +31 -0
  28. package/src/system/NewDialog/DialogOverlay.test.js +27 -0
  29. package/src/system/NewDialog/DialogTitle.js +27 -0
  30. package/src/system/NewDialog/DialogTitle.test.js +47 -0
  31. package/src/system/NewDialog/NewDialog.js +87 -0
  32. package/src/system/NewDialog/NewDialog.stories.jsx +96 -0
  33. package/src/system/NewDialog/index.js +7 -0
  34. package/src/system/Notice/Notice.js +3 -3
  35. package/src/system/index.js +3 -0
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.DialogTitle = void 0;
7
+
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
10
+ var DialogPrimitive = _interopRequireWildcard(require("@radix-ui/react-dialog"));
11
+
12
+ var _ScreenReaderText = _interopRequireDefault(require("../ScreenReaderText/ScreenReaderText"));
13
+
14
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ /** @jsxImportSource theme-ui */
21
+
22
+ /**
23
+ * External dependencies
24
+ */
25
+
26
+ /**
27
+ * Internal dependencies
28
+ */
29
+ var DialogTitle = function DialogTitle(_ref) {
30
+ var title = _ref.title,
31
+ _ref$hidden = _ref.hidden,
32
+ hidden = _ref$hidden === void 0 ? false : _ref$hidden;
33
+ var titleNode = title;
34
+
35
+ if (hidden) {
36
+ titleNode = (0, _jsxRuntime.jsx)(_ScreenReaderText["default"], {
37
+ children: titleNode
38
+ });
39
+ }
40
+
41
+ return (0, _jsxRuntime.jsx)(DialogPrimitive.Title, {
42
+ children: titleNode
43
+ });
44
+ };
45
+
46
+ exports.DialogTitle = DialogTitle;
47
+ DialogTitle.propTypes = {
48
+ title: _propTypes["default"].string,
49
+ hidden: _propTypes["default"].bool
50
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
6
+
7
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
+
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+
11
+ var _reactDialog = require("@radix-ui/react-dialog");
12
+
13
+ var _react = require("@testing-library/react");
14
+
15
+ var _jestAxe = require("jest-axe");
16
+
17
+ var _DialogTitle = require("./DialogTitle");
18
+
19
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
20
+
21
+ /**
22
+ * External dependencies
23
+ */
24
+
25
+ /**
26
+ * Internal dependencies
27
+ */
28
+ // If you render any Dialog child without the `<Dialog />` parent, it will throw an error.
29
+ var Wrapper = function Wrapper(props) {
30
+ return (0, _jsxRuntime.jsx)(_reactDialog.Dialog, (0, _extends2["default"])({
31
+ open: true
32
+ }, props));
33
+ };
34
+
35
+ var defaultProps = {
36
+ title: 'This is a DialogTitle'
37
+ };
38
+
39
+ var getTitle = function getTitle() {
40
+ return _react.screen.getByRole('heading');
41
+ };
42
+
43
+ describe('<DialogTitle />', function () {
44
+ it('renders the DialogTitle component', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
45
+ var _render, container;
46
+
47
+ return _regenerator["default"].wrap(function _callee$(_context) {
48
+ while (1) {
49
+ switch (_context.prev = _context.next) {
50
+ case 0:
51
+ _render = (0, _react.render)((0, _jsxRuntime.jsx)(Wrapper, {
52
+ children: (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, (0, _extends2["default"])({}, defaultProps))
53
+ })), container = _render.container;
54
+ expect(getTitle()).toHaveTextContent(defaultProps.title); // Check for accessibility issues
55
+
56
+ _context.t0 = expect;
57
+ _context.next = 5;
58
+ return (0, _jestAxe.axe)(container);
59
+
60
+ case 5:
61
+ _context.t1 = _context.sent;
62
+ _context.next = 8;
63
+ return (0, _context.t0)(_context.t1).toHaveNoViolations();
64
+
65
+ case 8:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }
70
+ }, _callee);
71
+ })));
72
+ it('renders text visually hidden for a11y purposes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
73
+ var _render2, container;
74
+
75
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
76
+ while (1) {
77
+ switch (_context2.prev = _context2.next) {
78
+ case 0:
79
+ _render2 = (0, _react.render)((0, _jsxRuntime.jsx)(Wrapper, {
80
+ children: (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, (0, _extends2["default"])({}, defaultProps, {
81
+ hidden: true
82
+ }))
83
+ })), container = _render2.container; // Small check to make sure we are hiding with the css class
84
+
85
+ expect(container.innerHTML).toContain('screen-reader-text');
86
+ expect(getTitle()).toHaveTextContent(defaultProps.title);
87
+
88
+ case 3:
89
+ case "end":
90
+ return _context2.stop();
91
+ }
92
+ }
93
+ }, _callee2);
94
+ })));
95
+ });
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.NewDialog = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var DialogPrimitive = _interopRequireWildcard(require("@radix-ui/react-dialog"));
13
+
14
+ var _DialogOverlay = require("./DialogOverlay");
15
+
16
+ var _DialogClose = require("./DialogClose");
17
+
18
+ var _DialogTitle = require("./DialogTitle");
19
+
20
+ var _DialogDescription = require("./DialogDescription");
21
+
22
+ var _DialogContent = require("./DialogContent");
23
+
24
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
25
+
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
30
+ /** @jsxImportSource theme-ui */
31
+
32
+ /**
33
+ * External dependencies
34
+ */
35
+
36
+ /**
37
+ * Internal dependencies
38
+ */
39
+ var NewDialog = function NewDialog(_ref) {
40
+ var _ref$trigger = _ref.trigger,
41
+ trigger = _ref$trigger === void 0 ? null : _ref$trigger,
42
+ description = _ref.description,
43
+ title = _ref.title,
44
+ _ref$content = _ref.content,
45
+ content = _ref$content === void 0 ? null : _ref$content,
46
+ _ref$showHeading = _ref.showHeading,
47
+ showHeading = _ref$showHeading === void 0 ? true : _ref$showHeading,
48
+ _ref$disabled = _ref.disabled,
49
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
50
+ extraStyles = _ref.style,
51
+ _ref$defaultOpen = _ref.defaultOpen,
52
+ defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
53
+ _ref$allowPinchZoom = _ref.allowPinchZoom,
54
+ allowPinchZoom = _ref$allowPinchZoom === void 0 ? false : _ref$allowPinchZoom,
55
+ _ref$onOpenAutoFocus = _ref.onOpenAutoFocus,
56
+ onOpenAutoFocus = _ref$onOpenAutoFocus === void 0 ? null : _ref$onOpenAutoFocus,
57
+ _ref$onCloseAutoFocus = _ref.onCloseAutoFocus,
58
+ onCloseAutoFocus = _ref$onCloseAutoFocus === void 0 ? null : _ref$onCloseAutoFocus,
59
+ _ref$onEscapeKeyDown = _ref.onEscapeKeyDown,
60
+ onEscapeKeyDown = _ref$onEscapeKeyDown === void 0 ? null : _ref$onEscapeKeyDown,
61
+ _ref$onPointerDownOut = _ref.onPointerDownOutside,
62
+ onPointerDownOutside = _ref$onPointerDownOut === void 0 ? null : _ref$onPointerDownOut,
63
+ _ref$onInteractOutsid = _ref.onInteractOutside,
64
+ onInteractOutside = _ref$onInteractOutsid === void 0 ? null : _ref$onInteractOutsid;
65
+
66
+ if (disabled) {
67
+ return;
68
+ }
69
+
70
+ return (0, _jsxRuntime.jsxs)(DialogPrimitive.Root, {
71
+ defaultOpen: defaultOpen,
72
+ allowPinchZoom: allowPinchZoom,
73
+ children: [trigger && (0, _jsxRuntime.jsx)(DialogPrimitive.Trigger, {
74
+ asChild: true,
75
+ children: trigger
76
+ }), (0, _jsxRuntime.jsxs)(DialogPrimitive.Portal, {
77
+ children: [(0, _jsxRuntime.jsx)(_DialogOverlay.DialogOverlay, {}), (0, _jsxRuntime.jsxs)(DialogPrimitive.Content, {
78
+ className: "vip-dialog-component",
79
+ sx: (0, _extends2["default"])({}, _DialogContent.contentStyles, extraStyles),
80
+ onOpenAutoFocus: onOpenAutoFocus,
81
+ onCloseAutoFocus: onCloseAutoFocus,
82
+ onEscapeKeyDown: onEscapeKeyDown,
83
+ onPointerDownOutside: onPointerDownOutside,
84
+ onInteractOutside: onInteractOutside,
85
+ children: [(0, _jsxRuntime.jsx)(_DialogClose.DialogClose, {}), (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, {
86
+ title: title,
87
+ hidden: !showHeading
88
+ }), (0, _jsxRuntime.jsx)(_DialogDescription.DialogDescription, {
89
+ description: description,
90
+ hidden: !showHeading
91
+ }), content]
92
+ })]
93
+ })]
94
+ });
95
+ };
96
+
97
+ exports.NewDialog = NewDialog;
98
+ NewDialog.propTypes = {
99
+ trigger: _propTypes["default"].node.isRequired,
100
+ title: _propTypes["default"].string.isRequired,
101
+ description: _propTypes["default"].string.isRequired,
102
+ content: _propTypes["default"].node,
103
+ showHeading: _propTypes["default"].bool,
104
+ disabled: _propTypes["default"].bool,
105
+ style: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].func]),
106
+ // Radix DialogPrimitive.Root properties
107
+ // https://www.radix-ui.com/docs/primitives/components/dialog#root
108
+ defaultOpen: _propTypes["default"].bool,
109
+ allowPinchZoom: _propTypes["default"].bool,
110
+ // Radix DialogPrimitive.Content properties
111
+ // https://www.radix-ui.com/docs/primitives/components/dialog#content
112
+ onOpenAutoFocus: _propTypes["default"].func,
113
+ onCloseAutoFocus: _propTypes["default"].func,
114
+ onEscapeKeyDown: _propTypes["default"].func,
115
+ onPointerDownOutside: _propTypes["default"].func,
116
+ onInteractOutside: _propTypes["default"].func
117
+ };
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports["default"] = exports.HiddenHeadings = exports.Default = exports.CustomStyling = exports.AutoOpen = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _system = require("../../system");
11
+
12
+ var _ScreenReaderText = _interopRequireDefault(require("../ScreenReaderText/ScreenReaderText"));
13
+
14
+ var _NewDialog = require("./NewDialog");
15
+
16
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
17
+
18
+ /** @jsxImportSource theme-ui */
19
+
20
+ /**
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+ var _default = {
25
+ title: 'NewDialog',
26
+ component: _NewDialog.NewDialog
27
+ };
28
+ exports["default"] = _default;
29
+ var defaultProps = {
30
+ title: 'User settings',
31
+ description: 'Use this form to manage your settings'
32
+ };
33
+
34
+ var Default = function Default() {
35
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
36
+ children: [(0, _jsxRuntime.jsx)(_system.Text, {
37
+ sx: {
38
+ fontSize: 3,
39
+ mb: 3
40
+ },
41
+ children: "Regular Dialog where the title and description are built-in and the content is provided by the user."
42
+ }), (0, _jsxRuntime.jsx)(_NewDialog.NewDialog, (0, _extends2["default"])({}, defaultProps, {
43
+ trigger: (0, _jsxRuntime.jsx)(_system.Button, {
44
+ children: "Trigger Dialog"
45
+ })
46
+ }))]
47
+ });
48
+ };
49
+
50
+ exports.Default = Default;
51
+
52
+ var AutoOpen = function AutoOpen() {
53
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
54
+ children: [(0, _jsxRuntime.jsx)(_system.Text, {
55
+ sx: {
56
+ fontSize: 3,
57
+ mb: 3
58
+ },
59
+ children: "Auto Opens when rendered. Press escape to close it."
60
+ }), (0, _jsxRuntime.jsx)(_NewDialog.NewDialog, (0, _extends2["default"])({}, defaultProps, {
61
+ defaultOpen: true,
62
+ trigger: (0, _jsxRuntime.jsx)(_ScreenReaderText["default"], {
63
+ children: "hey"
64
+ })
65
+ }))]
66
+ });
67
+ };
68
+
69
+ exports.AutoOpen = AutoOpen;
70
+
71
+ var HiddenHeadings = function HiddenHeadings() {
72
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
73
+ children: [(0, _jsxRuntime.jsx)(_system.Text, {
74
+ sx: {
75
+ fontSize: 3,
76
+ mb: 3
77
+ },
78
+ children: "Title and description are hidden, but still announced using a screen reader. Activate VoiceOver or any similar screen reader to listen to: Custom dialog title, Description of the dialog content."
79
+ }), (0, _jsxRuntime.jsx)(_NewDialog.NewDialog, (0, _extends2["default"])({}, defaultProps, {
80
+ trigger: (0, _jsxRuntime.jsx)(_system.Button, {
81
+ children: "Trigger Dialog"
82
+ }),
83
+ title: "Custom dialog title",
84
+ showHeading: false,
85
+ content: (0, _jsxRuntime.jsxs)("div", {
86
+ children: [(0, _jsxRuntime.jsx)("h3", {
87
+ children: "My Custom Content"
88
+ }), (0, _jsxRuntime.jsxs)("form", {
89
+ children: [(0, _jsxRuntime.jsx)(_system.Label, {
90
+ htmlFor: "username",
91
+ children: "User name"
92
+ }), (0, _jsxRuntime.jsx)(_system.Input, {
93
+ type: "text",
94
+ name: "username",
95
+ id: "username"
96
+ }), (0, _jsxRuntime.jsx)(_system.Button, {
97
+ type: "submit",
98
+ children: "Submit"
99
+ })]
100
+ })]
101
+ })
102
+ }))]
103
+ });
104
+ };
105
+
106
+ exports.HiddenHeadings = HiddenHeadings;
107
+
108
+ var CustomStyling = function CustomStyling() {
109
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
110
+ children: [(0, _jsxRuntime.jsx)(_system.Text, {
111
+ sx: {
112
+ fontSize: 3,
113
+ mb: 3
114
+ },
115
+ children: "Custom Styling on Dialog Content"
116
+ }), (0, _jsxRuntime.jsx)(_NewDialog.NewDialog, (0, _extends2["default"])({}, defaultProps, {
117
+ defaultOpen: true,
118
+ trigger: (0, _jsxRuntime.jsx)(_system.Button, {
119
+ children: "Trigger Dialog"
120
+ }),
121
+ title: "Custom dialog title",
122
+ style: {
123
+ background: function background(theme) {
124
+ return "" + theme.colors.primary;
125
+ },
126
+ padding: 5,
127
+ borderRadius: 20,
128
+ h2: {
129
+ fontSize: 4,
130
+ color: function color(theme) {
131
+ return "" + theme.colors.text;
132
+ }
133
+ },
134
+ h3: {
135
+ fontSize: 3,
136
+ color: function color(theme) {
137
+ return "" + theme.colors.heading;
138
+ }
139
+ },
140
+ p: {
141
+ color: 'white'
142
+ },
143
+ 'button[type="button"]:focus': {
144
+ outlineColor: 'white',
145
+ color: 'white'
146
+ }
147
+ },
148
+ content: (0, _jsxRuntime.jsxs)("div", {
149
+ children: [(0, _jsxRuntime.jsx)("h3", {
150
+ children: "This is Read because it is Custom"
151
+ }), (0, _jsxRuntime.jsx)("p", {
152
+ children: "This Dialog is styled using the `sx` property."
153
+ })]
154
+ })
155
+ }))]
156
+ });
157
+ };
158
+
159
+ exports.CustomStyling = CustomStyling;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _NewDialog = require("./NewDialog");
6
+
7
+ exports.NewDialog = _NewDialog.NewDialog;
@@ -42,10 +42,10 @@ var NoticeIcon = function NoticeIcon(_ref) {
42
42
 
43
43
  return (0, _jsxRuntime.jsx)(Icon, {
44
44
  sx: {
45
- marginRight: 2,
46
45
  color: color,
47
46
  flex: '0 0 auto'
48
- }
47
+ },
48
+ size: 21
49
49
  });
50
50
  };
51
51
 
@@ -106,12 +106,12 @@ var Notice = function Notice(_ref2) {
106
106
  alignItems: 'center'
107
107
  },
108
108
  children: (0, _jsxRuntime.jsx)(NoticeIcon, {
109
- color: color + ".100",
109
+ color: color + ".200",
110
110
  variant: variant
111
111
  })
112
112
  }), (0, _jsxRuntime.jsxs)(_.Box, {
113
113
  sx: {
114
- ml: 23
114
+ ml: 3
115
115
  },
116
116
  children: [title && (0, _jsxRuntime.jsx)(_.Heading, {
117
117
  variant: "h4",
@@ -42,6 +42,10 @@ exports.DialogMenuItem = _Dialog.DialogMenuItem;
42
42
  exports.DialogTrigger = _Dialog.DialogTrigger;
43
43
  exports.DialogContent = _Dialog.DialogContent;
44
44
 
45
+ var _NewDialog = require("./NewDialog");
46
+
47
+ exports.NewDialog = _NewDialog.NewDialog;
48
+
45
49
  var _ConfirmationDialog = require("./ConfirmationDialog");
46
50
 
47
51
  exports.ConfirmationDialog = _ConfirmationDialog.ConfirmationDialog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
@@ -17,10 +17,12 @@
17
17
  "watch": "npm run build -- --watch"
18
18
  },
19
19
  "dependencies": {
20
- "@radix-ui/react-checkbox": "^0.1.0",
21
- "@radix-ui/react-radio-group": "^0.1.0",
20
+ "@radix-ui/react-checkbox": "^0.1.5",
21
+ "@radix-ui/react-dialog": "^0.1.7",
22
+ "@radix-ui/react-radio-group": "^0.1.5",
22
23
  "@radix-ui/react-switch": "^0.1.5",
23
- "@radix-ui/react-tooltip": "^0.1.0",
24
+ "@radix-ui/react-tooltip": "^0.1.7",
25
+ "@radix-ui/react-visually-hidden": "^0.1.4",
24
26
  "babel-loader": "^8.2.2",
25
27
  "classnames": "^2.3.1",
26
28
  "framer-motion": "^3.9.1",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable max-len */
1
2
  /** @jsxImportSource theme-ui */
2
3
 
3
4
  /**
@@ -11,18 +12,34 @@ import * as Switch from '@radix-ui/react-switch';
11
12
  // Documentation for Radix Switch component
12
13
  // https://www.radix-ui.com/docs/primitives/components/switch
13
14
 
14
- export const Toggle = ( { name = 'toggle', onChange, className = null, ...rest } ) => (
15
+ export const Toggle = ( {
16
+ name = 'toggle',
17
+ onChange,
18
+ className = null,
19
+ variant = 'primary',
20
+ ...rest
21
+ } ) => (
15
22
  <Switch.Root
16
23
  className={ classNames( 'vip-toggle-component', className ) }
17
24
  sx={ {
18
25
  all: 'unset',
19
- width: 42,
20
- height: 24,
21
- backgroundColor: 'muted',
22
- borderRadius: '15px',
23
26
  position: 'relative',
27
+ width: 40,
28
+ height: 20,
29
+ borderRadius: '32px',
30
+ backgroundColor: 'muted',
31
+ backgroundRepeat: 'no-repeat',
32
+ backgroundPosition: 'right 2px top 2px',
33
+ backgroundImage: `url(
34
+ 'data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.53846 3L3 4.53846L6.46156 8.00001L3.00003 11.4615L4.53848 13L8.00001 9.53847L11.4615 13L13 11.4615L9.53847 8.00001L13 4.53849L11.4615 3.00003L8.00001 6.46156L4.53846 3Z" fill="white"/></svg>')`,
24
35
  WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
25
- '&[data-state="checked"]': { backgroundColor: 'success' },
36
+
37
+ '&[data-state="checked"]': {
38
+ backgroundColor: variant,
39
+ backgroundPosition: 'left 2px top 2px',
40
+ backgroundImage: `url(
41
+ 'data:image/svg+xml;utf8,<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M13.4999 4.9995L5.7254 12.4008L2.5 9.33023L3.83307 7.92994L5.7254 9.73144L12.1668 3.59921L13.4999 4.9995Z" fill="white"/></svg>')`,
42
+ },
26
43
  } }
27
44
  name={ name }
28
45
  onCheckedChange={ onChange || undefined }
@@ -31,15 +48,15 @@ export const Toggle = ( { name = 'toggle', onChange, className = null, ...rest }
31
48
  <Switch.Thumb
32
49
  sx={ {
33
50
  display: 'block',
34
- width: 18,
35
- height: 18,
51
+ width: 16,
52
+ height: 16,
36
53
  backgroundColor: 'white',
37
54
  borderRadius: '50%',
38
55
  boxShadow: 'rgb(0 0 0 / 5%) 0px 1px 5px, rgb(0 0 0 / 15%) 0px 1px 1px',
39
56
  transition: 'transform 100ms',
40
- transform: 'translateX(3px)',
57
+ transform: 'translateX(2px)',
41
58
  willChange: 'transform',
42
- '&[data-state="checked"]': { transform: 'translateX(21px)' },
59
+ '&[data-state="checked"]': { transform: 'translateX(22px)' },
43
60
  } }
44
61
  />
45
62
  </Switch.Root>
@@ -49,4 +66,5 @@ Toggle.propTypes = {
49
66
  name: PropTypes.string,
50
67
  className: PropTypes.any,
51
68
  onChange: PropTypes.func,
69
+ variant: PropTypes.string,
52
70
  };
@@ -1,3 +1,4 @@
1
+ /** @jsxImportSource theme-ui */
1
2
  /**
2
3
  * External dependencies
3
4
  */
@@ -21,7 +22,17 @@ export default {
21
22
 
22
23
  const Default = args => (
23
24
  <form>
24
- <Toggle defaultChecked checked={ args.checked } aria-label="Feature flag" />
25
+ <Toggle
26
+ checked={ args.checked }
27
+ defaultChecked
28
+ color={ args.color }
29
+ aria-label="Feature flag"
30
+ />
31
+
32
+ <br />
33
+ <br />
34
+
35
+ <Toggle checked={ args.checked } defaultChecked={ false } aria-label="Feature flag 2" />
25
36
  </form>
26
37
  );
27
38
 
@@ -38,5 +49,36 @@ const WithLabel = args => (
38
49
  </form>
39
50
  );
40
51
 
52
+ const CustomStyling = args => (
53
+ <form>
54
+ <Label htmlFor="custom-label-input">Custom Styling</Label>
55
+
56
+ <div>
57
+ <Toggle
58
+ id="custom-label-input"
59
+ defaultChecked
60
+ checked={ args.checked }
61
+ aria-label="Feature flag"
62
+ variant="success"
63
+ />{ ' ' }
64
+ <Toggle
65
+ id="custom-label-input-error"
66
+ defaultChecked
67
+ checked={ args.checked }
68
+ aria-label="Error flag"
69
+ variant="error"
70
+ />{ ' ' }
71
+ <Toggle
72
+ id="custom-label-input-warning"
73
+ defaultChecked
74
+ checked={ args.checked }
75
+ aria-label="Warning flag"
76
+ variant="warning"
77
+ />
78
+ </div>
79
+ </form>
80
+ );
81
+
41
82
  export const Primary = Default.bind( { checked: true } );
42
83
  export const ExternalLabel = WithLabel.bind( { checked: true } );
84
+ export const CustomStyle = CustomStyling.bind( { checked: true } );
@@ -0,0 +1,45 @@
1
+ /** @jsxImportSource theme-ui */
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import React from 'react';
7
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
8
+ import { IoClose } from 'react-icons/io5';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ export const DialogClose = React.forwardRef( ( props, forwardedRef ) => (
14
+ <DialogPrimitive.Close asChild { ...props } ref={ forwardedRef }>
15
+ <button
16
+ aria-label="Close"
17
+ sx={ {
18
+ all: 'unset',
19
+ fontFamily: 'inherit',
20
+ borderRadius: '100%',
21
+ height: 25,
22
+ width: 25,
23
+ display: 'inline-flex',
24
+ alignItems: 'center',
25
+ justifyContent: 'center',
26
+ color: theme => `${ theme?.colors?.text }`,
27
+ position: 'absolute',
28
+ top: 10,
29
+ right: 10,
30
+
31
+ '&:hover': {
32
+ backgroundColor: 'border',
33
+ outlineStyle: 'solid',
34
+ outlineColor: 'primary',
35
+ outlineWidth: '2px',
36
+ },
37
+ '&:focus': { outlineStyle: 'solid', outlineColor: 'primary', outlineWidth: '2px' },
38
+ } }
39
+ >
40
+ <IoClose aria-hidden="true" />
41
+ </button>
42
+ </DialogPrimitive.Close>
43
+ ) );
44
+
45
+ DialogClose.displayName = 'DialogClose';