@carbon/react 1.23.0 → 1.23.1
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/es/components/Dropdown/Dropdown.Skeleton.d.ts +15 -0
- package/es/components/Dropdown/Dropdown.Skeleton.js +1 -2
- package/es/components/Dropdown/index.js +1 -0
- package/es/components/FluidDropdown/FluidDropdown.js +1 -0
- package/es/components/Heading/index.js +11 -4
- package/es/components/Menu/Menu.js +164 -216
- package/es/components/Menu/MenuContext.js +44 -0
- package/es/components/Menu/MenuItem.js +401 -23
- package/es/components/MultiSelect/MultiSelect.js +6 -0
- package/es/components/OverflowMenu/OverflowMenu.js +2 -2
- package/es/components/OverflowMenuV2/index.js +4 -14
- package/es/components/Search/Search.js +3 -3
- package/es/index.d.ts +1 -1
- package/es/index.js +2 -6
- package/es/prop-types/isRequiredOneOf.js +2 -2
- package/lib/components/Dropdown/Dropdown.Skeleton.d.ts +15 -0
- package/lib/components/Dropdown/Dropdown.Skeleton.js +1 -2
- package/lib/components/Dropdown/index.js +2 -0
- package/lib/components/FluidDropdown/FluidDropdown.js +1 -0
- package/lib/components/Heading/index.js +11 -4
- package/lib/components/Menu/Menu.js +163 -216
- package/lib/components/Menu/MenuContext.js +53 -0
- package/lib/components/Menu/MenuItem.js +406 -23
- package/lib/components/MultiSelect/MultiSelect.js +6 -0
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
- package/lib/components/OverflowMenuV2/index.js +5 -15
- package/lib/components/Search/Search.js +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7 -11
- package/lib/prop-types/isRequiredOneOf.js +2 -2
- package/package.json +4 -4
- package/es/components/Menu/MenuDivider.js +0 -19
- package/es/components/Menu/MenuGroup.js +0 -34
- package/es/components/Menu/MenuOption.js +0 -250
- package/es/components/Menu/MenuRadioGroup.js +0 -50
- package/es/components/Menu/MenuRadioGroupOptions.js +0 -64
- package/es/components/Menu/MenuSelectableItem.js +0 -57
- package/es/components/Menu/_utils.js +0 -177
- package/es/components/Menu/index.js +0 -25
- package/lib/components/Menu/MenuDivider.js +0 -27
- package/lib/components/Menu/MenuGroup.js +0 -43
- package/lib/components/Menu/MenuOption.js +0 -260
- package/lib/components/Menu/MenuRadioGroup.js +0 -59
- package/lib/components/Menu/MenuRadioGroupOptions.js +0 -73
- package/lib/components/Menu/MenuSelectableItem.js +0 -66
- package/lib/components/Menu/_utils.js +0 -191
- package/lib/components/Menu/index.js +0 -31
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React__default from 'react';
|
|
9
|
-
import { usePrefix } from '../../internal/usePrefix.js';
|
|
10
|
-
|
|
11
|
-
function MenuDivider() {
|
|
12
|
-
var prefix = usePrefix();
|
|
13
|
-
return /*#__PURE__*/React__default.createElement("li", {
|
|
14
|
-
role: "separator",
|
|
15
|
-
className: "".concat(prefix, "--menu-divider")
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { MenuDivider as default };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React__default from 'react';
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
|
|
11
|
-
function MenuGroup(_ref) {
|
|
12
|
-
var label = _ref.label,
|
|
13
|
-
children = _ref.children;
|
|
14
|
-
return /*#__PURE__*/React__default.createElement("li", {
|
|
15
|
-
role: "none"
|
|
16
|
-
}, /*#__PURE__*/React__default.createElement("ul", {
|
|
17
|
-
role: "group",
|
|
18
|
-
"aria-label": label
|
|
19
|
-
}, children));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
MenuGroup.propTypes = {
|
|
23
|
-
/**
|
|
24
|
-
* Specify the children of the MenuGroup
|
|
25
|
-
*/
|
|
26
|
-
children: PropTypes.node,
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Rendered label for the MenuGroup
|
|
30
|
-
*/
|
|
31
|
-
label: PropTypes.node.isRequired
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export { MenuGroup as default };
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useState, useRef, useEffect } from 'react';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
|
-
import cx from 'classnames';
|
|
12
|
-
import { CaretRight } from '@carbon/icons-react';
|
|
13
|
-
import { usePrefix } from '../../internal/usePrefix.js';
|
|
14
|
-
import { getFirstSubNode, focusNode, clickedElementHasSubnodes, getParentMenu } from './_utils.js';
|
|
15
|
-
import Menu from './Menu.js';
|
|
16
|
-
import { match } from '../../internal/keyboard/match.js';
|
|
17
|
-
import { ArrowRight, Enter, Space } from '../../internal/keyboard/keys.js';
|
|
18
|
-
|
|
19
|
-
var _CaretRight;
|
|
20
|
-
|
|
21
|
-
var _excluded = ["children", "disabled", "indented", "kind", "label", "level", "onClick", "renderIcon", "shortcut"];
|
|
22
|
-
var hoverIntentDelay = 150; // in ms
|
|
23
|
-
|
|
24
|
-
function MenuOptionContent(_ref) {
|
|
25
|
-
var label = _ref.label,
|
|
26
|
-
info = _ref.info,
|
|
27
|
-
disabled = _ref.disabled,
|
|
28
|
-
Icon = _ref.icon,
|
|
29
|
-
indented = _ref.indented;
|
|
30
|
-
var prefix = usePrefix();
|
|
31
|
-
var classes = cx("".concat(prefix, "--menu-option__content"), _defineProperty({}, "".concat(prefix, "--menu-option__content--disabled"), disabled));
|
|
32
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
33
|
-
className: classes
|
|
34
|
-
}, indented && /*#__PURE__*/React__default.createElement("div", {
|
|
35
|
-
className: "".concat(prefix, "--menu-option__icon")
|
|
36
|
-
}, Icon && /*#__PURE__*/React__default.createElement(Icon, null)), /*#__PURE__*/React__default.createElement("span", {
|
|
37
|
-
className: "".concat(prefix, "--menu-option__label"),
|
|
38
|
-
title: label
|
|
39
|
-
}, label), /*#__PURE__*/React__default.createElement("div", {
|
|
40
|
-
className: "".concat(prefix, "--menu-option__info")
|
|
41
|
-
}, info));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function MenuOption(_ref2) {
|
|
45
|
-
var _classnames2;
|
|
46
|
-
|
|
47
|
-
var children = _ref2.children,
|
|
48
|
-
disabled = _ref2.disabled,
|
|
49
|
-
indented = _ref2.indented,
|
|
50
|
-
_ref2$kind = _ref2.kind,
|
|
51
|
-
kind = _ref2$kind === void 0 ? 'default' : _ref2$kind,
|
|
52
|
-
label = _ref2.label,
|
|
53
|
-
level = _ref2.level,
|
|
54
|
-
_ref2$onClick = _ref2.onClick,
|
|
55
|
-
onClick = _ref2$onClick === void 0 ? function () {} : _ref2$onClick,
|
|
56
|
-
renderIcon = _ref2.renderIcon,
|
|
57
|
-
shortcut = _ref2.shortcut,
|
|
58
|
-
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
59
|
-
|
|
60
|
-
var _useState = useState(false),
|
|
61
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
-
submenuOpen = _useState2[0],
|
|
63
|
-
setSubmenuOpen = _useState2[1];
|
|
64
|
-
|
|
65
|
-
var _useState3 = useState(false),
|
|
66
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
67
|
-
submenuOpenedByKeyboard = _useState4[0],
|
|
68
|
-
setSubmenuOpenedByKeyboard = _useState4[1];
|
|
69
|
-
|
|
70
|
-
var rootRef = useRef(null);
|
|
71
|
-
var hoverIntentTimeout = useRef(null);
|
|
72
|
-
var prefix = usePrefix();
|
|
73
|
-
var subOptions = React__default.Children.map(children, function (node) {
|
|
74
|
-
if ( /*#__PURE__*/React__default.isValidElement(node)) {
|
|
75
|
-
return /*#__PURE__*/React__default.cloneElement(node);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
function openSubmenu() {
|
|
80
|
-
var openedByKeyboard = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
81
|
-
setSubmenuOpenedByKeyboard(openedByKeyboard);
|
|
82
|
-
setSubmenuOpen(true);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function handleKeyDown(event) {
|
|
86
|
-
if (clickedElementHasSubnodes(event) && (match(event, ArrowRight) || match(event, Enter) || match(event, Space))) {
|
|
87
|
-
openSubmenu(true);
|
|
88
|
-
} else if ((match(event, Enter) || match(event, Space)) && onClick) {
|
|
89
|
-
onClick(event);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function handleMouseEnter() {
|
|
94
|
-
hoverIntentTimeout.current = setTimeout(openSubmenu, hoverIntentDelay);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function handleMouseLeave() {
|
|
98
|
-
clearTimeout(hoverIntentTimeout === null || hoverIntentTimeout === void 0 ? void 0 : hoverIntentTimeout.current);
|
|
99
|
-
setSubmenuOpen(false);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getSubmenuPosition() {
|
|
103
|
-
var pos = [0, 0];
|
|
104
|
-
|
|
105
|
-
if (subOptions) {
|
|
106
|
-
var parentMenu = getParentMenu(rootRef === null || rootRef === void 0 ? void 0 : rootRef.current);
|
|
107
|
-
|
|
108
|
-
if (parentMenu) {
|
|
109
|
-
var _parentMenu$getBoundi = parentMenu.getBoundingClientRect(),
|
|
110
|
-
x = _parentMenu$getBoundi.x,
|
|
111
|
-
width = _parentMenu$getBoundi.width;
|
|
112
|
-
|
|
113
|
-
var _rootRef$current$getB = rootRef.current.getBoundingClientRect(),
|
|
114
|
-
y = _rootRef$current$getB.y;
|
|
115
|
-
|
|
116
|
-
pos[0] = x + width;
|
|
117
|
-
pos[1] = y;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return pos;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
useEffect(function () {
|
|
125
|
-
if (subOptions && submenuOpenedByKeyboard) {
|
|
126
|
-
var firstSubnode = getFirstSubNode(rootRef === null || rootRef === void 0 ? void 0 : rootRef.current);
|
|
127
|
-
focusNode(firstSubnode);
|
|
128
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
129
|
-
|
|
130
|
-
}, [submenuOpen]);
|
|
131
|
-
var classes = cx("".concat(prefix, "--menu-option"), (_classnames2 = {}, _defineProperty(_classnames2, "".concat(prefix, "--menu-option--disabled"), disabled), _defineProperty(_classnames2, "".concat(prefix, "--menu-option--active"), subOptions && submenuOpen), _defineProperty(_classnames2, "".concat(prefix, "--menu-option--danger"), !subOptions && kind === 'danger'), _classnames2));
|
|
132
|
-
var allowedRoles = ['menuitemradio', 'menuitemcheckbox'];
|
|
133
|
-
var role = rest.role && allowedRoles.includes(rest.role) ? rest.role : 'menuitem';
|
|
134
|
-
var submenuPosition = getSubmenuPosition();
|
|
135
|
-
return (
|
|
136
|
-
/*#__PURE__*/
|
|
137
|
-
// role is either menuitemradio, menuitemcheckbox, or menuitem which are all interactive
|
|
138
|
-
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
139
|
-
React__default.createElement("li", _extends({}, rest, {
|
|
140
|
-
ref: rootRef,
|
|
141
|
-
className: classes,
|
|
142
|
-
role: role,
|
|
143
|
-
tabIndex: -1,
|
|
144
|
-
"aria-disabled": !subOptions && disabled,
|
|
145
|
-
"aria-haspopup": subOptions ? true : null,
|
|
146
|
-
"aria-expanded": subOptions ? submenuOpen : null,
|
|
147
|
-
onKeyDown: handleKeyDown,
|
|
148
|
-
onMouseEnter: subOptions ? handleMouseEnter : null,
|
|
149
|
-
onMouseLeave: subOptions ? handleMouseLeave : null,
|
|
150
|
-
onClick: onClick
|
|
151
|
-
}), subOptions ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(MenuOptionContent, {
|
|
152
|
-
label: label,
|
|
153
|
-
icon: renderIcon,
|
|
154
|
-
info: _CaretRight || (_CaretRight = /*#__PURE__*/React__default.createElement(CaretRight, null)),
|
|
155
|
-
indented: indented
|
|
156
|
-
}), /*#__PURE__*/React__default.createElement(Menu, {
|
|
157
|
-
level: level + 1,
|
|
158
|
-
open: submenuOpen,
|
|
159
|
-
onClose: function onClose() {
|
|
160
|
-
setSubmenuOpen(false);
|
|
161
|
-
},
|
|
162
|
-
x: submenuPosition[0],
|
|
163
|
-
y: submenuPosition[1]
|
|
164
|
-
}, subOptions)) : /*#__PURE__*/React__default.createElement(MenuOptionContent, {
|
|
165
|
-
label: label,
|
|
166
|
-
disabled: disabled,
|
|
167
|
-
icon: renderIcon,
|
|
168
|
-
info: shortcut,
|
|
169
|
-
indented: indented
|
|
170
|
-
}))
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
MenuOptionContent.propTypes = {
|
|
175
|
-
/**
|
|
176
|
-
* Whether this option is disabled
|
|
177
|
-
*/
|
|
178
|
-
disabled: PropTypes.bool,
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Icon that is displayed in front of the option
|
|
182
|
-
*/
|
|
183
|
-
icon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Whether the content should be indented
|
|
187
|
-
*/
|
|
188
|
-
indented: PropTypes.bool,
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Additional information such as shortcut or caret
|
|
192
|
-
*/
|
|
193
|
-
info: PropTypes.node,
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Rendered label for the MenuOptionContent
|
|
197
|
-
*/
|
|
198
|
-
label: PropTypes.node.isRequired
|
|
199
|
-
};
|
|
200
|
-
MenuOption.propTypes = {
|
|
201
|
-
/**
|
|
202
|
-
* Specify the children of the MenuOption
|
|
203
|
-
*/
|
|
204
|
-
children: PropTypes.node,
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Specify whether this MenuOption is disabled
|
|
208
|
-
*/
|
|
209
|
-
disabled: PropTypes.bool,
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Whether the content should be indented (for example because it's in a group with options that have icons).
|
|
213
|
-
* Is automatically set by Menu
|
|
214
|
-
*/
|
|
215
|
-
indented: PropTypes.bool,
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Optional prop to specify the kind of the MenuOption
|
|
219
|
-
*/
|
|
220
|
-
kind: PropTypes.oneOf(['default', 'danger']),
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Rendered label for the MenuOption
|
|
224
|
-
*/
|
|
225
|
-
label: PropTypes.node.isRequired,
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Which nested level this option is located in.
|
|
229
|
-
* Is automatically set by Menu
|
|
230
|
-
*/
|
|
231
|
-
level: PropTypes.number,
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* The onClick handler
|
|
235
|
-
*/
|
|
236
|
-
onClick: PropTypes.func,
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Rendered icon for the MenuOption.
|
|
240
|
-
* Can be a React component class
|
|
241
|
-
*/
|
|
242
|
-
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Rendered shortcut for the MenuOption
|
|
246
|
-
*/
|
|
247
|
-
shortcut: PropTypes.node
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
export { MenuOption as default };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React__default from 'react';
|
|
9
|
-
import PropTypes from 'prop-types';
|
|
10
|
-
import MenuGroup from './MenuGroup.js';
|
|
11
|
-
import MenuRadioGroupOptions from './MenuRadioGroupOptions.js';
|
|
12
|
-
|
|
13
|
-
function MenuRadioGroup(_ref) {
|
|
14
|
-
var items = _ref.items,
|
|
15
|
-
initialSelectedItem = _ref.initialSelectedItem,
|
|
16
|
-
label = _ref.label,
|
|
17
|
-
_ref$onChange = _ref.onChange,
|
|
18
|
-
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
19
|
-
return /*#__PURE__*/React__default.createElement(MenuGroup, {
|
|
20
|
-
label: label
|
|
21
|
-
}, /*#__PURE__*/React__default.createElement(MenuRadioGroupOptions, {
|
|
22
|
-
items: items,
|
|
23
|
-
initialSelectedItem: initialSelectedItem,
|
|
24
|
-
onChange: onChange
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
MenuRadioGroup.propTypes = {
|
|
29
|
-
/**
|
|
30
|
-
* Whether the option should be checked by default
|
|
31
|
-
*/
|
|
32
|
-
initialSelectedItem: PropTypes.string,
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Array of the radio options
|
|
36
|
-
*/
|
|
37
|
-
items: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The radio group label
|
|
41
|
-
*/
|
|
42
|
-
label: PropTypes.string.isRequired,
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Callback function when selection the has been changed
|
|
46
|
-
*/
|
|
47
|
-
onChange: PropTypes.func
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { MenuRadioGroup as default };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useState } from 'react';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
|
-
import { Checkmark } from '@carbon/icons-react';
|
|
12
|
-
import MenuOption from './MenuOption.js';
|
|
13
|
-
|
|
14
|
-
function MenuRadioGroupOptions(_ref) {
|
|
15
|
-
var items = _ref.items,
|
|
16
|
-
initialSelectedItem = _ref.initialSelectedItem,
|
|
17
|
-
_ref$onChange = _ref.onChange,
|
|
18
|
-
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
19
|
-
|
|
20
|
-
var _useState = useState(initialSelectedItem),
|
|
21
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
-
selected = _useState2[0],
|
|
23
|
-
setSelected = _useState2[1];
|
|
24
|
-
|
|
25
|
-
function handleClick(option) {
|
|
26
|
-
setSelected(option);
|
|
27
|
-
onChange(option);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var options = items.map(function (option, i) {
|
|
31
|
-
var isSelected = selected === option;
|
|
32
|
-
return /*#__PURE__*/React__default.createElement(MenuOption, {
|
|
33
|
-
key: i,
|
|
34
|
-
role: "menuitemradio",
|
|
35
|
-
"aria-checked": isSelected,
|
|
36
|
-
renderIcon: isSelected ? Checkmark : null,
|
|
37
|
-
label: option,
|
|
38
|
-
indented: true,
|
|
39
|
-
onClick: function onClick() {
|
|
40
|
-
handleClick(option);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
return options;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
MenuRadioGroupOptions.propTypes = {
|
|
48
|
-
/**
|
|
49
|
-
* Whether the option should be checked by default
|
|
50
|
-
*/
|
|
51
|
-
initialSelectedItem: PropTypes.string,
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Array of the radio options
|
|
55
|
-
*/
|
|
56
|
-
items: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Callback function when selection the has been changed
|
|
60
|
-
*/
|
|
61
|
-
onChange: PropTypes.func
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export { MenuRadioGroupOptions as default };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useState } from 'react';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
|
-
import { Checkmark } from '@carbon/icons-react';
|
|
12
|
-
import MenuOption from './MenuOption.js';
|
|
13
|
-
|
|
14
|
-
function MenuSelectableItem(_ref) {
|
|
15
|
-
var label = _ref.label,
|
|
16
|
-
initialChecked = _ref.initialChecked,
|
|
17
|
-
_ref$onChange = _ref.onChange,
|
|
18
|
-
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
19
|
-
|
|
20
|
-
var _useState = useState(initialChecked),
|
|
21
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
-
checked = _useState2[0],
|
|
23
|
-
setChecked = _useState2[1];
|
|
24
|
-
|
|
25
|
-
function handleClick() {
|
|
26
|
-
setChecked(!checked);
|
|
27
|
-
onChange(!checked);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return /*#__PURE__*/React__default.createElement(MenuOption, {
|
|
31
|
-
role: "menuitemcheckbox",
|
|
32
|
-
"aria-checked": checked,
|
|
33
|
-
renderIcon: checked ? Checkmark : null,
|
|
34
|
-
label: label,
|
|
35
|
-
indented: true,
|
|
36
|
-
onClick: handleClick
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
MenuSelectableItem.propTypes = {
|
|
41
|
-
/**
|
|
42
|
-
* Whether the option should be checked by default
|
|
43
|
-
*/
|
|
44
|
-
initialChecked: PropTypes.bool,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Rendered label for the MenuOptionContent
|
|
48
|
-
*/
|
|
49
|
-
label: PropTypes.node.isRequired,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Callback function when selection the has been changed
|
|
53
|
-
*/
|
|
54
|
-
onChange: PropTypes.func
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export { MenuSelectableItem as default };
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
var prefix = 'cds';
|
|
9
|
-
function resetFocus(el) {
|
|
10
|
-
if (el) {
|
|
11
|
-
var _el$querySelectorAll;
|
|
12
|
-
|
|
13
|
-
Array.from((_el$querySelectorAll = el.querySelectorAll('[tabindex="0"]')) !== null && _el$querySelectorAll !== void 0 ? _el$querySelectorAll : []).forEach(function (node) {
|
|
14
|
-
node.tabIndex = -1;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function focusNode(node) {
|
|
19
|
-
if (node) {
|
|
20
|
-
node.tabIndex = 0;
|
|
21
|
-
node.focus();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function getValidNodes(list) {
|
|
25
|
-
var level = list.dataset.level;
|
|
26
|
-
var nodes = [];
|
|
27
|
-
|
|
28
|
-
if (level) {
|
|
29
|
-
var submenus = Array.from(list.querySelectorAll('[data-level]'));
|
|
30
|
-
nodes = Array.from(list.querySelectorAll("li.".concat(prefix, "--menu-option"))).filter(function (child) {
|
|
31
|
-
return !submenus.some(function (submenu) {
|
|
32
|
-
return submenu.contains(child);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return nodes.filter(function (node) {
|
|
38
|
-
return node.matches(":not(.".concat(prefix, "--menu-option--disabled)"));
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function getNextNode(current, direction) {
|
|
42
|
-
var menu = getParentMenu(current);
|
|
43
|
-
var nodes = getValidNodes(menu);
|
|
44
|
-
var currentIndex = nodes.indexOf(current);
|
|
45
|
-
var nextNode = nodes[currentIndex + direction];
|
|
46
|
-
return nextNode || null;
|
|
47
|
-
}
|
|
48
|
-
function getFirstSubNode(node) {
|
|
49
|
-
var submenu = node.querySelector("ul.".concat(prefix, "--menu"));
|
|
50
|
-
|
|
51
|
-
if (submenu) {
|
|
52
|
-
var subnodes = getValidNodes(submenu);
|
|
53
|
-
return subnodes[0] || null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
function getParentNode(node) {
|
|
59
|
-
if (node) {
|
|
60
|
-
var parentNode = node.parentNode.closest("li.".concat(prefix, "--menu-option"));
|
|
61
|
-
return parentNode || null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
function getSubMenuOffset(node) {
|
|
67
|
-
if (node) {
|
|
68
|
-
var nodeStyles = getComputedStyle(node);
|
|
69
|
-
var spacings = parseInt(nodeStyles.paddingTop) + parseInt(nodeStyles.paddingBottom); // styles always in px, convert to number
|
|
70
|
-
|
|
71
|
-
var elementHeight = node.firstElementChild.offsetHeight;
|
|
72
|
-
return elementHeight + spacings || 0;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
|
77
|
-
function getParentMenu(el) {
|
|
78
|
-
if (el) {
|
|
79
|
-
var parentMenu = el.parentNode.closest("ul.".concat(prefix, "--menu"));
|
|
80
|
-
return parentMenu || null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
function clickedElementHasSubnodes(e) {
|
|
86
|
-
if (e) {
|
|
87
|
-
var closestFocusableElement = e.target.closest('[tabindex]');
|
|
88
|
-
|
|
89
|
-
if ((closestFocusableElement === null || closestFocusableElement === void 0 ? void 0 : closestFocusableElement.tagName) === 'LI') {
|
|
90
|
-
return getFirstSubNode(closestFocusableElement) !== null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* @param {number} [value] The value to cap
|
|
98
|
-
* @param {number} [min] The minimum of the range
|
|
99
|
-
* @param {number} [max] The maximum of the range
|
|
100
|
-
* @returns {number} Whether or not the element fits inside the boundaries on the given axis
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
function capWithinRange(value, min, max) {
|
|
104
|
-
if (value > max) {
|
|
105
|
-
return max;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (value < min) {
|
|
109
|
-
return min;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return value;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* @param {number[]} [elementDimensions] The dimensions of the element: [width, height]
|
|
116
|
-
* @param {number[]} [position] The desired position of the element: [x, y]
|
|
117
|
-
* @param {number[]} [boundaries] The boundaries of the container the element should be contained in: [minX, minY, maxX, maxY]
|
|
118
|
-
* @param {string} [axis="x"] Which axis to check. Either "x" or "y"
|
|
119
|
-
* @returns {boolean} Whether or not the element fits inside the boundaries on the given axis
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
function elementFits(elementDimensions, position, boundaries) {
|
|
123
|
-
var axis = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'x';
|
|
124
|
-
var index = axis === 'y' ? 1 : 0;
|
|
125
|
-
var min = boundaries[index];
|
|
126
|
-
var max = boundaries[index + 2];
|
|
127
|
-
var start = position[index];
|
|
128
|
-
var end = position[index] + elementDimensions[index];
|
|
129
|
-
return start >= min && end <= max;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* @param {number[]} [elementDimensions] The dimensions of the element: [width, height]
|
|
133
|
-
* @param {number[]} [targetBoundaries] The boundaries of the target the element should attach to: [minX, minY, maxX, maxY]
|
|
134
|
-
* @param {number[]} [containerBoundaries] The boundaries of the container the element should be contained in: [minX, minY, maxX, maxY]
|
|
135
|
-
* @param {number} [preferredDirection=1] Which direction is preferred. Either 1 (right right) or -1 (to left)
|
|
136
|
-
* @param {boolean} [isRootLevel] Flag that indicates if the element is on level 1 (the root level)
|
|
137
|
-
* @param {object} [element] The list element - used to calculate the offset of submenus
|
|
138
|
-
* @returns {object} The determined position and direction of the element: { position: [x, y], direction: 1 | -1 }
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
function getPosition(elementDimensions, targetBoundaries, containerBoundaries) {
|
|
143
|
-
var preferredDirection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
144
|
-
var isRootLevel = arguments.length > 4 ? arguments[4] : undefined;
|
|
145
|
-
var element = arguments.length > 5 ? arguments[5] : undefined;
|
|
146
|
-
var position = [0, 0];
|
|
147
|
-
var direction = preferredDirection; // x
|
|
148
|
-
|
|
149
|
-
position[0] = direction === 1 ? targetBoundaries[0] : targetBoundaries[2] - elementDimensions[0];
|
|
150
|
-
var xFits = elementFits(elementDimensions, position, containerBoundaries, 'x');
|
|
151
|
-
|
|
152
|
-
if (!xFits) {
|
|
153
|
-
direction = direction * -1;
|
|
154
|
-
position[0] = direction === 1 ? targetBoundaries[0] : targetBoundaries[2] - elementDimensions[0];
|
|
155
|
-
} // y
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
position[1] = targetBoundaries[3];
|
|
159
|
-
var yFits = elementFits(elementDimensions, position, containerBoundaries, 'y');
|
|
160
|
-
|
|
161
|
-
if (!yFits) {
|
|
162
|
-
position[1] = targetBoundaries[1] - elementDimensions[1];
|
|
163
|
-
|
|
164
|
-
if (!isRootLevel && element) {
|
|
165
|
-
// if sub-menu and not root level, consider offset
|
|
166
|
-
var diff = getSubMenuOffset(element);
|
|
167
|
-
position[1] += diff;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
position: position,
|
|
173
|
-
direction: direction
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { capWithinRange, clickedElementHasSubnodes, focusNode, getFirstSubNode, getNextNode, getParentMenu, getParentNode, getPosition, getSubMenuOffset, getValidNodes, resetFocus };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2016, 2022
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import Menu from './Menu.js';
|
|
9
|
-
export { default as Menu, default } from './Menu.js';
|
|
10
|
-
import MenuDivider from './MenuDivider.js';
|
|
11
|
-
export { default as MenuDivider } from './MenuDivider.js';
|
|
12
|
-
import MenuGroup from './MenuGroup.js';
|
|
13
|
-
export { default as MenuGroup } from './MenuGroup.js';
|
|
14
|
-
import MenuItem from './MenuItem.js';
|
|
15
|
-
export { default as MenuItem } from './MenuItem.js';
|
|
16
|
-
import MenuRadioGroup from './MenuRadioGroup.js';
|
|
17
|
-
export { default as MenuRadioGroup } from './MenuRadioGroup.js';
|
|
18
|
-
import MenuSelectableItem from './MenuSelectableItem.js';
|
|
19
|
-
export { default as MenuSelectableItem } from './MenuSelectableItem.js';
|
|
20
|
-
|
|
21
|
-
Menu.MenuDivider = MenuDivider;
|
|
22
|
-
Menu.MenuGroup = MenuGroup;
|
|
23
|
-
Menu.MenuItem = MenuItem;
|
|
24
|
-
Menu.MenuRadioGroup = MenuRadioGroup;
|
|
25
|
-
Menu.MenuSelectableItem = MenuSelectableItem;
|