carbon-react 106.6.1 → 106.6.4
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/esm/__spec_helper__/expect.d.ts +8 -1
- package/esm/__spec_helper__/expect.js +1 -5
- package/esm/__spec_helper__/test-utils.d.ts +71 -33
- package/esm/__spec_helper__/test-utils.js +63 -65
- package/esm/components/action-popover/action-popover-context.d.ts +7 -2
- package/esm/components/action-popover/action-popover-context.js +1 -1
- package/esm/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
- package/esm/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
- package/esm/components/action-popover/action-popover-item/action-popover-item.component.js +99 -118
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.component.js +42 -53
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
- package/esm/components/action-popover/action-popover-test.stories.js +76 -0
- package/esm/components/action-popover/action-popover.component.d.ts +30 -53
- package/esm/components/action-popover/action-popover.component.js +205 -67
- package/esm/components/action-popover/action-popover.style.d.ts +17 -11
- package/esm/components/action-popover/action-popover.style.js +20 -26
- package/esm/components/action-popover/index.d.ts +9 -5
- package/esm/components/box/box.component.d.ts +12 -1
- package/esm/components/box/box.component.js +12 -23
- package/esm/components/box/box.config.d.ts +10 -12
- package/esm/components/box/index.d.ts +2 -1
- package/esm/components/button-bar/button-bar-test.stories.js +122 -0
- package/esm/components/button-bar/button-bar.component.d.ts +12 -15
- package/esm/components/button-bar/button-bar.component.js +331 -33
- package/esm/components/button-bar/button-bar.config.d.ts +2 -2
- package/esm/components/button-bar/button-bar.style.d.ts +4 -4
- package/esm/components/button-bar/button-bar.style.js +18 -33
- package/esm/components/button-bar/index.d.ts +2 -1
- package/esm/components/dismissible-box/dismissible-box.style.d.ts +1 -2
- package/esm/components/drawer/drawer.style.d.ts +1 -2
- package/esm/components/duelling-picklist/picklist/picklist.style.d.ts +2 -3
- package/esm/components/flat-table/flat-table.style.d.ts +1 -2
- package/esm/components/form/form.component.js +2 -1
- package/esm/components/link/link.component.js +1 -5
- package/esm/components/menu/__internal__/spec-helper/index.js +2 -1
- package/esm/components/menu/__internal__/submenu/submenu.component.js +21 -4
- package/esm/components/menu/menu.component.js +2 -1
- package/esm/components/menu/scrollable-block/scrollable-block.component.js +4 -2
- package/esm/components/modal/modal.component.js +3 -60
- package/esm/components/toast/toast.component.js +3 -13
- package/esm/hooks/__internal__/useModalManager/index.d.ts +1 -0
- package/esm/hooks/__internal__/useModalManager/index.js +1 -0
- package/esm/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
- package/esm/hooks/__internal__/useModalManager/useModalManager.js +66 -0
- package/lib/__spec_helper__/expect.d.ts +8 -1
- package/lib/__spec_helper__/expect.js +2 -4
- package/lib/__spec_helper__/test-utils.d.ts +71 -33
- package/lib/__spec_helper__/test-utils.js +63 -65
- package/lib/components/action-popover/action-popover-context.d.ts +7 -2
- package/lib/components/action-popover/action-popover-context.js +1 -1
- package/lib/components/action-popover/action-popover-divider/action-popover-divider.component.d.ts +1 -1
- package/lib/components/action-popover/action-popover-item/action-popover-item.component.d.ts +28 -41
- package/lib/components/action-popover/action-popover-item/action-popover-item.component.js +100 -119
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts +35 -2
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.js +44 -55
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.d.ts +20 -18
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.component.js +13 -5
- package/lib/components/action-popover/action-popover-test.stories.js +95 -0
- package/lib/components/action-popover/action-popover.component.d.ts +30 -53
- package/lib/components/action-popover/action-popover.component.js +206 -71
- package/lib/components/action-popover/action-popover.style.d.ts +17 -11
- package/lib/components/action-popover/action-popover.style.js +21 -28
- package/lib/components/action-popover/index.d.ts +9 -5
- package/lib/components/box/box.component.d.ts +12 -1
- package/lib/components/box/box.component.js +13 -26
- package/lib/components/box/box.config.d.ts +10 -12
- package/lib/components/box/index.d.ts +2 -1
- package/lib/components/button-bar/button-bar-test.stories.js +145 -0
- package/lib/components/button-bar/button-bar.component.d.ts +12 -15
- package/lib/components/button-bar/button-bar.component.js +336 -35
- package/lib/components/button-bar/button-bar.config.d.ts +2 -2
- package/lib/components/button-bar/button-bar.style.d.ts +4 -4
- package/lib/components/button-bar/button-bar.style.js +18 -35
- package/lib/components/button-bar/index.d.ts +2 -1
- package/lib/components/dismissible-box/dismissible-box.style.d.ts +1 -2
- package/lib/components/drawer/drawer.style.d.ts +1 -2
- package/lib/components/duelling-picklist/picklist/picklist.style.d.ts +2 -3
- package/lib/components/flat-table/flat-table.style.d.ts +1 -2
- package/lib/components/form/form.component.js +2 -1
- package/lib/components/link/link.component.js +1 -5
- package/lib/components/menu/__internal__/spec-helper/index.js +2 -1
- package/lib/components/menu/__internal__/submenu/submenu.component.js +21 -4
- package/lib/components/menu/menu.component.js +2 -1
- package/lib/components/menu/scrollable-block/scrollable-block.component.js +4 -2
- package/lib/components/modal/modal.component.js +3 -62
- package/lib/components/toast/toast.component.js +4 -17
- package/lib/hooks/__internal__/useModalManager/index.d.ts +1 -0
- package/lib/hooks/__internal__/useModalManager/index.js +15 -0
- package/lib/hooks/__internal__/useModalManager/package.json +6 -0
- package/lib/hooks/__internal__/useModalManager/useModalManager.d.ts +3 -0
- package/lib/hooks/__internal__/useModalManager/useModalManager.js +79 -0
- package/package.json +5 -1
- package/esm/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
- package/esm/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
- package/esm/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
- package/esm/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
- package/esm/components/action-popover/action-popover.d.ts +0 -39
- package/esm/components/box/box.d.ts +0 -31
- package/esm/components/button-bar/button-bar.d.ts +0 -24
- package/lib/components/action-popover/action-popover-divider/action-popover-divider.d.ts +0 -12
- package/lib/components/action-popover/action-popover-item/action-popover-item.d.ts +0 -26
- package/lib/components/action-popover/action-popover-menu/action-popover-menu.d.ts +0 -33
- package/lib/components/action-popover/action-popover-menu-button/action-popover-menu-button.d.ts +0 -13
- package/lib/components/action-popover/action-popover.d.ts +0 -39
- package/lib/components/box/box.d.ts +0 -31
- package/lib/components/button-bar/button-bar.d.ts +0 -24
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.
|
|
6
|
+
exports.default = exports.ActionPopoverItem = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
13
13
|
|
|
14
14
|
var _actionPopover = require("../action-popover.style");
|
|
15
15
|
|
|
@@ -21,6 +21,8 @@ var _actionPopoverContext = _interopRequireDefault(require("../action-popover-co
|
|
|
21
21
|
|
|
22
22
|
var _useLocale = _interopRequireDefault(require("../../../hooks/__internal__/useLocale"));
|
|
23
23
|
|
|
24
|
+
var _actionPopoverMenu = _interopRequireDefault(require("../action-popover-menu/action-popover-menu.component"));
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -31,13 +33,46 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
31
33
|
|
|
32
34
|
const INTERVAL = 150;
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
function checkRef(ref) {
|
|
37
|
+
return Boolean(ref && ref.current);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function leftAlignSubmenu(ref, submenuRef) {
|
|
41
|
+
/* istanbul ignore if */
|
|
42
|
+
if (!ref.current || !submenuRef.current) return true;
|
|
43
|
+
const {
|
|
44
|
+
left
|
|
45
|
+
} = ref.current.getBoundingClientRect();
|
|
46
|
+
const {
|
|
47
|
+
offsetWidth
|
|
48
|
+
} = submenuRef.current;
|
|
49
|
+
return left >= offsetWidth;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getContainerPosition(itemRef, submenuRef, placement) {
|
|
53
|
+
/* istanbul ignore if */
|
|
54
|
+
if (!itemRef.current || !submenuRef.current) return undefined;
|
|
55
|
+
const {
|
|
56
|
+
offsetWidth: parentWidth
|
|
57
|
+
} = itemRef.current;
|
|
58
|
+
const {
|
|
59
|
+
offsetWidth: submenuWidth
|
|
60
|
+
} = submenuRef.current;
|
|
61
|
+
const xPositionValue = leftAlignSubmenu(itemRef, submenuRef) ? -submenuWidth : parentWidth;
|
|
62
|
+
const yPositionName = placement === "top" ? "bottom" : "top";
|
|
63
|
+
return {
|
|
64
|
+
left: xPositionValue,
|
|
65
|
+
[yPositionName]: "calc(-1 * var(--spacing100))",
|
|
66
|
+
right: "auto"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ActionPopoverItem = ({
|
|
35
71
|
children,
|
|
36
72
|
icon,
|
|
37
73
|
disabled = false,
|
|
38
74
|
onClick: onClickProp,
|
|
39
75
|
submenu,
|
|
40
|
-
theme,
|
|
41
76
|
placement = "bottom",
|
|
42
77
|
focusItem,
|
|
43
78
|
download,
|
|
@@ -46,47 +81,49 @@ const MenuItem = ({
|
|
|
46
81
|
...rest
|
|
47
82
|
}) => {
|
|
48
83
|
const l = (0, _useLocale.default)();
|
|
84
|
+
const context = (0, _react.useContext)(_actionPopoverContext.default);
|
|
85
|
+
(0, _invariant.default)(context, "ActionPopoverItem must be used within an ActionPopover component");
|
|
86
|
+
(0, _invariant.default)( /*#__PURE__*/_react.default.isValidElement(submenu) ? submenu.type === _actionPopoverMenu.default : true, "ActionPopoverItem only accepts submenu of type `ActionPopoverMenu`");
|
|
49
87
|
const {
|
|
50
88
|
setOpenPopover,
|
|
51
89
|
isOpenPopover,
|
|
52
90
|
focusButton
|
|
53
|
-
} =
|
|
91
|
+
} = context;
|
|
54
92
|
const isHref = !!href;
|
|
55
|
-
const [containerPosition, setContainerPosition] = (0, _react.useState)(
|
|
93
|
+
const [containerPosition, setContainerPosition] = (0, _react.useState)(undefined);
|
|
56
94
|
const [guid] = (0, _react.useState)((0, _guid.default)());
|
|
57
95
|
const [isOpen, setOpen] = (0, _react.useState)(false);
|
|
58
96
|
const [focusIndex, setFocusIndex] = (0, _react.useState)(0);
|
|
59
97
|
const [isLeftAligned, setIsLeftAligned] = (0, _react.useState)(true);
|
|
60
|
-
const submenuRef = (0, _react.useRef)();
|
|
61
|
-
const ref = (0, _react.useRef)();
|
|
62
|
-
const mouseEnterTimer = (0, _react.useRef)();
|
|
63
|
-
const mouseLeaveTimer = (0, _react.useRef)();
|
|
64
|
-
const {
|
|
65
|
-
spacing
|
|
66
|
-
} = theme;
|
|
98
|
+
const submenuRef = (0, _react.useRef)(null);
|
|
99
|
+
const ref = (0, _react.useRef)(null);
|
|
100
|
+
const mouseEnterTimer = (0, _react.useRef)(null);
|
|
101
|
+
const mouseLeaveTimer = (0, _react.useRef)(null);
|
|
67
102
|
(0, _react.useEffect)(() => {
|
|
68
103
|
if (!isOpenPopover) {
|
|
69
104
|
setOpen(false);
|
|
70
105
|
}
|
|
71
106
|
}, [isOpenPopover]);
|
|
72
107
|
const alignSubmenu = (0, _react.useCallback)(() => {
|
|
73
|
-
if (checkRef(ref) && checkRef(submenuRef)) {
|
|
74
|
-
const align =
|
|
108
|
+
if (checkRef(ref) && checkRef(submenuRef) && submenu) {
|
|
109
|
+
const align = leftAlignSubmenu(ref, submenuRef);
|
|
75
110
|
setIsLeftAligned(align);
|
|
76
|
-
setContainerPosition(getContainerPosition(ref, submenuRef,
|
|
111
|
+
setContainerPosition(getContainerPosition(ref, submenuRef, placement));
|
|
77
112
|
}
|
|
78
|
-
}, [submenu,
|
|
113
|
+
}, [submenu, placement]);
|
|
79
114
|
(0, _react.useEffect)(() => {
|
|
80
115
|
alignSubmenu();
|
|
81
116
|
|
|
82
|
-
if (focusItem
|
|
83
|
-
|
|
117
|
+
if (focusItem) {
|
|
118
|
+
var _ref$current;
|
|
119
|
+
|
|
120
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
|
84
121
|
}
|
|
85
122
|
}, [alignSubmenu, focusItem]);
|
|
86
123
|
(0, _react.useEffect)(() => {
|
|
87
124
|
return function cleanup() {
|
|
88
|
-
clearTimeout(mouseEnterTimer.current);
|
|
89
|
-
clearTimeout(mouseLeaveTimer.current);
|
|
125
|
+
if (mouseEnterTimer.current) clearTimeout(mouseEnterTimer.current);
|
|
126
|
+
if (mouseLeaveTimer.current) clearTimeout(mouseLeaveTimer.current);
|
|
90
127
|
};
|
|
91
128
|
}, []);
|
|
92
129
|
(0, _react.useEffect)(() => {
|
|
@@ -104,10 +141,12 @@ const MenuItem = ({
|
|
|
104
141
|
focusButton();
|
|
105
142
|
|
|
106
143
|
if (onClickProp) {
|
|
107
|
-
onClickProp();
|
|
144
|
+
onClickProp(e);
|
|
108
145
|
}
|
|
109
146
|
} else {
|
|
110
|
-
|
|
147
|
+
var _ref$current2;
|
|
148
|
+
|
|
149
|
+
(_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
|
|
111
150
|
e.preventDefault();
|
|
112
151
|
}
|
|
113
152
|
}, [disabled, focusButton, onClickProp, setOpenPopover]);
|
|
@@ -128,8 +167,10 @@ const MenuItem = ({
|
|
|
128
167
|
setFocusIndex(0);
|
|
129
168
|
e.stopPropagation();
|
|
130
169
|
} else if (_events.default.isRightKey(e)) {
|
|
170
|
+
var _ref$current3;
|
|
171
|
+
|
|
131
172
|
setOpen(false);
|
|
132
|
-
ref.current.focus();
|
|
173
|
+
(_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.focus();
|
|
133
174
|
e.stopPropagation();
|
|
134
175
|
}
|
|
135
176
|
} else {
|
|
@@ -141,8 +182,10 @@ const MenuItem = ({
|
|
|
141
182
|
}
|
|
142
183
|
|
|
143
184
|
if (_events.default.isLeftKey(e)) {
|
|
185
|
+
var _ref$current4;
|
|
186
|
+
|
|
144
187
|
setOpen(false);
|
|
145
|
-
ref.current.focus();
|
|
188
|
+
(_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.focus();
|
|
146
189
|
e.stopPropagation();
|
|
147
190
|
}
|
|
148
191
|
}
|
|
@@ -150,7 +193,9 @@ const MenuItem = ({
|
|
|
150
193
|
e.preventDefault();
|
|
151
194
|
} else if (_events.default.isEnterKey(e)) {
|
|
152
195
|
if (isHref && download) {
|
|
153
|
-
|
|
196
|
+
var _ref$current5;
|
|
197
|
+
|
|
198
|
+
(_ref$current5 = ref.current) === null || _ref$current5 === void 0 ? void 0 : _ref$current5.click();
|
|
154
199
|
}
|
|
155
200
|
|
|
156
201
|
e.preventDefault();
|
|
@@ -162,23 +207,25 @@ const MenuItem = ({
|
|
|
162
207
|
}, [disabled, download, focusButton, isHref, isLeftAligned, onClick, setOpenPopover, submenu]);
|
|
163
208
|
const itemSubmenuProps = { ...(!disabled && {
|
|
164
209
|
onMouseEnter: e => {
|
|
165
|
-
clearTimeout(mouseEnterTimer.current);
|
|
166
|
-
setFocusIndex(
|
|
210
|
+
if (mouseEnterTimer.current) clearTimeout(mouseEnterTimer.current);
|
|
211
|
+
setFocusIndex(-1);
|
|
167
212
|
mouseEnterTimer.current = setTimeout(() => {
|
|
168
213
|
setOpen(true);
|
|
169
214
|
}, INTERVAL);
|
|
170
215
|
e.stopPropagation();
|
|
171
216
|
},
|
|
172
217
|
onMouseLeave: e => {
|
|
173
|
-
clearTimeout(mouseLeaveTimer.current);
|
|
218
|
+
if (mouseLeaveTimer.current) clearTimeout(mouseLeaveTimer.current);
|
|
174
219
|
mouseLeaveTimer.current = setTimeout(() => {
|
|
175
220
|
setOpen(false);
|
|
176
221
|
}, INTERVAL);
|
|
177
222
|
e.stopPropagation();
|
|
178
223
|
},
|
|
179
224
|
onClick: e => {
|
|
225
|
+
var _ref$current6;
|
|
226
|
+
|
|
180
227
|
setOpen(true);
|
|
181
|
-
ref.current.focus();
|
|
228
|
+
(_ref$current6 = ref.current) === null || _ref$current6 === void 0 ? void 0 : _ref$current6.focus();
|
|
182
229
|
e.preventDefault();
|
|
183
230
|
e.stopPropagation();
|
|
184
231
|
}
|
|
@@ -191,8 +238,8 @@ const MenuItem = ({
|
|
|
191
238
|
|
|
192
239
|
const renderMenuItemIcon = () => {
|
|
193
240
|
return icon && /*#__PURE__*/_react.default.createElement(_actionPopover.MenuItemIcon, {
|
|
194
|
-
|
|
195
|
-
|
|
241
|
+
as: undefined,
|
|
242
|
+
type: icon
|
|
196
243
|
});
|
|
197
244
|
};
|
|
198
245
|
|
|
@@ -201,15 +248,17 @@ const MenuItem = ({
|
|
|
201
248
|
onClick: onClick,
|
|
202
249
|
onKeyDown: onKeyDown,
|
|
203
250
|
type: "button",
|
|
204
|
-
tabIndex:
|
|
205
|
-
role: "menuitem"
|
|
251
|
+
tabIndex: 0,
|
|
252
|
+
role: "menuitem",
|
|
253
|
+
isDisabled: disabled,
|
|
254
|
+
horizontalAlignment: horizontalAlignment
|
|
206
255
|
}, disabled && {
|
|
207
256
|
"aria-disabled": true
|
|
208
257
|
}, isHref && {
|
|
209
258
|
as: "a",
|
|
210
259
|
download,
|
|
211
260
|
href
|
|
212
|
-
}, submenu && itemSubmenuProps), submenu
|
|
261
|
+
}, submenu && itemSubmenuProps), /*#__PURE__*/_react.default.isValidElement(submenu) ? /*#__PURE__*/_react.default.cloneElement(submenu, {
|
|
213
262
|
parentID: `ActionPopoverItem_${guid}`,
|
|
214
263
|
menuID: `ActionPopoverMenu_${guid}`,
|
|
215
264
|
"data-element": "action-popover-submenu",
|
|
@@ -219,94 +268,26 @@ const MenuItem = ({
|
|
|
219
268
|
setOpen,
|
|
220
269
|
setFocusIndex,
|
|
221
270
|
focusIndex
|
|
222
|
-
}), submenu && checkRef(ref) && isLeftAligned
|
|
271
|
+
}) : null, submenu && checkRef(ref) && isLeftAligned ? /*#__PURE__*/_react.default.createElement(_actionPopover.SubMenuItemIcon, {
|
|
223
272
|
type: "chevron_left"
|
|
224
|
-
}), horizontalAlignment === "left"
|
|
273
|
+
}) : null, horizontalAlignment === "left" ? renderMenuItemIcon() : null, children, horizontalAlignment === "right" ? renderMenuItemIcon() : null, submenu && checkRef(ref) && !isLeftAligned ? /*#__PURE__*/_react.default.createElement(_actionPopover.SubMenuItemIcon, {
|
|
225
274
|
type: "chevron_right"
|
|
226
|
-
}));
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
exports.MenuItem = MenuItem;
|
|
230
|
-
|
|
231
|
-
function checkRef(ref) {
|
|
232
|
-
return Boolean(ref && ref.current);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function leftAlignSubmenu(ref, submenuRef) {
|
|
236
|
-
const itemRect = ref.current.getBoundingClientRect();
|
|
237
|
-
const {
|
|
238
|
-
offsetWidth
|
|
239
|
-
} = submenuRef.current;
|
|
240
|
-
return itemRect.left >= offsetWidth;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function getContainerPosition(itemRef, submenuRef, spacing, placement) {
|
|
244
|
-
const {
|
|
245
|
-
offsetWidth: parentWidth
|
|
246
|
-
} = itemRef.current;
|
|
247
|
-
const {
|
|
248
|
-
offsetWidth: submenuWidth
|
|
249
|
-
} = submenuRef.current;
|
|
250
|
-
const xPositionValue = leftAlignSubmenu(itemRef, submenuRef) ? -submenuWidth : parentWidth;
|
|
251
|
-
const yPositionName = placement === "top" ? "bottom" : "top";
|
|
252
|
-
return {
|
|
253
|
-
left: xPositionValue,
|
|
254
|
-
[yPositionName]: -spacing,
|
|
255
|
-
right: "auto"
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const StyledActionPopoverItem = (0, _actionPopover.MenuItemFactory)(MenuItem);
|
|
260
|
-
StyledActionPopoverItem.displayName = "ActionPopoverItem";
|
|
261
|
-
const ActionPopoverItem = (0, _styledComponents.withTheme)(StyledActionPopoverItem);
|
|
262
|
-
const propTypes = {
|
|
263
|
-
/** The text label to display for this Item */
|
|
264
|
-
children: _propTypes.default.string.isRequired,
|
|
265
|
-
|
|
266
|
-
/** Flag to indicate if item is disabled */
|
|
267
|
-
disabled: _propTypes.default.bool,
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* <a href="https://brand.sage.com/d/NdbrveWvNheA/foundations#/icons/icons" target="_blank">List of supported icons</a>
|
|
271
|
-
*
|
|
272
|
-
* The name of the icon to display next to the label
|
|
273
|
-
* */
|
|
274
|
-
icon: _propTypes.default.string,
|
|
275
|
-
|
|
276
|
-
/** Callback to run when item is clicked */
|
|
277
|
-
onClick: _propTypes.default.func,
|
|
278
|
-
|
|
279
|
-
/** allows to provide download prop that works dependent with href */
|
|
280
|
-
download: _propTypes.default.bool,
|
|
281
|
-
|
|
282
|
-
/** allows to provide href prop */
|
|
283
|
-
href: _propTypes.default.string,
|
|
284
|
-
|
|
285
|
-
/** Submenu component for item */
|
|
286
|
-
submenu(props, propName, componentName) {
|
|
287
|
-
let error;
|
|
288
|
-
|
|
289
|
-
if (props[propName] && props[propName].type.displayName !== "ActionPopoverMenu") {
|
|
290
|
-
error = new Error(`\`${componentName}\` only accepts submenu of type \`ActionPopoverMenu\``);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return error;
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
/** @ignore @private */
|
|
297
|
-
placement: _propTypes.default.oneOf(["bottom", "top"]),
|
|
298
|
-
|
|
299
|
-
/** @ignore @private */
|
|
300
|
-
focusItem: _propTypes.default.bool,
|
|
301
|
-
|
|
302
|
-
/** @ignore @private */
|
|
303
|
-
horizontalAlignment: _propTypes.default.oneOf(["left", "right"])
|
|
275
|
+
}) : null);
|
|
304
276
|
};
|
|
305
|
-
ActionPopoverItem.propTypes = { ...propTypes
|
|
306
|
-
}; // needed to export MenuItem to create prop tables in storybook
|
|
307
277
|
|
|
308
|
-
|
|
278
|
+
exports.ActionPopoverItem = ActionPopoverItem;
|
|
279
|
+
ActionPopoverItem.propTypes = {
|
|
280
|
+
"children": _propTypes.default.string.isRequired,
|
|
281
|
+
"disabled": _propTypes.default.bool,
|
|
282
|
+
"download": _propTypes.default.bool,
|
|
283
|
+
"focusItem": _propTypes.default.bool,
|
|
284
|
+
"horizontalAlignment": _propTypes.default.oneOf(["left", "right"]),
|
|
285
|
+
"href": _propTypes.default.string,
|
|
286
|
+
"icon": _propTypes.default.oneOf(["add", "alert", "analysis", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_up", "attach", "bank", "basket_with_squares", "basket", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "copy", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "gift", "graph", "grid", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "ledger_arrow_left", "ledger_arrow_right", "ledger", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "messages", "minus_large", "minus", "mobile", "money_bag", "pause_circle", "pause", "pdf", "people_switch", "people", "person_info", "person_tick", "person", "phone", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "three_boxes", "tick_circle", "tick", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
287
|
+
"onClick": _propTypes.default.func,
|
|
288
|
+
"placement": _propTypes.default.oneOf(["bottom", "top"]),
|
|
289
|
+
"submenu": _propTypes.default.node
|
|
309
290
|
};
|
|
310
|
-
|
|
291
|
+
ActionPopoverItem.displayName = "ActionPopoverItem";
|
|
311
292
|
var _default = ActionPopoverItem;
|
|
312
293
|
exports.default = _default;
|
package/lib/components/action-popover/action-popover-menu/action-popover-menu.component.d.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
export default ActionPopoverMenu;
|
|
2
|
-
declare const ActionPopoverMenu: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
3
1
|
import React from "react";
|
|
2
|
+
export interface ActionPopoverMenuBaseProps {
|
|
3
|
+
/** Children for the menu */
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
/** Index to control which item is focused */
|
|
6
|
+
focusIndex?: number;
|
|
7
|
+
/** Flag to indicate whether a menu should open */
|
|
8
|
+
isOpen?: boolean;
|
|
9
|
+
/** A unique ID for the menu */
|
|
10
|
+
menuID?: string;
|
|
11
|
+
/** Callback to set the index of the focused item */
|
|
12
|
+
setFocusIndex?: (args: number) => void;
|
|
13
|
+
/** Callback to set the isOpen flag */
|
|
14
|
+
setOpen?: (args: boolean) => void;
|
|
15
|
+
/** Unique ID for the menu's parent */
|
|
16
|
+
parentID?: string;
|
|
17
|
+
/** Horizontal alignment of menu items content */
|
|
18
|
+
horizontalAlignment?: "left" | "right";
|
|
19
|
+
/** Set whether the menu should open above or below the button */
|
|
20
|
+
placement?: "bottom" | "top";
|
|
21
|
+
/** @ignore @private */
|
|
22
|
+
role?: string;
|
|
23
|
+
/** @ignore @private */
|
|
24
|
+
"data-element"?: string;
|
|
25
|
+
/** @ignore @private */
|
|
26
|
+
style?: {
|
|
27
|
+
left: number;
|
|
28
|
+
top?: string;
|
|
29
|
+
bottom?: string;
|
|
30
|
+
right: "auto";
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface ActionPopoverMenuProps extends ActionPopoverMenuBaseProps, React.RefAttributes<HTMLDivElement> {
|
|
34
|
+
}
|
|
35
|
+
declare const ActionPopoverMenu: React.ForwardRefExoticComponent<ActionPopoverMenuBaseProps & React.RefAttributes<HTMLDivElement>>;
|
|
36
|
+
export default ActionPopoverMenu;
|
|
@@ -9,6 +9,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
13
|
+
|
|
12
14
|
var _actionPopover = require("../action-popover.style");
|
|
13
15
|
|
|
14
16
|
var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events"));
|
|
@@ -28,22 +30,40 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
28
30
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
29
31
|
|
|
30
32
|
const ActionPopoverMenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
31
|
-
parentID,
|
|
32
33
|
children,
|
|
34
|
+
parentID,
|
|
33
35
|
focusIndex,
|
|
34
36
|
isOpen,
|
|
35
37
|
menuID,
|
|
36
|
-
onClick,
|
|
37
38
|
setOpen,
|
|
38
39
|
setFocusIndex,
|
|
39
40
|
placement = "bottom",
|
|
40
41
|
horizontalAlignment,
|
|
41
42
|
...rest
|
|
42
43
|
}, ref) => {
|
|
44
|
+
const context = (0, _react.useContext)(_actionPopoverContext.default);
|
|
45
|
+
(0, _invariant.default)(context, "ActionPopoverMenu must be used within an ActionPopover component");
|
|
43
46
|
const {
|
|
44
47
|
focusButton
|
|
45
|
-
} =
|
|
46
|
-
|
|
48
|
+
} = context;
|
|
49
|
+
(0, _invariant.default)(setOpen && setFocusIndex && typeof focusIndex !== "undefined", "ActionPopoverMenu must be used within an ActionPopover or ActionPopoverItem component");
|
|
50
|
+
const hasProperChildren = (0, _react.useMemo)(() => {
|
|
51
|
+
const incorrectChild = _react.default.Children.toArray(children).find(child => {
|
|
52
|
+
if (! /*#__PURE__*/_react.default.isValidElement(child)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return child.type !== _actionPopoverItem.default && child.type !== _actionPopoverDivider.default;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return !incorrectChild;
|
|
60
|
+
}, [children]);
|
|
61
|
+
(0, _invariant.default)(hasProperChildren, `ActionPopoverMenu only accepts children of type \`${_actionPopoverItem.default.displayName}\`` + ` and \`${_actionPopoverDivider.default.displayName}\`.`);
|
|
62
|
+
const items = (0, _react.useMemo)(() => {
|
|
63
|
+
return _react.default.Children.toArray(children).filter(child => {
|
|
64
|
+
return /*#__PURE__*/_react.default.isValidElement(child) && child.type === _actionPopoverItem.default;
|
|
65
|
+
});
|
|
66
|
+
}, [children]);
|
|
47
67
|
const onKeyDown = (0, _react.useCallback)(e => {
|
|
48
68
|
if (_events.default.isTabKey(e)) {
|
|
49
69
|
e.preventDefault(); // TAB: close menu and allow focus to change to next focusable element
|
|
@@ -79,12 +99,8 @@ const ActionPopoverMenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
79
99
|
let firstMatch;
|
|
80
100
|
let nextMatch;
|
|
81
101
|
|
|
82
|
-
_react.default.Children.forEach(items, ({
|
|
83
|
-
props
|
|
84
|
-
children: text
|
|
85
|
-
}
|
|
86
|
-
}, index) => {
|
|
87
|
-
if (text && text.toLowerCase().startsWith(e.key.toLowerCase())) {
|
|
102
|
+
_react.default.Children.forEach(items, (child, index) => {
|
|
103
|
+
if ( /*#__PURE__*/_react.default.isValidElement(child) && child.props.children.toLowerCase().startsWith(e.key.toLowerCase())) {
|
|
88
104
|
if (firstMatch === undefined) {
|
|
89
105
|
firstMatch = index;
|
|
90
106
|
}
|
|
@@ -105,7 +121,7 @@ const ActionPopoverMenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
105
121
|
const clonedChildren = (0, _react.useMemo)(() => {
|
|
106
122
|
let index = 0;
|
|
107
123
|
return _react.default.Children.map(children, child => {
|
|
108
|
-
if (child && child.type === _actionPopoverItem.default) {
|
|
124
|
+
if ( /*#__PURE__*/_react.default.isValidElement(child) && child.type === _actionPopoverItem.default) {
|
|
109
125
|
index += 1;
|
|
110
126
|
return /*#__PURE__*/_react.default.cloneElement(child, {
|
|
111
127
|
focusItem: isOpen && focusIndex === index - 1,
|
|
@@ -129,50 +145,23 @@ const ActionPopoverMenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
129
145
|
});
|
|
130
146
|
|
|
131
147
|
ActionPopoverMenu.propTypes = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return error;
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
/** Index to control which item is focused */
|
|
154
|
-
focusIndex: _propTypes.default.number,
|
|
155
|
-
|
|
156
|
-
/** A unique ID for the menu */
|
|
157
|
-
menuID: _propTypes.default.string,
|
|
158
|
-
|
|
159
|
-
/** Flag to indicate whether a menu should open */
|
|
160
|
-
isOpen: _propTypes.default.bool,
|
|
161
|
-
|
|
162
|
-
/** Callback to set the index of the focused item */
|
|
163
|
-
setFocusIndex: _propTypes.default.func,
|
|
164
|
-
|
|
165
|
-
/** Callback to set the isOpen flag */
|
|
166
|
-
setOpen: _propTypes.default.func,
|
|
167
|
-
|
|
168
|
-
/** Callback called on click event */
|
|
169
|
-
onClick: _propTypes.default.func,
|
|
170
|
-
|
|
171
|
-
/** @ignore @private */
|
|
172
|
-
placement: _propTypes.default.oneOf(["bottom", "top"]),
|
|
173
|
-
|
|
174
|
-
/** @ignore @private */
|
|
175
|
-
horizontalAlignment: _propTypes.default.oneOf(["left", "right"])
|
|
148
|
+
"children": _propTypes.default.node,
|
|
149
|
+
"data-element": _propTypes.default.string,
|
|
150
|
+
"focusIndex": _propTypes.default.number,
|
|
151
|
+
"horizontalAlignment": _propTypes.default.oneOf(["left", "right"]),
|
|
152
|
+
"isOpen": _propTypes.default.bool,
|
|
153
|
+
"menuID": _propTypes.default.string,
|
|
154
|
+
"parentID": _propTypes.default.string,
|
|
155
|
+
"placement": _propTypes.default.oneOf(["bottom", "top"]),
|
|
156
|
+
"role": _propTypes.default.string,
|
|
157
|
+
"setFocusIndex": _propTypes.default.func,
|
|
158
|
+
"setOpen": _propTypes.default.func,
|
|
159
|
+
"style": _propTypes.default.shape({
|
|
160
|
+
"bottom": _propTypes.default.string,
|
|
161
|
+
"left": _propTypes.default.number.isRequired,
|
|
162
|
+
"right": _propTypes.default.oneOf(["auto"]).isRequired,
|
|
163
|
+
"top": _propTypes.default.string
|
|
164
|
+
})
|
|
176
165
|
};
|
|
177
166
|
ActionPopoverMenu.displayName = "ActionPopoverMenu";
|
|
178
167
|
var _default = ActionPopoverMenu;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ButtonTypes } from "../../button/button.component";
|
|
3
|
+
import { IconType } from "../../icon";
|
|
4
|
+
export declare type ActionPopoverMenuButtonAria = {
|
|
5
|
+
"aria-haspopup": string;
|
|
6
|
+
"aria-label": string;
|
|
7
|
+
"aria-controls": string;
|
|
8
|
+
"aria-expanded": string;
|
|
9
|
+
};
|
|
10
|
+
export interface ActionPopoverMenuButtonProps {
|
|
11
|
+
children?: string;
|
|
12
|
+
buttonType?: ButtonTypes;
|
|
13
|
+
iconType?: IconType;
|
|
14
|
+
iconPosition?: "after" | "before";
|
|
15
|
+
size?: "small" | "medium" | "large";
|
|
16
|
+
tabIndex: number;
|
|
17
|
+
ariaAttributes: ActionPopoverMenuButtonAria;
|
|
18
|
+
"data-element": string;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
declare const ActionPopoverMenuButton: ({ buttonType, iconType, iconPosition, size, children, ...props }: ActionPopoverMenuButtonProps) => JSX.Element;
|
|
21
|
+
export default ActionPopoverMenuButton;
|
|
@@ -32,11 +32,19 @@ const ActionPopoverMenuButton = ({
|
|
|
32
32
|
}, props), children));
|
|
33
33
|
|
|
34
34
|
ActionPopoverMenuButton.propTypes = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
"ariaAttributes": _propTypes.default.shape({
|
|
36
|
+
"aria-controls": _propTypes.default.string.isRequired,
|
|
37
|
+
"aria-expanded": _propTypes.default.string.isRequired,
|
|
38
|
+
"aria-haspopup": _propTypes.default.string.isRequired,
|
|
39
|
+
"aria-label": _propTypes.default.string.isRequired
|
|
40
|
+
}).isRequired,
|
|
41
|
+
"buttonType": _propTypes.default.oneOf(["darkBackground", "dashed", "primary", "secondary", "tertiary"]),
|
|
42
|
+
"children": _propTypes.default.string,
|
|
43
|
+
"data-element": _propTypes.default.string.isRequired,
|
|
44
|
+
"iconPosition": _propTypes.default.oneOf(["after", "before"]),
|
|
45
|
+
"iconType": _propTypes.default.oneOf(["add", "alert", "analysis", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_up", "attach", "bank", "basket_with_squares", "basket", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "copy", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "gift", "graph", "grid", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "ledger_arrow_left", "ledger_arrow_right", "ledger", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "messages", "minus_large", "minus", "mobile", "money_bag", "pause_circle", "pause", "pdf", "people_switch", "people", "person_info", "person_tick", "person", "phone", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "three_boxes", "tick_circle", "tick", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
46
|
+
"size": _propTypes.default.oneOf(["large", "medium", "small"]),
|
|
47
|
+
"tabIndex": _propTypes.default.number.isRequired
|
|
40
48
|
};
|
|
41
49
|
var _default = ActionPopoverMenuButton;
|
|
42
50
|
exports.default = _default;
|