@carbon/react 1.23.0-rc.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/DataTable/tools/sorting.js +3 -0
- 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/Grid/CSSGrid.d.ts +9 -0
- package/es/components/Grid/CSSGrid.js +8 -5
- package/es/components/Grid/Column.d.ts +73 -0
- package/es/components/Grid/Column.js +40 -34
- package/es/components/Grid/ColumnHang.d.ts +24 -0
- package/es/components/Grid/ColumnHang.js +7 -4
- package/es/components/Grid/FlexGrid.d.ts +9 -0
- package/es/components/Grid/FlexGrid.js +6 -3
- package/es/components/Grid/Grid.d.ts +9 -0
- package/es/components/Grid/Grid.js +6 -5
- package/es/components/Grid/GridContext.d.ts +38 -0
- package/es/components/Grid/GridContext.js +6 -6
- package/es/components/Grid/GridTypes.d.ts +37 -0
- package/es/components/Grid/Row.d.ts +34 -0
- package/es/components/Grid/Row.js +4 -2
- package/es/components/Grid/index.d.ts +11 -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 +7 -11
- package/es/prop-types/isRequiredOneOf.js +2 -2
- package/lib/components/DataTable/tools/sorting.js +3 -0
- 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/Grid/CSSGrid.d.ts +9 -0
- package/lib/components/Grid/CSSGrid.js +8 -5
- package/lib/components/Grid/Column.d.ts +73 -0
- package/lib/components/Grid/Column.js +36 -30
- package/lib/components/Grid/ColumnHang.d.ts +24 -0
- package/lib/components/Grid/ColumnHang.js +7 -4
- package/lib/components/Grid/FlexGrid.d.ts +9 -0
- package/lib/components/Grid/FlexGrid.js +6 -3
- package/lib/components/Grid/Grid.d.ts +9 -0
- package/lib/components/Grid/Grid.js +2 -1
- package/lib/components/Grid/GridContext.d.ts +38 -0
- package/lib/components/Grid/GridContext.js +6 -6
- package/lib/components/Grid/GridTypes.d.ts +37 -0
- package/lib/components/Grid/Row.d.ts +34 -0
- package/lib/components/Grid/Row.js +4 -2
- package/lib/components/Grid/index.d.ts +11 -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 +17 -21
- 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
|
@@ -10,68 +10,75 @@
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
12
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var React = require('react');
|
|
14
|
-
var ReactDOM = require('react-dom');
|
|
15
13
|
var cx = require('classnames');
|
|
16
14
|
var PropTypes = require('prop-types');
|
|
15
|
+
var React = require('react');
|
|
16
|
+
var ReactDOM = require('react-dom');
|
|
17
|
+
var useMergedRefs = require('../../internal/useMergedRefs.js');
|
|
17
18
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
18
|
-
var
|
|
19
|
-
var MenuGroup = require('./MenuGroup.js');
|
|
20
|
-
var MenuRadioGroup = require('./MenuRadioGroup.js');
|
|
21
|
-
var MenuRadioGroupOptions = require('./MenuRadioGroupOptions.js');
|
|
22
|
-
var MenuSelectableItem = require('./MenuSelectableItem.js');
|
|
19
|
+
var MenuContext = require('./MenuContext.js');
|
|
23
20
|
var match = require('../../internal/keyboard/match.js');
|
|
24
21
|
var keys = require('../../internal/keyboard/keys.js');
|
|
25
22
|
|
|
26
23
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
24
|
|
|
28
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
29
|
-
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
30
25
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
31
26
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
27
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
32
28
|
|
|
33
|
-
var _excluded = ["children", "className", "
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
var defaultSize = 'sm';
|
|
29
|
+
var _excluded = ["children", "className", "label", "onClose", "open", "size", "target", "x", "y"];
|
|
30
|
+
var spacing = 8; // distance to keep to window edges, in px
|
|
37
31
|
|
|
38
|
-
var Menu = function Menu(_ref) {
|
|
39
|
-
var
|
|
32
|
+
var Menu = /*#__PURE__*/React__default["default"].forwardRef(function Menu(_ref, forwardRef) {
|
|
33
|
+
var _cx;
|
|
40
34
|
|
|
41
35
|
var children = _ref.children,
|
|
42
36
|
className = _ref.className,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
level = _ref$level === void 0 ? 1 : _ref$level,
|
|
37
|
+
label = _ref.label,
|
|
38
|
+
onClose = _ref.onClose,
|
|
46
39
|
open = _ref.open,
|
|
47
40
|
_ref$size = _ref.size,
|
|
48
|
-
size = _ref$size === void 0 ?
|
|
41
|
+
size = _ref$size === void 0 ? 'sm' : _ref$size,
|
|
49
42
|
_ref$target = _ref.target,
|
|
50
43
|
target = _ref$target === void 0 ? document.body : _ref$target,
|
|
51
44
|
_ref$x = _ref.x,
|
|
52
45
|
x = _ref$x === void 0 ? 0 : _ref$x,
|
|
53
46
|
_ref$y = _ref.y,
|
|
54
47
|
y = _ref$y === void 0 ? 0 : _ref$y,
|
|
55
|
-
_ref$onClose = _ref.onClose,
|
|
56
|
-
onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
|
|
57
48
|
rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
|
|
58
49
|
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
var
|
|
50
|
+
var prefix = usePrefix.usePrefix();
|
|
51
|
+
var focusReturn = React.useRef(null);
|
|
52
|
+
var context = React.useContext(MenuContext.MenuContext);
|
|
53
|
+
var isRoot = context.state.isRoot;
|
|
54
|
+
var menuSize = isRoot ? size : context.state.size;
|
|
55
|
+
|
|
56
|
+
var _useReducer = React.useReducer(MenuContext.menuReducer, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, context.state), {}, {
|
|
57
|
+
isRoot: false,
|
|
58
|
+
size: size,
|
|
59
|
+
requestCloseRoot: isRoot ? handleClose : context.state.requestCloseRoot
|
|
60
|
+
})),
|
|
61
|
+
_useReducer2 = _rollupPluginBabelHelpers.slicedToArray(_useReducer, 2),
|
|
62
|
+
childState = _useReducer2[0],
|
|
63
|
+
childDispatch = _useReducer2[1];
|
|
64
|
+
|
|
65
|
+
var childContext = React.useMemo(function () {
|
|
66
|
+
return {
|
|
67
|
+
state: childState,
|
|
68
|
+
dispatch: childDispatch
|
|
69
|
+
};
|
|
70
|
+
}, [childState, childDispatch]);
|
|
71
|
+
var menu = React.useRef();
|
|
72
|
+
var ref = useMergedRefs.useMergedRefs([forwardRef, menu]);
|
|
73
|
+
|
|
74
|
+
var _useState = React.useState([-1, -1]),
|
|
62
75
|
_useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
position = _useState2[0],
|
|
77
|
+
setPosition = _useState2[1];
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
position = _useState4[0],
|
|
70
|
-
setPosition = _useState4[1];
|
|
71
|
-
|
|
72
|
-
var isRootMenu = level === 1;
|
|
73
|
-
var focusReturn = React.useRef(null);
|
|
74
|
-
var prefix = usePrefix.usePrefix();
|
|
79
|
+
var focusableItems = childContext.state.items.filter(function (item) {
|
|
80
|
+
return !item.disabled;
|
|
81
|
+
});
|
|
75
82
|
|
|
76
83
|
function returnFocus() {
|
|
77
84
|
if (focusReturn.current) {
|
|
@@ -79,261 +86,201 @@ var Menu = function Menu(_ref) {
|
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
function
|
|
83
|
-
|
|
89
|
+
function handleOpen() {
|
|
90
|
+
if (menu.current) {
|
|
91
|
+
focusReturn.current = document.activeElement;
|
|
92
|
+
setPosition(calculatePosition());
|
|
93
|
+
menu.current.focus();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
84
96
|
|
|
85
|
-
|
|
97
|
+
function handleClose(e) {
|
|
98
|
+
if (/^key/.test(e.type)) {
|
|
86
99
|
window.addEventListener('keyup', returnFocus, {
|
|
87
100
|
once: true
|
|
88
101
|
});
|
|
89
|
-
} else {
|
|
90
|
-
|
|
102
|
+
} else if (e.type === 'click' && menu.current) {
|
|
103
|
+
menu.current.addEventListener('focusout', returnFocus, {
|
|
91
104
|
once: true
|
|
92
105
|
});
|
|
106
|
+
} else {
|
|
107
|
+
returnFocus();
|
|
93
108
|
}
|
|
94
109
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function getContainerBoundaries() {
|
|
99
|
-
var _document$body = document.body,
|
|
100
|
-
bodyWidth = _document$body.clientWidth,
|
|
101
|
-
bodyHeight = _document$body.clientHeight;
|
|
102
|
-
return [margin, margin, bodyWidth - margin, bodyHeight - margin];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function getTargetBoundaries() {
|
|
106
|
-
var xIsRange = _rollupPluginBabelHelpers["typeof"](x) === 'object' && x.length === 2;
|
|
107
|
-
var yIsRange = _rollupPluginBabelHelpers["typeof"](y) === 'object' && y.length === 2;
|
|
108
|
-
var targetBoundaries = [xIsRange ? x[0] : x, yIsRange ? y[0] : y, xIsRange ? x[1] : x, yIsRange ? y[1] : y];
|
|
109
|
-
|
|
110
|
-
if (!isRootMenu) {
|
|
111
|
-
var _getParentMenu;
|
|
112
|
-
|
|
113
|
-
var _getParentMenu$getBou = (_getParentMenu = _utils.getParentMenu(rootRef.current)) === null || _getParentMenu === void 0 ? void 0 : _getParentMenu.getBoundingClientRect(),
|
|
114
|
-
parentWidth = _getParentMenu$getBou.width;
|
|
115
|
-
|
|
116
|
-
targetBoundaries[2] -= parentWidth;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var containerBoundaries = getContainerBoundaries();
|
|
120
|
-
return [_utils.capWithinRange(targetBoundaries[0], containerBoundaries[0], containerBoundaries[2]), _utils.capWithinRange(targetBoundaries[1], containerBoundaries[1], containerBoundaries[3]), _utils.capWithinRange(targetBoundaries[2], containerBoundaries[0], containerBoundaries[2]), _utils.capWithinRange(targetBoundaries[3], containerBoundaries[1], containerBoundaries[3])];
|
|
121
|
-
}
|
|
110
|
+
childDispatch({
|
|
111
|
+
type: 'clearRegisteredItems'
|
|
112
|
+
});
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
_utils.resetFocus(rootRef.current);
|
|
126
|
-
_utils.focusNode(node);
|
|
114
|
+
if (onClose) {
|
|
115
|
+
onClose();
|
|
127
116
|
}
|
|
128
117
|
}
|
|
129
118
|
|
|
130
|
-
function handleKeyDown(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
119
|
+
function handleKeyDown(e) {
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
var currentItem = focusableItems.findIndex(function (item) {
|
|
122
|
+
return item.ref.current.contains(document.activeElement);
|
|
123
|
+
});
|
|
124
|
+
var indexToFocus = currentItem; // if the user presses escape or this is a submenu
|
|
125
|
+
// and the user presses ArrowLeft, close it
|
|
135
126
|
|
|
136
|
-
if (
|
|
137
|
-
|
|
127
|
+
if ((match.match(e, keys.Escape) || !isRoot && match.match(e, keys.ArrowLeft)) && onClose) {
|
|
128
|
+
handleClose(e);
|
|
138
129
|
} else {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var nodeToFocus;
|
|
147
|
-
|
|
148
|
-
if (event.target.tagName === 'LI') {
|
|
149
|
-
var currentNode = event.target;
|
|
130
|
+
// if currentItem is -1, the menu itself is focused.
|
|
131
|
+
// in this case, the arrow keys define the first item
|
|
132
|
+
// to be focused.
|
|
133
|
+
if (match.match(e, keys.ArrowUp)) {
|
|
134
|
+
indexToFocus = currentItem === -1 ? focusableItems.length - 1 : indexToFocus - 1;
|
|
135
|
+
}
|
|
150
136
|
|
|
151
|
-
if (match.match(
|
|
152
|
-
|
|
153
|
-
} else if (match.match(event, keys.ArrowDown)) {
|
|
154
|
-
nodeToFocus = _utils.getNextNode(currentNode, 1);
|
|
155
|
-
} else if (match.match(event, keys.ArrowLeft)) {
|
|
156
|
-
nodeToFocus = _utils.getParentNode(currentNode);
|
|
137
|
+
if (match.match(e, keys.ArrowDown)) {
|
|
138
|
+
indexToFocus = currentItem === -1 ? 0 : indexToFocus + 1;
|
|
157
139
|
}
|
|
158
|
-
} else if (event.target.tagName === 'UL') {
|
|
159
|
-
var validNodes = _utils.getValidNodes(event.target);
|
|
160
140
|
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
} else if (validNodes.length > 0 && match.match(event, keys.ArrowDown)) {
|
|
164
|
-
nodeToFocus = validNodes[0];
|
|
141
|
+
if (indexToFocus < 0) {
|
|
142
|
+
indexToFocus = 0;
|
|
165
143
|
}
|
|
166
|
-
}
|
|
167
144
|
|
|
168
|
-
|
|
145
|
+
if (indexToFocus >= focusableItems.length) {
|
|
146
|
+
indexToFocus = focusableItems.length - 1;
|
|
147
|
+
}
|
|
169
148
|
|
|
170
|
-
|
|
171
|
-
|
|
149
|
+
if (indexToFocus !== currentItem) {
|
|
150
|
+
var nodeToFocus = focusableItems[indexToFocus];
|
|
151
|
+
nodeToFocus.ref.current.focus();
|
|
152
|
+
}
|
|
172
153
|
}
|
|
173
154
|
}
|
|
174
155
|
|
|
175
|
-
function
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
} else {
|
|
179
|
-
event.stopPropagation();
|
|
156
|
+
function handleBlur(e) {
|
|
157
|
+
if (open && onClose && isRoot && !menu.current.contains(e.relatedTarget)) {
|
|
158
|
+
handleClose(e);
|
|
180
159
|
}
|
|
181
160
|
}
|
|
182
161
|
|
|
183
|
-
function
|
|
184
|
-
var
|
|
162
|
+
function fitValue(range, axis) {
|
|
163
|
+
var _menu$current$getBoun = menu.current.getBoundingClientRect(),
|
|
164
|
+
width = _menu$current$getBoun.width,
|
|
165
|
+
height = _menu$current$getBoun.height;
|
|
166
|
+
|
|
167
|
+
var alignment = isRoot ? 'vertical' : 'horizontal';
|
|
168
|
+
var axes = {
|
|
169
|
+
x: {
|
|
170
|
+
max: window.innerWidth,
|
|
171
|
+
size: width,
|
|
172
|
+
anchor: alignment === 'horizontal' ? range[1] : range[0],
|
|
173
|
+
reversedAnchor: alignment === 'horizontal' ? range[0] : range[1],
|
|
174
|
+
offset: 0
|
|
175
|
+
},
|
|
176
|
+
y: {
|
|
177
|
+
max: window.innerHeight,
|
|
178
|
+
size: height,
|
|
179
|
+
anchor: alignment === 'horizontal' ? range[0] : range[1],
|
|
180
|
+
reversedAnchor: alignment === 'horizontal' ? range[1] : range[0],
|
|
181
|
+
offset: isRoot ? 0 : 4 // top padding in menu, used to align the menu items
|
|
185
182
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var _axes$axis = axes[axis],
|
|
186
|
+
max = _axes$axis.max,
|
|
187
|
+
size = _axes$axis.size,
|
|
188
|
+
anchor = _axes$axis.anchor,
|
|
189
|
+
reversedAnchor = _axes$axis.reversedAnchor,
|
|
190
|
+
offset = _axes$axis.offset; // get values for different scenarios, set to false if they don't work
|
|
191
|
+
|
|
192
|
+
var options = [// towards max (preferred)
|
|
193
|
+
max - spacing - size - anchor >= 0 ? anchor - offset : false, // towards min / reversed (first fallback)
|
|
194
|
+
reversedAnchor - size >= 0 ? reversedAnchor - size + offset : false, // align at max (second fallback)
|
|
195
|
+
max - spacing - size];
|
|
196
|
+
var bestOption = options.find(function (option) {
|
|
197
|
+
return option !== false;
|
|
198
|
+
});
|
|
199
|
+
return bestOption >= spacing ? bestOption : spacing;
|
|
197
200
|
}
|
|
198
201
|
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
function calculatePosition() {
|
|
203
|
+
if (menu.current) {
|
|
204
|
+
var ranges = {
|
|
205
|
+
x: _rollupPluginBabelHelpers["typeof"](x) === 'object' && x.length === 2 ? x : [x, x],
|
|
206
|
+
y: _rollupPluginBabelHelpers["typeof"](y) === 'object' && y.length === 2 ? y : [y, y]
|
|
207
|
+
};
|
|
208
|
+
return [fitValue(ranges.x, 'x'), fitValue(ranges.y, 'y')];
|
|
204
209
|
}
|
|
210
|
+
|
|
211
|
+
return [-1, -1];
|
|
205
212
|
}
|
|
206
213
|
|
|
207
214
|
React.useEffect(function () {
|
|
208
215
|
if (open) {
|
|
209
|
-
|
|
210
|
-
var localDirection = 1;
|
|
211
|
-
|
|
212
|
-
if (isRootMenu) {
|
|
213
|
-
var _rootRef$current3;
|
|
214
|
-
|
|
215
|
-
(_rootRef$current3 = rootRef.current) === null || _rootRef$current3 === void 0 ? void 0 : _rootRef$current3.focus();
|
|
216
|
-
} else {
|
|
217
|
-
var parentMenu = _utils.getParentMenu(rootRef.current);
|
|
218
|
-
|
|
219
|
-
if (parentMenu) {
|
|
220
|
-
localDirection = Number(parentMenu.dataset.direction);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
var correctedPosition = getCorrectedPosition(localDirection);
|
|
225
|
-
setPosition(correctedPosition);
|
|
226
|
-
} else {
|
|
227
|
-
setPosition([0, 0]);
|
|
216
|
+
handleOpen();
|
|
228
217
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
229
218
|
|
|
230
|
-
}, [open
|
|
231
|
-
var
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
var classes = cx__default["default"]("".concat(prefix, "--menu"), (_classnames = {}, _rollupPluginBabelHelpers.defineProperty(_classnames, "".concat(prefix, "--menu--open"), open), _rollupPluginBabelHelpers.defineProperty(_classnames, "".concat(prefix, "--menu--invisible"), open && position[0] === 0 && position[1] === 0), _rollupPluginBabelHelpers.defineProperty(_classnames, "".concat(prefix, "--menu--root"), isRootMenu), _classnames), size !== defaultSize && "".concat(prefix, "--menu--").concat(size), className);
|
|
243
|
-
|
|
244
|
-
var ulAttributes = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, rest), {}, {
|
|
245
|
-
id: id,
|
|
246
|
-
ref: rootRef,
|
|
247
|
-
className: classes,
|
|
248
|
-
onKeyDown: handleKeyDown,
|
|
249
|
-
onClick: handleClick,
|
|
250
|
-
onBlur: handleBlur,
|
|
251
|
-
role: 'menu',
|
|
219
|
+
}, [open]);
|
|
220
|
+
var classNames = cx__default["default"](className, "".concat(prefix, "--menu"), "".concat(prefix, "--menu--").concat(menuSize), (_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--menu--open"), open), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--menu--shown"), position[0] >= 0 && position[1] >= 0), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--menu--with-icons"), childContext.state.hasIcons), _cx));
|
|
221
|
+
var rendered = /*#__PURE__*/React__default["default"].createElement(MenuContext.MenuContext.Provider, {
|
|
222
|
+
value: childContext
|
|
223
|
+
}, /*#__PURE__*/React__default["default"].createElement("ul", _rollupPluginBabelHelpers["extends"]({}, rest, {
|
|
224
|
+
className: classNames,
|
|
225
|
+
role: "menu",
|
|
226
|
+
ref: ref,
|
|
227
|
+
"aria-label": label,
|
|
252
228
|
tabIndex: -1,
|
|
253
|
-
|
|
254
|
-
|
|
229
|
+
onKeyDown: handleKeyDown,
|
|
230
|
+
onBlur: handleBlur // eslint-disable-next-line react/forbid-dom-props
|
|
231
|
+
,
|
|
255
232
|
style: {
|
|
256
233
|
left: "".concat(position[0], "px"),
|
|
257
234
|
top: "".concat(position[1], "px")
|
|
258
235
|
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// only the items to prevent duplicate markup
|
|
263
|
-
|
|
264
|
-
if (options && options.length === 1 && options[0].type === MenuRadioGroup["default"]) {
|
|
265
|
-
var radioGroupProps = options[0].props;
|
|
266
|
-
ulAttributes['aria-label'] = radioGroupProps.label;
|
|
267
|
-
childrenToRender = /*#__PURE__*/React__default["default"].createElement(MenuRadioGroupOptions["default"], {
|
|
268
|
-
items: radioGroupProps.items,
|
|
269
|
-
initialSelectedItem: radioGroupProps.initialSelectedItem,
|
|
270
|
-
onChange: radioGroupProps.onChange
|
|
271
|
-
});
|
|
272
|
-
} // if the only child is a generic group, don't render it as group component, but
|
|
273
|
-
// only the children to prevent duplicate markup
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (options && options.length === 1 && options[0].type === MenuGroup["default"]) {
|
|
277
|
-
var groupProps = options[0].props;
|
|
278
|
-
ulAttributes['aria-label'] = groupProps.label;
|
|
279
|
-
childrenToRender = React__default["default"].Children.toArray(options[0].props.children);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var menu = /*#__PURE__*/React__default["default"].createElement("ul", ulAttributes, childrenToRender);
|
|
283
|
-
return isRootMenu ? open && /*#__PURE__*/ReactDOM__default["default"].createPortal(menu, target) || null : menu;
|
|
284
|
-
};
|
|
285
|
-
|
|
236
|
+
}), children));
|
|
237
|
+
return isRoot ? open && /*#__PURE__*/ReactDOM.createPortal(rendered, target) || null : rendered;
|
|
238
|
+
});
|
|
286
239
|
Menu.propTypes = {
|
|
287
240
|
/**
|
|
288
|
-
*
|
|
241
|
+
* A collection of MenuItems to be rendered within this Menu.
|
|
289
242
|
*/
|
|
290
243
|
children: PropTypes__default["default"].node,
|
|
291
244
|
|
|
292
245
|
/**
|
|
293
|
-
*
|
|
246
|
+
* Additional CSS class names.
|
|
294
247
|
*/
|
|
295
248
|
className: PropTypes__default["default"].string,
|
|
296
249
|
|
|
297
250
|
/**
|
|
298
|
-
*
|
|
299
|
-
*/
|
|
300
|
-
id: PropTypes__default["default"].string,
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Internal: keeps track of the nesting level of the menu
|
|
251
|
+
* A label describing the Menu.
|
|
304
252
|
*/
|
|
305
|
-
|
|
253
|
+
label: PropTypes__default["default"].string,
|
|
306
254
|
|
|
307
255
|
/**
|
|
308
|
-
*
|
|
256
|
+
* Provide an optional function to be called when the Menu should be closed.
|
|
309
257
|
*/
|
|
310
258
|
onClose: PropTypes__default["default"].func,
|
|
311
259
|
|
|
312
260
|
/**
|
|
313
|
-
*
|
|
261
|
+
* Whether the Menu is open or not.
|
|
314
262
|
*/
|
|
315
263
|
open: PropTypes__default["default"].bool,
|
|
316
264
|
|
|
317
265
|
/**
|
|
318
|
-
* Specify the size of the
|
|
266
|
+
* Specify the size of the Menu.
|
|
319
267
|
*/
|
|
320
|
-
size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg']),
|
|
268
|
+
size: PropTypes__default["default"].oneOf(['xs', 'sm', 'md', 'lg']),
|
|
321
269
|
|
|
322
270
|
/**
|
|
323
|
-
*
|
|
271
|
+
* Specify a DOM node where the Menu should be rendered in. Defaults to document.body.
|
|
324
272
|
*/
|
|
325
273
|
target: PropTypes__default["default"].object,
|
|
326
274
|
|
|
327
275
|
/**
|
|
328
|
-
* Specify the x position
|
|
276
|
+
* Specify the x position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([x1, x2])
|
|
329
277
|
*/
|
|
330
278
|
x: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)]),
|
|
331
279
|
|
|
332
280
|
/**
|
|
333
|
-
* Specify the y position
|
|
281
|
+
* Specify the y position of the Menu. Either pass a single number or an array with two numbers describing your activator's boundaries ([y1, y2])
|
|
334
282
|
*/
|
|
335
283
|
y: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)])
|
|
336
284
|
};
|
|
337
|
-
var Menu$1 = Menu;
|
|
338
285
|
|
|
339
|
-
exports
|
|
286
|
+
exports.Menu = Menu;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
|
+
|
|
19
|
+
var menuDefaultState = {
|
|
20
|
+
isRoot: true,
|
|
21
|
+
hasIcons: false,
|
|
22
|
+
size: null,
|
|
23
|
+
items: [],
|
|
24
|
+
requestCloseRoot: function requestCloseRoot() {}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function menuReducer(state, action) {
|
|
28
|
+
switch (action.type) {
|
|
29
|
+
case 'enableIcons':
|
|
30
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, {
|
|
31
|
+
hasIcons: true
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
case 'registerItem':
|
|
35
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, {
|
|
36
|
+
items: [].concat(_rollupPluginBabelHelpers.toConsumableArray(state.items), [action.payload])
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
case 'clearRegisteredItems':
|
|
40
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, {
|
|
41
|
+
items: []
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var MenuContext = /*#__PURE__*/React__default["default"].createContext({
|
|
47
|
+
state: menuDefaultState,
|
|
48
|
+
// 'dispatch' is populated by the root menu
|
|
49
|
+
dispatch: function dispatch() {}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
exports.MenuContext = MenuContext;
|
|
53
|
+
exports.menuReducer = menuReducer;
|