@automattic/vip-design-system 0.18.2-0 → 0.18.3-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.
- package/build/system/Dropdown/Dropdown.js +39 -7
- package/build/system/Dropdown/Dropdown.stories.js +55 -41
- package/build/system/NewConfirmationDialog/NewConfirmationDialog.js +9 -3
- package/build/system/NewConfirmationDialog/NewConfirmationDialog.stories.js +1 -0
- package/build/system/NewDialog/NewDialog.js +14 -5
- package/package.json +1 -1
- package/src/system/Dropdown/Dropdown.js +34 -5
- package/src/system/Dropdown/Dropdown.stories.jsx +45 -30
- package/src/system/NewConfirmationDialog/NewConfirmationDialog.js +6 -1
- package/src/system/NewConfirmationDialog/NewConfirmationDialog.stories.jsx +1 -0
- package/src/system/NewDialog/NewDialog.js +10 -1
|
@@ -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: '
|
|
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.
|
|
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
|
|
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
|
|
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,61 @@ var WithDialogState = function WithDialogState() {
|
|
|
159
155
|
menuOpen = _React$useState5[0],
|
|
160
156
|
setMenuOpen = _React$useState5[1];
|
|
161
157
|
|
|
162
|
-
var
|
|
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
|
+
contentProps: {
|
|
163
|
+
onCloseAutoFocus: function onCloseAutoFocus() {
|
|
164
|
+
onConfirm();
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
content: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
168
|
+
children: [(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
169
|
+
variant: "secondary",
|
|
170
|
+
onClick: function onClick() {
|
|
171
|
+
return onConfirm();
|
|
172
|
+
},
|
|
173
|
+
children: "Custom Close."
|
|
174
|
+
}), (0, _jsxRuntime.jsx)("p", {
|
|
175
|
+
children: "Teste abc."
|
|
176
|
+
})]
|
|
177
|
+
})
|
|
178
|
+
}));
|
|
179
|
+
};
|
|
163
180
|
|
|
164
|
-
return (0, _jsxRuntime.jsxs)(
|
|
181
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
165
182
|
children: [(0, _jsxRuntime.jsx)("p", {
|
|
166
|
-
children: "
|
|
167
|
-
}), (0, _jsxRuntime.
|
|
183
|
+
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."
|
|
184
|
+
}), (0, _jsxRuntime.jsxs)(Dropdown.Root, {
|
|
168
185
|
open: menuOpen,
|
|
169
186
|
onOpenChange: setMenuOpen,
|
|
187
|
+
contentProps: {
|
|
188
|
+
sideOffset: 5
|
|
189
|
+
},
|
|
170
190
|
trigger: (0, _jsxRuntime.jsx)(_Button.Button, {
|
|
171
|
-
ref: triggerRef,
|
|
172
191
|
children: "Open"
|
|
173
192
|
}),
|
|
174
|
-
children: (0, _jsxRuntime.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
children: [(0, _jsxRuntime.jsx)(Dropdown.Item, {
|
|
194
|
+
children: "I don't do anything"
|
|
195
|
+
}), (0, _jsxRuntime.jsx)(AreYouSureDialog, {
|
|
196
|
+
title: "Are you in the jungle?",
|
|
197
|
+
description: "sha-n-n-n-n-n-n-n-n knees, knees",
|
|
198
|
+
open: alertOpen,
|
|
199
|
+
onOpenChange: setAlertOpen,
|
|
200
|
+
onConfirm: function onConfirm() {
|
|
201
|
+
setAlertOpen(false);
|
|
202
|
+
setMenuOpen(false);
|
|
203
|
+
},
|
|
204
|
+
trigger: (0, _jsxRuntime.jsx)(Dropdown.Item, {
|
|
205
|
+
onSelect: function onSelect(event) {
|
|
206
|
+
return event.preventDefault();
|
|
188
207
|
},
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
},
|
|
193
|
-
children: "Click here"
|
|
194
|
-
})
|
|
195
|
-
})]
|
|
196
|
-
})
|
|
208
|
+
children: "Open Dialog"
|
|
209
|
+
})
|
|
210
|
+
})]
|
|
197
211
|
})]
|
|
198
212
|
});
|
|
199
213
|
};
|
|
200
214
|
|
|
201
|
-
exports.
|
|
215
|
+
exports.WithDialog = WithDialog;
|
|
@@ -27,6 +27,8 @@ var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
|
27
27
|
var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
|
|
28
28
|
var _ref$label = _ref.label,
|
|
29
29
|
label = _ref$label === void 0 ? 'Confirm' : _ref$label,
|
|
30
|
+
_ref$buttonVariant = _ref.buttonVariant,
|
|
31
|
+
buttonVariant = _ref$buttonVariant === void 0 ? 'danger' : _ref$buttonVariant,
|
|
30
32
|
onConfirm = _ref.onConfirm,
|
|
31
33
|
onClose = _ref.onClose,
|
|
32
34
|
_ref$className = _ref.className,
|
|
@@ -47,7 +49,7 @@ var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
|
|
|
47
49
|
children: "Cancel"
|
|
48
50
|
}), (0, _jsxRuntime.jsx)(_.NewDialog.Close, {
|
|
49
51
|
children: (0, _jsxRuntime.jsx)(_.Button, {
|
|
50
|
-
variant:
|
|
52
|
+
variant: buttonVariant,
|
|
51
53
|
onClick: function onClick() {
|
|
52
54
|
onConfirm();
|
|
53
55
|
onClose();
|
|
@@ -62,6 +64,7 @@ var NewConfirmationDialogContent = function NewConfirmationDialogContent(_ref) {
|
|
|
62
64
|
NewConfirmationDialogContent.propTypes = {
|
|
63
65
|
body: _propTypes["default"].node,
|
|
64
66
|
label: _propTypes["default"].string,
|
|
67
|
+
buttonVariant: _propTypes["default"].string,
|
|
65
68
|
onClose: _propTypes["default"].func,
|
|
66
69
|
onConfirm: _propTypes["default"].func,
|
|
67
70
|
className: _propTypes["default"].any
|
|
@@ -73,6 +76,7 @@ var NewConfirmationDialog = function NewConfirmationDialog(_ref2) {
|
|
|
73
76
|
_ref2$needsConfirm = _ref2.needsConfirm,
|
|
74
77
|
needsConfirm = _ref2$needsConfirm === void 0 ? true : _ref2$needsConfirm,
|
|
75
78
|
label = _ref2.label,
|
|
79
|
+
buttonVariant = _ref2.buttonVariant,
|
|
76
80
|
title = _ref2.title,
|
|
77
81
|
_ref2$body = _ref2.body,
|
|
78
82
|
body = _ref2$body === void 0 ? '' : _ref2$body;
|
|
@@ -103,7 +107,8 @@ var NewConfirmationDialog = function NewConfirmationDialog(_ref2) {
|
|
|
103
107
|
},
|
|
104
108
|
onConfirm: onConfirm,
|
|
105
109
|
body: body,
|
|
106
|
-
label: label
|
|
110
|
+
label: label,
|
|
111
|
+
buttonVariant: buttonVariant
|
|
107
112
|
}),
|
|
108
113
|
trigger: trigger
|
|
109
114
|
});
|
|
@@ -116,5 +121,6 @@ NewConfirmationDialog.propTypes = {
|
|
|
116
121
|
onConfirm: _propTypes["default"].func,
|
|
117
122
|
title: _propTypes["default"].node.isRequired,
|
|
118
123
|
body: _propTypes["default"].node,
|
|
119
|
-
label: _propTypes["default"].node
|
|
124
|
+
label: _propTypes["default"].node,
|
|
125
|
+
buttonVariant: _propTypes["default"].string
|
|
120
126
|
};
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -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 = ( {
|
|
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: '
|
|
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
|
|
14
|
+
import * as NewDialog from '../NewDialog';
|
|
17
15
|
|
|
18
16
|
export default {
|
|
19
17
|
title: 'Dropdown',
|
|
@@ -115,43 +113,60 @@ export const ComplexOptions = () => {
|
|
|
115
113
|
);
|
|
116
114
|
};
|
|
117
115
|
|
|
118
|
-
export const
|
|
116
|
+
export const WithDialog = () => {
|
|
119
117
|
const [ alertOpen, setAlertOpen ] = React.useState( false );
|
|
120
118
|
const [ menuOpen, setMenuOpen ] = React.useState( false );
|
|
121
|
-
|
|
119
|
+
|
|
120
|
+
const AreYouSureDialog = ( { onConfirm, ...props } ) => (
|
|
121
|
+
<NewDialog.Root
|
|
122
|
+
{ ...props }
|
|
123
|
+
contentProps={ {
|
|
124
|
+
onCloseAutoFocus: () => {
|
|
125
|
+
onConfirm();
|
|
126
|
+
},
|
|
127
|
+
} }
|
|
128
|
+
content={
|
|
129
|
+
<>
|
|
130
|
+
<Button variant="secondary" onClick={ () => onConfirm() }>
|
|
131
|
+
Custom Close.
|
|
132
|
+
</Button>
|
|
133
|
+
|
|
134
|
+
<p>Teste abc.</p>
|
|
135
|
+
</>
|
|
136
|
+
}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
|
|
122
140
|
return (
|
|
123
|
-
|
|
141
|
+
<div>
|
|
124
142
|
<p>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
This is an important example when combining the Dropdown component with the NewDialog
|
|
144
|
+
component. In order to have the correct accessibility, there are some events you need to
|
|
145
|
+
use. Use this example if you want to copy and paste the code.
|
|
128
146
|
</p>
|
|
129
147
|
|
|
130
148
|
<Dropdown.Root
|
|
131
149
|
open={ menuOpen }
|
|
132
150
|
onOpenChange={ setMenuOpen }
|
|
133
|
-
|
|
151
|
+
contentProps={ { sideOffset: 5 } }
|
|
152
|
+
trigger={ <Button>Open</Button> }
|
|
134
153
|
>
|
|
135
|
-
<Dropdown.
|
|
136
|
-
<Dropdown.Item>Copy</Dropdown.Item>
|
|
154
|
+
<Dropdown.Item>I don't do anything</Dropdown.Item>
|
|
137
155
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
/>
|
|
153
|
-
</Dropdown.Content>
|
|
156
|
+
<AreYouSureDialog
|
|
157
|
+
title="Are you in the jungle?"
|
|
158
|
+
description="sha-n-n-n-n-n-n-n-n knees, knees"
|
|
159
|
+
open={ alertOpen }
|
|
160
|
+
onOpenChange={ setAlertOpen }
|
|
161
|
+
onConfirm={ () => {
|
|
162
|
+
setAlertOpen( false );
|
|
163
|
+
setMenuOpen( false );
|
|
164
|
+
} }
|
|
165
|
+
trigger={
|
|
166
|
+
<Dropdown.Item onSelect={ event => event.preventDefault() }>Open Dialog</Dropdown.Item>
|
|
167
|
+
}
|
|
168
|
+
/>
|
|
154
169
|
</Dropdown.Root>
|
|
155
|
-
|
|
170
|
+
</div>
|
|
156
171
|
);
|
|
157
172
|
};
|
|
@@ -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=
|
|
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,6 +53,7 @@ const NewConfirmationDialog = ( {
|
|
|
51
53
|
onConfirm,
|
|
52
54
|
needsConfirm = true,
|
|
53
55
|
label,
|
|
56
|
+
buttonVariant,
|
|
54
57
|
title,
|
|
55
58
|
body = '',
|
|
56
59
|
} ) => {
|
|
@@ -74,6 +77,7 @@ const NewConfirmationDialog = ( {
|
|
|
74
77
|
onConfirm={ onConfirm }
|
|
75
78
|
body={ body }
|
|
76
79
|
label={ label }
|
|
80
|
+
buttonVariant={ buttonVariant }
|
|
77
81
|
/>
|
|
78
82
|
}
|
|
79
83
|
trigger={ trigger }
|
|
@@ -88,6 +92,7 @@ NewConfirmationDialog.propTypes = {
|
|
|
88
92
|
title: PropTypes.node.isRequired,
|
|
89
93
|
body: PropTypes.node,
|
|
90
94
|
label: PropTypes.node,
|
|
95
|
+
buttonVariant: PropTypes.string,
|
|
91
96
|
};
|
|
92
97
|
|
|
93
98
|
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‘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,
|