@automattic/vip-design-system 0.18.2-0 → 0.18.5-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,6 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.DropdownTrigger = exports.DropdownSubTrigger = exports.DropdownSubContent = exports.DropdownSub = exports.DropdownSeparator = exports.DropdownRadioGroup = exports.DropdownLabel = exports.DropdownItemIndicator = exports.Dropdown = void 0;
7
7
 
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
8
10
  var _react = _interopRequireDefault(require("react"));
9
11
 
10
12
  var DropdownMenuPrimitive = _interopRequireWildcard(require("@radix-ui/react-dropdown-menu"));
@@ -48,7 +50,21 @@ exports.DropdownSubContent = DropdownSubContent;
48
50
 
49
51
  var Dropdown = function Dropdown(_ref) {
50
52
  var trigger = _ref.trigger,
51
- children = _ref.children;
53
+ children = _ref.children,
54
+ _ref$open = _ref.open,
55
+ open = _ref$open === void 0 ? undefined : _ref$open,
56
+ _ref$defaultOpen = _ref.defaultOpen,
57
+ defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
58
+ _ref$onOpenChange = _ref.onOpenChange,
59
+ onOpenChange = _ref$onOpenChange === void 0 ? undefined : _ref$onOpenChange,
60
+ _ref$modal = _ref.modal,
61
+ modal = _ref$modal === void 0 ? true : _ref$modal,
62
+ _ref$dir = _ref.dir,
63
+ dir = _ref$dir === void 0 ? 'ltr' : _ref$dir,
64
+ _ref$contentProps = _ref.contentProps,
65
+ contentProps = _ref$contentProps === void 0 ? {} : _ref$contentProps,
66
+ _ref$portalProps = _ref.portalProps,
67
+ portalProps = _ref$portalProps === void 0 ? {} : _ref$portalProps;
52
68
 
53
69
  var firstChild = _react["default"].useMemo(function () {
54
70
  var _React$Children$only, _React$Children$only$;
@@ -57,23 +73,39 @@ var Dropdown = function Dropdown(_ref) {
57
73
  }, [children]);
58
74
 
59
75
  return (0, _jsxRuntime.jsxs)(DropdownMenu, {
76
+ open: open,
77
+ defaultOpen: defaultOpen,
78
+ onOpenChange: onOpenChange,
79
+ modal: modal,
80
+ dir: dir,
60
81
  children: [(0, _jsxRuntime.jsx)(DropdownTrigger, {
61
82
  asChild: true,
62
83
  children: trigger
63
- }), (0, _jsxRuntime.jsx)(DropdownMenuPrimitive.Portal, {
64
- children: firstChild === 'DropdownContent' ? children : (0, _jsxRuntime.jsxs)(_DropdownContent.DropdownContent, {
84
+ }), (0, _jsxRuntime.jsx)(DropdownMenuPrimitive.Portal, (0, _extends2["default"])({}, portalProps, {
85
+ children: firstChild === 'DropdownContent' ? children : (0, _jsxRuntime.jsxs)(_DropdownContent.DropdownContent, (0, _extends2["default"])({}, contentProps, {
65
86
  children: [children, (0, _jsxRuntime.jsx)(DropdownMenuPrimitive.Arrow, {
66
87
  sx: {
67
- fill: 'white'
88
+ fill: 'background',
89
+ boxShadow: 'high'
68
90
  }
69
91
  })]
70
- })
71
- })]
92
+ }))
93
+ }))]
72
94
  });
73
95
  };
74
96
 
75
97
  exports.Dropdown = Dropdown;
76
98
  Dropdown.propTypes = {
77
99
  trigger: _propTypes["default"].node.isRequired,
78
- children: _propTypes["default"].node.isRequired
100
+ children: _propTypes["default"].node.isRequired,
101
+ // Props in root: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#root
102
+ open: _propTypes["default"].bool,
103
+ defaultOpen: _propTypes["default"].bool,
104
+ onOpenChange: _propTypes["default"].func,
105
+ modal: _propTypes["default"].bool,
106
+ dir: _propTypes["default"].string,
107
+ // Content props in: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#content
108
+ contentProps: _propTypes["default"].any,
109
+ // Portal props in: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#portal
110
+ portalProps: _propTypes["default"].any
79
111
  }; // Exports
@@ -3,7 +3,11 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports["default"] = exports.WithDialogState = exports.Default = exports.ComplexOptions = void 0;
6
+ exports["default"] = exports.WithDialog = exports.Default = exports.ComplexOptions = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
7
11
 
8
12
  var _react = _interopRequireDefault(require("react"));
9
13
 
@@ -13,24 +17,16 @@ var Dropdown = _interopRequireWildcard(require("."));
13
17
 
14
18
  var _Button = require("../Button");
15
19
 
16
- var _NewConfirmationDialog = require("../NewConfirmationDialog");
20
+ var NewDialog = _interopRequireWildcard(require("../NewDialog"));
17
21
 
18
22
  var _jsxRuntime = require("theme-ui/jsx-runtime");
19
23
 
24
+ var _excluded = ["onConfirm"];
25
+
20
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); }
21
27
 
22
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; }
23
29
 
24
- /** @jsxImportSource theme-ui */
25
-
26
- /**
27
- * External dependencies
28
- */
29
-
30
- /**
31
- /**
32
- * Internal dependencies
33
- */
34
30
  var _default = {
35
31
  title: 'Dropdown',
36
32
  component: Dropdown.Root
@@ -150,7 +146,7 @@ var ComplexOptions = function ComplexOptions() {
150
146
 
151
147
  exports.ComplexOptions = ComplexOptions;
152
148
 
153
- var WithDialogState = function WithDialogState() {
149
+ var WithDialog = function WithDialog() {
154
150
  var _React$useState4 = _react["default"].useState(false),
155
151
  alertOpen = _React$useState4[0],
156
152
  setAlertOpen = _React$useState4[1];
@@ -159,43 +155,57 @@ var WithDialogState = function WithDialogState() {
159
155
  menuOpen = _React$useState5[0],
160
156
  setMenuOpen = _React$useState5[1];
161
157
 
162
- var triggerRef = _react["default"].useRef();
158
+ var AreYouSureDialog = function AreYouSureDialog(_ref) {
159
+ var onConfirm = _ref.onConfirm,
160
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
161
+ return (0, _jsxRuntime.jsx)(NewDialog.Root, (0, _extends2["default"])({}, props, {
162
+ content: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
163
+ children: [(0, _jsxRuntime.jsx)(_Button.Button, {
164
+ variant: "secondary",
165
+ onClick: function onClick() {
166
+ return onConfirm();
167
+ },
168
+ children: "Custom Close."
169
+ }), (0, _jsxRuntime.jsx)("p", {
170
+ children: "Teste abc."
171
+ })]
172
+ })
173
+ }));
174
+ };
163
175
 
164
- return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
176
+ return (0, _jsxRuntime.jsxs)("div", {
165
177
  children: [(0, _jsxRuntime.jsx)("p", {
166
- children: "In this example, you can see how to trigger a Dialog from the Dropdown and still keep the focus back to the dropdown once the Dialog is closed. This example is important to keep accessibility."
167
- }), (0, _jsxRuntime.jsx)(Dropdown.Root, {
178
+ children: "This is an important example when combining the Dropdown component with the NewDialog component. In order to have the correct accessibility, there are some events you need to use. Use this example if you want to copy and paste the code."
179
+ }), (0, _jsxRuntime.jsxs)(Dropdown.Root, {
180
+ modal: !alertOpen,
168
181
  open: menuOpen,
169
182
  onOpenChange: setMenuOpen,
183
+ contentProps: {
184
+ sideOffset: 5
185
+ },
170
186
  trigger: (0, _jsxRuntime.jsx)(_Button.Button, {
171
- ref: triggerRef,
172
187
  children: "Open"
173
188
  }),
174
- children: (0, _jsxRuntime.jsxs)(Dropdown.Content, {
175
- hidden: alertOpen,
176
- children: [(0, _jsxRuntime.jsx)(Dropdown.Item, {
177
- children: "Copy"
178
- }), (0, _jsxRuntime.jsx)(_NewConfirmationDialog.NewConfirmationDialog, {
179
- title: 'Are you sure?',
180
- description: 'Please confirm that',
181
- body: "Bla bleh.",
182
- needsConfirm: true,
183
- open: alertOpen,
184
- onOpenChange: setAlertOpen,
185
- onConfirm: function onConfirm() {
186
- setMenuOpen(false);
187
- triggerRef.current.focus();
189
+ children: [(0, _jsxRuntime.jsx)(Dropdown.Item, {
190
+ children: "I don't do anything"
191
+ }), (0, _jsxRuntime.jsx)(AreYouSureDialog, {
192
+ title: "Are you in the jungle?",
193
+ description: "sha-n-n-n-n-n-n-n-n knees, knees",
194
+ open: alertOpen,
195
+ onOpenChange: setAlertOpen,
196
+ onConfirm: function onConfirm() {
197
+ setAlertOpen(false);
198
+ setMenuOpen(false);
199
+ },
200
+ trigger: (0, _jsxRuntime.jsx)(Dropdown.Item, {
201
+ onSelect: function onSelect(event) {
202
+ return event.preventDefault();
188
203
  },
189
- trigger: (0, _jsxRuntime.jsx)(Dropdown.Item, {
190
- onSelect: function onSelect(event) {
191
- return event.preventDefault();
192
- },
193
- children: "Click here"
194
- })
195
- })]
196
- })
204
+ children: "Open Dialog"
205
+ })
206
+ })]
197
207
  })]
198
208
  });
199
209
  };
200
210
 
201
- exports.WithDialogState = WithDialogState;
211
+ exports.WithDialog = WithDialog;
@@ -5,6 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.NewConfirmationDialog = void 0;
7
7
 
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
8
12
  var _classnames = _interopRequireDefault(require("classnames"));
9
13
 
10
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -15,18 +19,13 @@ var _ = require("..");
15
19
 
16
20
  var _jsxRuntime = require("theme-ui/jsx-runtime");
17
21
 
18
- /** @jsxImportSource theme-ui */
22
+ var _excluded = ["trigger", "onConfirm", "needsConfirm", "label", "buttonVariant", "title", "body"];
19
23
 
20
- /**
21
- * External dependencies
22
- */
23
-
24
- /**
25
- * Internal dependencies
26
- */
27
24
  var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
28
25
  var _ref$label = _ref.label,
29
26
  label = _ref$label === void 0 ? 'Confirm' : _ref$label,
27
+ _ref$buttonVariant = _ref.buttonVariant,
28
+ buttonVariant = _ref$buttonVariant === void 0 ? 'danger' : _ref$buttonVariant,
30
29
  onConfirm = _ref.onConfirm,
31
30
  onClose = _ref.onClose,
32
31
  _ref$className = _ref.className,
@@ -47,7 +46,7 @@ var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
47
46
  children: "Cancel"
48
47
  }), (0, _jsxRuntime.jsx)(_.NewDialog.Close, {
49
48
  children: (0, _jsxRuntime.jsx)(_.Button, {
50
- variant: "danger",
49
+ variant: buttonVariant,
51
50
  onClick: function onClick() {
52
51
  onConfirm();
53
52
  onClose();
@@ -62,6 +61,7 @@ var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
62
61
  NewConfirmationDialogContent.propTypes = {
63
62
  body: _propTypes["default"].node,
64
63
  label: _propTypes["default"].string,
64
+ buttonVariant: _propTypes["default"].string,
65
65
  onClose: _propTypes["default"].func,
66
66
  onConfirm: _propTypes["default"].func,
67
67
  className: _propTypes["default"].any
@@ -73,13 +73,11 @@ var NewConfirmationDialog = function NewConfirmationDialog(_ref2) {
73
73
  _ref2$needsConfirm = _ref2.needsConfirm,
74
74
  needsConfirm = _ref2$needsConfirm === void 0 ? true : _ref2$needsConfirm,
75
75
  label = _ref2.label,
76
+ buttonVariant = _ref2.buttonVariant,
76
77
  title = _ref2.title,
77
78
  _ref2$body = _ref2.body,
78
- body = _ref2$body === void 0 ? '' : _ref2$body;
79
-
80
- var _React$useState = _react["default"].useState(false),
81
- open = _React$useState[0],
82
- setOpen = _React$useState[1];
79
+ body = _ref2$body === void 0 ? '' : _ref2$body,
80
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded);
83
81
 
84
82
  var directTrigger = /*#__PURE__*/_react["default"].cloneElement(trigger, {
85
83
  onClick: onConfirm
@@ -89,24 +87,24 @@ var NewConfirmationDialog = function NewConfirmationDialog(_ref2) {
89
87
  return directTrigger;
90
88
  }
91
89
 
92
- return (0, _jsxRuntime.jsx)(_.NewDialog.Root, {
93
- open: open,
94
- onOpenChange: setOpen,
90
+ return (0, _jsxRuntime.jsx)(_.NewDialog.Root, (0, _extends2["default"])({
95
91
  sx: {
96
92
  maxWidth: 680
97
93
  },
98
94
  title: title,
99
95
  description: body,
100
- content: (0, _jsxRuntime.jsx)(NewConfirmationDialogContent, {
101
- onClose: function onClose() {
102
- return setOpen(false);
103
- },
104
- onConfirm: onConfirm,
105
- body: body,
106
- label: label
107
- }),
96
+ content: function content(_ref3) {
97
+ var onClose = _ref3.onClose;
98
+ return (0, _jsxRuntime.jsx)(NewConfirmationDialogContent, {
99
+ onClose: onClose,
100
+ onConfirm: onConfirm,
101
+ body: body,
102
+ label: label,
103
+ buttonVariant: buttonVariant
104
+ });
105
+ },
108
106
  trigger: trigger
109
- });
107
+ }, props));
110
108
  };
111
109
 
112
110
  exports.NewConfirmationDialog = NewConfirmationDialog;
@@ -116,5 +114,6 @@ NewConfirmationDialog.propTypes = {
116
114
  onConfirm: _propTypes["default"].func,
117
115
  title: _propTypes["default"].node.isRequired,
118
116
  body: _propTypes["default"].node,
119
- label: _propTypes["default"].node
117
+ label: _propTypes["default"].node,
118
+ buttonVariant: _propTypes["default"].string
120
119
  };
@@ -36,6 +36,7 @@ var Default = function Default() {
36
36
  children: "Confirm that your name is John doe?"
37
37
  }), (0, _jsxRuntime.jsx)(_.NewConfirmationDialog, {
38
38
  title: 'Are you John Doe?',
39
+ buttonVariant: "danger",
39
40
  description: 'Please confirm that your name is John Doe.',
40
41
  trigger: ConfirmationTrigger,
41
42
  body: "A modal is used to perform more detailed actions that don\u2018t necessarily need the context behind.",
@@ -50,6 +50,10 @@ var NewDialog = function NewDialog(_ref) {
50
50
  _ref$disabled = _ref.disabled,
51
51
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
52
52
  extraStyles = _ref.style,
53
+ _ref$contentProps = _ref.contentProps,
54
+ contentProps = _ref$contentProps === void 0 ? {} : _ref$contentProps,
55
+ _ref$portalProps = _ref.portalProps,
56
+ portalProps = _ref$portalProps === void 0 ? {} : _ref$portalProps,
53
57
  _ref$defaultOpen = _ref.defaultOpen,
54
58
  defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
55
59
  _ref$allowPinchZoom = _ref.allowPinchZoom,
@@ -93,10 +97,11 @@ var NewDialog = function NewDialog(_ref) {
93
97
  children: [trigger && (0, _jsxRuntime.jsx)(DialogPrimitive.Trigger, {
94
98
  asChild: true,
95
99
  children: trigger
96
- }), (0, _jsxRuntime.jsxs)(DialogPrimitive.Portal, {
97
- children: [(0, _jsxRuntime.jsx)(_DialogOverlay.DialogOverlay, {}), (0, _jsxRuntime.jsxs)(DialogPrimitive.Content, {
100
+ }), (0, _jsxRuntime.jsxs)(DialogPrimitive.Portal, (0, _extends2["default"])({}, portalProps, {
101
+ children: [(0, _jsxRuntime.jsx)(_DialogOverlay.DialogOverlay, {}), (0, _jsxRuntime.jsxs)(DialogPrimitive.Content, (0, _extends2["default"])({
98
102
  className: "vip-dialog-component",
99
- sx: (0, _extends2["default"])({}, _DialogContent.contentStyles, extraStyles),
103
+ sx: (0, _extends2["default"])({}, _DialogContent.contentStyles, extraStyles)
104
+ }, contentProps, {
100
105
  children: [(0, _jsxRuntime.jsx)(_DialogClose.DialogCloseDefault, {}), (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, {
101
106
  title: title,
102
107
  hidden: !showHeading
@@ -111,8 +116,8 @@ var NewDialog = function NewDialog(_ref) {
111
116
  }
112
117
  }) : content
113
118
  })]
114
- })]
115
- })]
119
+ }))]
120
+ }))]
116
121
  });
117
122
  };
118
123
 
@@ -125,6 +130,10 @@ NewDialog.propTypes = {
125
130
  showHeading: _propTypes["default"].bool,
126
131
  disabled: _propTypes["default"].bool,
127
132
  style: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].func]),
133
+ // Content props in: https://www.radix-ui.com/docs/primitives/components/dialog#content
134
+ contentProps: _propTypes["default"].any,
135
+ // Portal props in: https://www.radix-ui.com/docs/primitives/components/dialog#portal
136
+ portalProps: _propTypes["default"].any,
128
137
  // Radix DialogPrimitive.Root properties
129
138
  // https://www.radix-ui.com/docs/primitives/components/dialog#root
130
139
  id: _propTypes["default"].string,
@@ -35,7 +35,11 @@ var StyledArrow = function StyledArrow(props) {
35
35
 
36
36
  var Tooltip = function Tooltip(_ref) {
37
37
  var _ref$trigger = _ref.trigger,
38
- trigger = _ref$trigger === void 0 ? (0, _jsxRuntime.jsx)(_md.MdHelp, {}) : _ref$trigger,
38
+ trigger = _ref$trigger === void 0 ? (0, _jsxRuntime.jsx)(_md.MdHelp, {
39
+ sx: {
40
+ fill: 'text'
41
+ }
42
+ }) : _ref$trigger,
39
43
  _ref$text = _ref.text,
40
44
  text = _ref$text === void 0 ? '' : _ref$text,
41
45
  _ref$width = _ref.width,
@@ -67,7 +71,12 @@ var Tooltip = function Tooltip(_ref) {
67
71
  background: 'transparent',
68
72
  border: 'none',
69
73
  display: 'inline-flex',
70
- outline: 'none',
74
+ '&:focus': function focus(theme) {
75
+ return theme.outline;
76
+ },
77
+ '&:focus-visible': function focusVisible(theme) {
78
+ return theme.outline;
79
+ },
71
80
  p: 0,
72
81
  m: 0
73
82
  },
@@ -75,12 +84,14 @@ var Tooltip = function Tooltip(_ref) {
75
84
  children: [(0, _jsxRuntime.jsx)(_.Card, (0, _extends2["default"])({
76
85
  className: "tooltip-content",
77
86
  sx: {
78
- width: width
87
+ width: width,
88
+ background: 'dialog'
79
89
  }
80
90
  }, props, {
81
91
  children: children ? children : (0, _jsxRuntime.jsx)(_.Text, {
82
92
  sx: {
83
- fontSize: 1
93
+ fontSize: 2,
94
+ color: 'text'
84
95
  },
85
96
  children: text
86
97
  })
@@ -30,7 +30,8 @@ var Default = function Default() {
30
30
  }), (0, _jsxRuntime.jsx)(_.Tooltip, {
31
31
  children: (0, _jsxRuntime.jsxs)(_.Text, {
32
32
  sx: {
33
- fontSize: 1
33
+ fontSize: 1,
34
+ color: 'text'
34
35
  },
35
36
  children: ["This is a tooltip that can be used to describe various pieces of functionality.", (0, _jsxRuntime.jsx)("br", {}), (0, _jsxRuntime.jsx)(_.Link, {
36
37
  children: "Find out more \u2192"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.18.2-0",
3
+ "version": "0.18.5-0",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
@@ -22,7 +22,18 @@ const DropdownSub = DropdownMenuPrimitive.DropdownMenuSub;
22
22
  const DropdownSubTrigger = DropdownMenuPrimitive.DropdownMenuSubTrigger;
23
23
  const DropdownSubContent = DropdownMenuPrimitive.DropdownMenuSubContent;
24
24
 
25
- export const Dropdown = ( { trigger, children } ) => {
25
+ export const Dropdown = ( {
26
+ trigger,
27
+ children,
28
+ // Radix Specific Properties
29
+ open = undefined,
30
+ defaultOpen = false,
31
+ onOpenChange = undefined,
32
+ modal = true,
33
+ dir = 'ltr',
34
+ contentProps = {},
35
+ portalProps = {},
36
+ } ) => {
26
37
  const firstChild = React.useMemo(
27
38
  () =>
28
39
  React.isValidElement( children ) ? React.Children.only( children )?.type?.displayName : '',
@@ -30,17 +41,23 @@ export const Dropdown = ( { trigger, children } ) => {
30
41
  );
31
42
 
32
43
  return (
33
- <DropdownMenu>
44
+ <DropdownMenu
45
+ open={ open }
46
+ defaultOpen={ defaultOpen }
47
+ onOpenChange={ onOpenChange }
48
+ modal={ modal }
49
+ dir={ dir }
50
+ >
34
51
  <DropdownTrigger asChild>{ trigger }</DropdownTrigger>
35
52
 
36
- <DropdownMenuPrimitive.Portal>
53
+ <DropdownMenuPrimitive.Portal { ...portalProps }>
37
54
  { /* User can customize the content */ }
38
55
  { firstChild === 'DropdownContent' ? (
39
56
  children
40
57
  ) : (
41
- <DropdownContent>
58
+ <DropdownContent { ...contentProps }>
42
59
  { children }
43
- <DropdownMenuPrimitive.Arrow sx={ { fill: 'white' } } />
60
+ <DropdownMenuPrimitive.Arrow sx={ { fill: 'background', boxShadow: 'high' } } />
44
61
  </DropdownContent>
45
62
  ) }
46
63
  </DropdownMenuPrimitive.Portal>
@@ -51,6 +68,18 @@ export const Dropdown = ( { trigger, children } ) => {
51
68
  Dropdown.propTypes = {
52
69
  trigger: PropTypes.node.isRequired,
53
70
  children: PropTypes.node.isRequired,
71
+
72
+ // Props in root: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#root
73
+ open: PropTypes.bool,
74
+ defaultOpen: PropTypes.bool,
75
+ onOpenChange: PropTypes.func,
76
+ modal: PropTypes.bool,
77
+ dir: PropTypes.string,
78
+
79
+ // Content props in: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#content
80
+ contentProps: PropTypes.any,
81
+ // Portal props in: https://www.radix-ui.com/docs/primitives/components/dropdown-menu#portal
82
+ portalProps: PropTypes.any,
54
83
  };
55
84
 
56
85
  // Exports
@@ -1,5 +1,3 @@
1
- /** @jsxImportSource theme-ui */
2
-
3
1
  /**
4
2
  * External dependencies
5
3
  */
@@ -7,13 +5,13 @@ import React from 'react';
7
5
  import { DotFilledIcon, CheckIcon, ChevronRightIcon } from '@radix-ui/react-icons';
8
6
 
9
7
  /**
10
- /**
8
+ /**
11
9
  * Internal dependencies
12
10
  */
13
11
 
14
12
  import * as Dropdown from '.';
15
13
  import { Button } from '../Button';
16
- import { NewConfirmationDialog } from '../NewConfirmationDialog';
14
+ import * as NewDialog from '../NewDialog';
17
15
 
18
16
  export default {
19
17
  title: 'Dropdown',
@@ -115,43 +113,56 @@ export const ComplexOptions = () => {
115
113
  );
116
114
  };
117
115
 
118
- export const WithDialogState = () => {
116
+ export const WithDialog = () => {
119
117
  const [ alertOpen, setAlertOpen ] = React.useState( false );
120
118
  const [ menuOpen, setMenuOpen ] = React.useState( false );
121
- const triggerRef = React.useRef();
119
+
120
+ const AreYouSureDialog = ( { onConfirm, ...props } ) => (
121
+ <NewDialog.Root
122
+ { ...props }
123
+ content={
124
+ <>
125
+ <Button variant="secondary" onClick={ () => onConfirm() }>
126
+ Custom Close.
127
+ </Button>
128
+
129
+ <p>Teste abc.</p>
130
+ </>
131
+ }
132
+ />
133
+ );
134
+
122
135
  return (
123
- <>
136
+ <div>
124
137
  <p>
125
- In this example, you can see how to trigger a Dialog from the Dropdown and still keep the
126
- focus back to the dropdown once the Dialog is closed. This example is important to keep
127
- accessibility.
138
+ This is an important example when combining the Dropdown component with the NewDialog
139
+ component. In order to have the correct accessibility, there are some events you need to
140
+ use. Use this example if you want to copy and paste the code.
128
141
  </p>
129
142
 
130
143
  <Dropdown.Root
144
+ modal={ ! alertOpen }
131
145
  open={ menuOpen }
132
146
  onOpenChange={ setMenuOpen }
133
- trigger={ <Button ref={ triggerRef }>Open</Button> }
147
+ contentProps={ { sideOffset: 5 } }
148
+ trigger={ <Button>Open</Button> }
134
149
  >
135
- <Dropdown.Content hidden={ alertOpen }>
136
- <Dropdown.Item>Copy</Dropdown.Item>
150
+ <Dropdown.Item>I don&apos;t do anything</Dropdown.Item>
137
151
 
138
- <NewConfirmationDialog
139
- title={ 'Are you sure?' }
140
- description={ 'Please confirm that' }
141
- body="Bla bleh."
142
- needsConfirm={ true }
143
- open={ alertOpen }
144
- onOpenChange={ setAlertOpen }
145
- onConfirm={ () => {
146
- setMenuOpen( false );
147
- triggerRef.current.focus();
148
- } }
149
- trigger={
150
- <Dropdown.Item onSelect={ event => event.preventDefault() }>Click here</Dropdown.Item>
151
- }
152
- />
153
- </Dropdown.Content>
152
+ <AreYouSureDialog
153
+ title="Are you in the jungle?"
154
+ description="sha-n-n-n-n-n-n-n-n knees, knees"
155
+ open={ alertOpen }
156
+ onOpenChange={ setAlertOpen }
157
+ onConfirm={ () => {
158
+ setAlertOpen( false );
159
+ setMenuOpen( false );
160
+ } }
161
+ trigger={
162
+ <Dropdown.Item onSelect={ event => event.preventDefault() }>Open Dialog</Dropdown.Item>
163
+ }
164
+ />
154
165
  </Dropdown.Root>
155
- </>
166
+ </div>
156
167
  );
157
168
  };
@@ -14,6 +14,7 @@ import { NewDialog, Box, Flex, Button } from '..';
14
14
 
15
15
  const NewConfirmationDialogContent = ( {
16
16
  label = 'Confirm',
17
+ buttonVariant = 'danger',
17
18
  onConfirm,
18
19
  onClose,
19
20
  className = null,
@@ -25,7 +26,7 @@ const NewConfirmationDialogContent = ( {
25
26
  </Button>
26
27
  <NewDialog.Close>
27
28
  <Button
28
- variant="danger"
29
+ variant={ buttonVariant }
29
30
  onClick={ () => {
30
31
  onConfirm();
31
32
  onClose();
@@ -41,6 +42,7 @@ const NewConfirmationDialogContent = ( {
41
42
  NewConfirmationDialogContent.propTypes = {
42
43
  body: PropTypes.node,
43
44
  label: PropTypes.string,
45
+ buttonVariant: PropTypes.string,
44
46
  onClose: PropTypes.func,
45
47
  onConfirm: PropTypes.func,
46
48
  className: PropTypes.any,
@@ -51,10 +53,11 @@ const NewConfirmationDialog = ( {
51
53
  onConfirm,
52
54
  needsConfirm = true,
53
55
  label,
56
+ buttonVariant,
54
57
  title,
55
58
  body = '',
59
+ ...props
56
60
  } ) => {
57
- const [ open, setOpen ] = React.useState( false );
58
61
  const directTrigger = React.cloneElement( trigger, { onClick: onConfirm } );
59
62
 
60
63
  if ( ! needsConfirm ) {
@@ -63,20 +66,20 @@ const NewConfirmationDialog = ( {
63
66
 
64
67
  return (
65
68
  <NewDialog.Root
66
- open={ open }
67
- onOpenChange={ setOpen }
68
69
  sx={ { maxWidth: 680 } }
69
70
  title={ title }
70
71
  description={ body }
71
- content={
72
+ content={ ( { onClose } ) => (
72
73
  <NewConfirmationDialogContent
73
- onClose={ () => setOpen( false ) }
74
+ onClose={ onClose }
74
75
  onConfirm={ onConfirm }
75
76
  body={ body }
76
77
  label={ label }
78
+ buttonVariant={ buttonVariant }
77
79
  />
78
- }
80
+ ) }
79
81
  trigger={ trigger }
82
+ { ...props }
80
83
  />
81
84
  );
82
85
  };
@@ -88,6 +91,7 @@ NewConfirmationDialog.propTypes = {
88
91
  title: PropTypes.node.isRequired,
89
92
  body: PropTypes.node,
90
93
  label: PropTypes.node,
94
+ buttonVariant: PropTypes.string,
91
95
  };
92
96
 
93
97
  export { NewConfirmationDialog };
@@ -18,6 +18,7 @@ export const Default = () => {
18
18
  <p>Confirm that your name is John doe?</p>
19
19
  <NewConfirmationDialog
20
20
  title={ 'Are you John Doe?' }
21
+ buttonVariant="danger"
21
22
  description={ 'Please confirm that your name is John Doe.' }
22
23
  trigger={ ConfirmationTrigger }
23
24
  body="A modal is used to perform more detailed actions that don&lsquo;t necessarily need the context
@@ -23,6 +23,8 @@ export const NewDialog = ( {
23
23
  showHeading = true,
24
24
  disabled = false,
25
25
  style: extraStyles,
26
+ contentProps = {},
27
+ portalProps = {},
26
28
 
27
29
  // Radix Specific Properties
28
30
  defaultOpen = false,
@@ -62,12 +64,13 @@ export const NewDialog = ( {
62
64
  >
63
65
  { trigger && <DialogPrimitive.Trigger asChild>{ trigger }</DialogPrimitive.Trigger> }
64
66
 
65
- <DialogPrimitive.Portal>
67
+ <DialogPrimitive.Portal { ...portalProps }>
66
68
  <DialogOverlay />
67
69
 
68
70
  <DialogPrimitive.Content
69
71
  className="vip-dialog-component"
70
72
  sx={ { ...contentStyles, ...extraStyles } }
73
+ { ...contentProps }
71
74
  >
72
75
  <DialogClose />
73
76
  <DialogTitle title={ title } hidden={ ! showHeading } />
@@ -91,6 +94,12 @@ NewDialog.propTypes = {
91
94
  disabled: PropTypes.bool,
92
95
  style: PropTypes.oneOfType( [ PropTypes.object, PropTypes.func ] ),
93
96
 
97
+ // Content props in: https://www.radix-ui.com/docs/primitives/components/dialog#content
98
+ contentProps: PropTypes.any,
99
+
100
+ // Portal props in: https://www.radix-ui.com/docs/primitives/components/dialog#portal
101
+ portalProps: PropTypes.any,
102
+
94
103
  // Radix DialogPrimitive.Root properties
95
104
  // https://www.radix-ui.com/docs/primitives/components/dialog#root
96
105
  id: PropTypes.string,
@@ -15,7 +15,7 @@ import { Card, Text } from '..';
15
15
  const StyledArrow = props => <TooltipPrimitive.Arrow sx={ { fill: 'white' } } { ...props } />;
16
16
 
17
17
  const Tooltip = ( {
18
- trigger = <MdHelp />,
18
+ trigger = <MdHelp sx={ { fill: 'text' } } />,
19
19
  text = '',
20
20
  width = 200,
21
21
  children,
@@ -48,7 +48,8 @@ const Tooltip = ( {
48
48
  background: 'transparent',
49
49
  border: 'none',
50
50
  display: 'inline-flex',
51
- outline: 'none',
51
+ '&:focus': theme => theme.outline,
52
+ '&:focus-visible': theme => theme.outline,
52
53
  p: 0,
53
54
  m: 0,
54
55
  } }
@@ -56,8 +57,8 @@ const Tooltip = ( {
56
57
  { trigger }
57
58
 
58
59
  <TooltipPrimitive.Content>
59
- <Card className="tooltip-content" sx={ { width: width } } { ...props }>
60
- { children ? children : <Text sx={ { fontSize: 1 } }>{ text }</Text> }
60
+ <Card className="tooltip-content" sx={ { width, background: 'dialog' } } { ...props }>
61
+ { children ? children : <Text sx={ { fontSize: 2, color: 'text' } }>{ text }</Text> }
61
62
  </Card>
62
63
  <StyledArrow />
63
64
  </TooltipPrimitive.Content>
@@ -12,7 +12,7 @@ export const Default = () => (
12
12
  <Flex sx={ { alignItems: 'center' } }>
13
13
  <Heading sx={ { mb: 0, mr: 2 } }>My Section Heading</Heading>
14
14
  <Tooltip>
15
- <Text sx={ { fontSize: 1 } }>
15
+ <Text sx={ { fontSize: 1, color: 'text' } }>
16
16
  This is a tooltip that can be used to describe various pieces of functionality.
17
17
  <br />
18
18
  <Link>Find out more &rarr;</Link>