@carbon/react 1.78.1 → 1.79.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +844 -844
- package/es/components/Button/Button.js +28 -17
- package/es/components/Button/ButtonBase.js +2 -0
- package/es/components/DataTable/TableContainer.js +3 -2
- package/es/components/Grid/Column.d.ts +2 -2
- package/es/components/Grid/Column.js +7 -8
- package/es/components/IconButton/index.d.ts +2 -2
- package/es/components/IconButton/index.js +1 -1
- package/es/components/MultiSelect/index.d.ts +1 -1
- package/es/components/MultiSelect/index.js +1 -8
- package/es/components/OverflowMenu/OverflowMenu.d.ts +21 -196
- package/es/components/OverflowMenu/OverflowMenu.js +267 -336
- package/es/components/OverflowMenu/index.d.ts +5 -5
- package/es/components/OverflowMenu/index.js +2 -2
- package/es/components/OverflowMenu/next/index.d.ts +2 -2
- package/es/components/Slider/Slider.d.ts +23 -29
- package/es/components/Slider/Slider.js +35 -37
- package/es/components/Tabs/Tabs.js +8 -9
- package/es/components/Tile/Tile.js +8 -4
- package/es/index.js +1 -1
- package/es/internal/FloatingMenu.d.ts +2 -2
- package/es/internal/FloatingMenu.js +4 -1
- package/es/internal/createClassWrapper.d.ts +3 -3
- package/es/internal/createClassWrapper.js +4 -4
- package/es/internal/useMatchMedia.d.ts +8 -0
- package/es/internal/useMatchMedia.js +10 -20
- package/es/internal/useNormalizedInputProps.d.ts +52 -0
- package/es/internal/useNormalizedInputProps.js +9 -36
- package/lib/components/Button/Button.js +28 -17
- package/lib/components/Button/ButtonBase.js +2 -0
- package/lib/components/DataTable/TableContainer.js +3 -2
- package/lib/components/Grid/Column.d.ts +2 -2
- package/lib/components/Grid/Column.js +7 -8
- package/lib/components/IconButton/index.d.ts +2 -2
- package/lib/components/IconButton/index.js +1 -1
- package/lib/components/MultiSelect/index.d.ts +1 -1
- package/lib/components/MultiSelect/index.js +1 -8
- package/lib/components/OverflowMenu/OverflowMenu.d.ts +21 -196
- package/lib/components/OverflowMenu/OverflowMenu.js +266 -334
- package/lib/components/OverflowMenu/index.d.ts +5 -5
- package/lib/components/OverflowMenu/index.js +2 -2
- package/lib/components/OverflowMenu/next/index.d.ts +2 -2
- package/lib/components/Slider/Slider.d.ts +23 -29
- package/lib/components/Slider/Slider.js +35 -37
- package/lib/components/Tabs/Tabs.js +8 -9
- package/lib/components/Tile/Tile.js +8 -4
- package/lib/index.js +2 -2
- package/lib/internal/FloatingMenu.d.ts +2 -2
- package/lib/internal/FloatingMenu.js +4 -1
- package/lib/internal/createClassWrapper.d.ts +3 -3
- package/lib/internal/createClassWrapper.js +4 -4
- package/lib/internal/useMatchMedia.d.ts +8 -0
- package/lib/internal/useMatchMedia.js +10 -20
- package/lib/internal/useNormalizedInputProps.d.ts +52 -0
- package/lib/internal/useNormalizedInputProps.js +9 -36
- package/package.json +6 -6
- package/es/internal/useEffectOnce.js +0 -30
- package/lib/internal/useEffectOnce.js +0 -34
|
@@ -10,38 +10,38 @@
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
12
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
|
-
var FloatingMenu = require('../../internal/FloatingMenu.js');
|
|
14
13
|
var React = require('react');
|
|
14
|
+
var iconsReact = require('@carbon/icons-react');
|
|
15
|
+
var cx = require('classnames');
|
|
16
|
+
var invariant = require('invariant');
|
|
17
|
+
var PropTypes = require('prop-types');
|
|
18
|
+
var ClickListener = require('../../internal/ClickListener.js');
|
|
19
|
+
var FloatingMenu = require('../../internal/FloatingMenu.js');
|
|
15
20
|
var keys = require('../../internal/keyboard/keys.js');
|
|
16
21
|
var match = require('../../internal/keyboard/match.js');
|
|
17
|
-
var
|
|
18
|
-
var index = require('../IconButton/index.js');
|
|
19
|
-
var iconsReact = require('@carbon/icons-react');
|
|
22
|
+
var noopFn = require('../../internal/noopFn.js');
|
|
20
23
|
var usePrefix = require('../../internal/usePrefix.js');
|
|
21
|
-
var PropTypes = require('prop-types');
|
|
22
|
-
var cx = require('classnames');
|
|
23
24
|
var deprecate = require('../../prop-types/deprecate.js');
|
|
24
|
-
var invariant = require('invariant');
|
|
25
25
|
var mergeRefs = require('../../tools/mergeRefs.js');
|
|
26
|
-
var noopFn = require('../../internal/noopFn.js');
|
|
27
26
|
var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
|
|
27
|
+
var index = require('../IconButton/index.js');
|
|
28
28
|
|
|
29
29
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
30
30
|
|
|
31
31
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
32
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
33
32
|
var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
|
|
34
33
|
var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
|
|
34
|
+
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
35
35
|
|
|
36
36
|
const getInstanceId = setupGetInstanceId["default"]();
|
|
37
|
-
const on = function (
|
|
37
|
+
const on = function (target) {
|
|
38
38
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
39
39
|
args[_key - 1] = arguments[_key];
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
target.addEventListener(...args);
|
|
42
42
|
return {
|
|
43
43
|
release() {
|
|
44
|
-
|
|
44
|
+
target.removeEventListener(...args);
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -49,7 +49,6 @@ const on = function (element) {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* The CSS property names of the arrow keyed by the floating menu direction.
|
|
52
|
-
* @type {[key: string]: string}
|
|
53
52
|
*/
|
|
54
53
|
const triggerButtonPositionProps = {
|
|
55
54
|
[FloatingMenu.DIRECTION_TOP]: 'bottom',
|
|
@@ -57,13 +56,22 @@ const triggerButtonPositionProps = {
|
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
|
-
* Determines how the position of arrow should affect the floating menu
|
|
61
|
-
*
|
|
59
|
+
* Determines how the position of the arrow should affect the floating menu
|
|
60
|
+
* position.
|
|
62
61
|
*/
|
|
63
62
|
const triggerButtonPositionFactors = {
|
|
64
63
|
[FloatingMenu.DIRECTION_TOP]: -2,
|
|
65
64
|
[FloatingMenu.DIRECTION_BOTTOM]: -1
|
|
66
65
|
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Calculates the offset for the floating menu.
|
|
69
|
+
*
|
|
70
|
+
* @param menuBody - The menu body with the menu arrow.
|
|
71
|
+
* @param direction - The floating menu direction.
|
|
72
|
+
* @returns The adjustment of the floating menu position, upon the position of
|
|
73
|
+
* the menu arrow.
|
|
74
|
+
*/
|
|
67
75
|
const getMenuOffset = (menuBody, direction, trigger, flip) => {
|
|
68
76
|
const triggerButtonPositionProp = triggerButtonPositionProps[direction];
|
|
69
77
|
const triggerButtonPositionFactor = triggerButtonPositionFactors[direction];
|
|
@@ -92,324 +100,254 @@ const getMenuOffset = (menuBody, direction, trigger, flip) => {
|
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
102
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.focusMenuEl();
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
_rollupPluginBabelHelpers.defineProperty(this, "closeMenuOnEscape", () => {
|
|
146
|
-
const wasOpen = this.state.open;
|
|
147
|
-
this.closeMenu(() => {
|
|
148
|
-
if (wasOpen) {
|
|
149
|
-
this.focusMenuEl();
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleKeyPress", evt => {
|
|
154
|
-
if (this.state.open && match.matches(evt, [keys.ArrowUp, keys.ArrowRight, keys.ArrowDown, keys.ArrowLeft])) {
|
|
155
|
-
evt.preventDefault();
|
|
156
|
-
}
|
|
103
|
+
const OverflowMenu = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
104
|
+
let {
|
|
105
|
+
['aria-label']: ariaLabel = null,
|
|
106
|
+
ariaLabel: deprecatedAriaLabel,
|
|
107
|
+
children,
|
|
108
|
+
className,
|
|
109
|
+
direction = FloatingMenu.DIRECTION_BOTTOM,
|
|
110
|
+
flipped = false,
|
|
111
|
+
focusTrap = true,
|
|
112
|
+
iconClass,
|
|
113
|
+
iconDescription = 'Options',
|
|
114
|
+
id,
|
|
115
|
+
light,
|
|
116
|
+
menuOffset = getMenuOffset,
|
|
117
|
+
menuOffsetFlip = getMenuOffset,
|
|
118
|
+
menuOptionsClass,
|
|
119
|
+
onClick = noopFn.noopFn,
|
|
120
|
+
onClose = noopFn.noopFn,
|
|
121
|
+
onOpen = noopFn.noopFn,
|
|
122
|
+
open: openProp,
|
|
123
|
+
renderIcon: IconElement = iconsReact.OverflowMenuVertical,
|
|
124
|
+
selectorPrimaryFocus = '[data-floating-menu-primary-focus]',
|
|
125
|
+
size = 'md',
|
|
126
|
+
...other
|
|
127
|
+
} = _ref;
|
|
128
|
+
const prefix = React.useContext(usePrefix.PrefixContext);
|
|
129
|
+
const [open, setOpen] = React.useState(openProp ?? false);
|
|
130
|
+
const [click, setClick] = React.useState(false);
|
|
131
|
+
const [hasMountedTrigger, setHasMountedTrigger] = React.useState(false);
|
|
132
|
+
/** The handle of `onfocusin` or `focus` event handler. */
|
|
133
|
+
const hFocusIn = React.useRef(null);
|
|
134
|
+
const instanceId = React.useRef(getInstanceId());
|
|
135
|
+
const menuBodyRef = React.useRef(null);
|
|
136
|
+
const menuItemRefs = React.useRef({});
|
|
137
|
+
const prevOpenProp = React.useRef(openProp);
|
|
138
|
+
const prevOpenState = React.useRef(open);
|
|
139
|
+
/** The element ref of the tooltip's trigger button. */
|
|
140
|
+
const triggerRef = React.useRef(null);
|
|
141
|
+
|
|
142
|
+
// Sync open prop changes.
|
|
143
|
+
React.useEffect(() => {
|
|
144
|
+
if (prevOpenProp.current !== openProp) {
|
|
145
|
+
setOpen(!!openProp);
|
|
146
|
+
prevOpenProp.current = openProp;
|
|
147
|
+
}
|
|
148
|
+
}, [openProp]);
|
|
157
149
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
// Mark trigger as mounted.
|
|
151
|
+
React.useEffect(() => {
|
|
152
|
+
if (triggerRef.current) {
|
|
153
|
+
setHasMountedTrigger(true);
|
|
154
|
+
}
|
|
155
|
+
}, []);
|
|
161
156
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
157
|
+
// Call `onClose` when menu closes.
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
if (!open && prevOpenState.current) {
|
|
160
|
+
onClose();
|
|
161
|
+
}
|
|
162
|
+
prevOpenState.current = open;
|
|
163
|
+
}, [open, onClose]);
|
|
164
|
+
const focusMenuEl = React.useCallback(() => {
|
|
165
|
+
if (triggerRef.current) {
|
|
166
|
+
triggerRef.current.focus();
|
|
167
|
+
}
|
|
168
|
+
}, []);
|
|
169
|
+
const closeMenu = React.useCallback(onCloseMenu => {
|
|
170
|
+
setOpen(false);
|
|
171
|
+
// Optional callback to be executed after the state as been set to close
|
|
172
|
+
if (onCloseMenu) {
|
|
173
|
+
onCloseMenu();
|
|
174
|
+
}
|
|
175
|
+
onClose();
|
|
176
|
+
}, [onClose]);
|
|
177
|
+
const closeMenuAndFocus = React.useCallback(() => {
|
|
178
|
+
const wasClicked = click;
|
|
179
|
+
const wasOpen = open;
|
|
180
|
+
closeMenu(() => {
|
|
181
|
+
if (wasOpen && !wasClicked) {
|
|
182
|
+
focusMenuEl();
|
|
169
183
|
}
|
|
170
184
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}, () => {
|
|
178
|
-
// Optional callback to be executed after the state as been set to close
|
|
179
|
-
if (onCloseMenu) {
|
|
180
|
-
onCloseMenu();
|
|
181
|
-
}
|
|
182
|
-
onClose();
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
_rollupPluginBabelHelpers.defineProperty(this, "focusMenuEl", () => {
|
|
186
|
-
const {
|
|
187
|
-
current: triggerEl
|
|
188
|
-
} = this._triggerRef;
|
|
189
|
-
if (triggerEl) {
|
|
190
|
-
triggerEl.focus();
|
|
185
|
+
}, [click, open, closeMenu, focusMenuEl]);
|
|
186
|
+
const closeMenuOnEscape = React.useCallback(() => {
|
|
187
|
+
const wasOpen = open;
|
|
188
|
+
closeMenu(() => {
|
|
189
|
+
if (wasOpen) {
|
|
190
|
+
focusMenuEl();
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*/
|
|
233
|
-
_rollupPluginBabelHelpers.defineProperty(this, "_menuBody", null);
|
|
234
|
-
_rollupPluginBabelHelpers.defineProperty(this, "_bindMenuBody", menuBody => {
|
|
235
|
-
if (!menuBody) {
|
|
236
|
-
this._menuBody = menuBody;
|
|
193
|
+
}, [open, closeMenu, focusMenuEl]);
|
|
194
|
+
const handleClick = evt => {
|
|
195
|
+
setClick(true);
|
|
196
|
+
if (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target)) {
|
|
197
|
+
setOpen(prev => !prev);
|
|
198
|
+
onClick(evt);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const handleKeyPress = evt => {
|
|
202
|
+
if (open && match.matches(evt, [keys.ArrowUp, keys.ArrowRight, keys.ArrowDown, keys.ArrowLeft])) {
|
|
203
|
+
evt.preventDefault();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Close the overflow menu on escape
|
|
207
|
+
if (match.matches(evt, [keys.Escape])) {
|
|
208
|
+
closeMenuOnEscape();
|
|
209
|
+
|
|
210
|
+
// Stop the esc keypress from bubbling out and closing something it shouldn't
|
|
211
|
+
evt.stopPropagation();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const handleClickOutside = evt => {
|
|
215
|
+
if (open && (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target))) {
|
|
216
|
+
closeMenu();
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Focuses the next enabled overflow menu item given the currently focused
|
|
222
|
+
* item index and direction to move.
|
|
223
|
+
*/
|
|
224
|
+
const handleOverflowMenuItemFocus = _ref2 => {
|
|
225
|
+
let {
|
|
226
|
+
currentIndex,
|
|
227
|
+
direction
|
|
228
|
+
} = _ref2;
|
|
229
|
+
const enabledIndices = React.Children.toArray(children).reduce((acc, curr, i) => {
|
|
230
|
+
if (/*#__PURE__*/React.isValidElement(curr) && !curr.props.disabled) {
|
|
231
|
+
acc.push(i);
|
|
237
232
|
}
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
return acc;
|
|
234
|
+
}, []);
|
|
235
|
+
const nextValidIndex = (() => {
|
|
236
|
+
const nextIndex = enabledIndices.indexOf(currentIndex) + direction;
|
|
237
|
+
switch (nextIndex) {
|
|
238
|
+
case -1:
|
|
239
|
+
return enabledIndices.length - 1;
|
|
240
|
+
case enabledIndices.length:
|
|
241
|
+
return 0;
|
|
242
|
+
default:
|
|
243
|
+
return nextIndex;
|
|
240
244
|
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}, !hasFocusin);
|
|
266
|
-
onOpen();
|
|
245
|
+
})();
|
|
246
|
+
const overflowMenuItem = menuItemRefs.current[enabledIndices[nextValidIndex]];
|
|
247
|
+
overflowMenuItem?.focus();
|
|
248
|
+
};
|
|
249
|
+
const bindMenuBody = menuBody => {
|
|
250
|
+
if (!menuBody) {
|
|
251
|
+
menuBodyRef.current = menuBody;
|
|
252
|
+
}
|
|
253
|
+
if (!menuBody && hFocusIn.current) {
|
|
254
|
+
hFocusIn.current = hFocusIn.current.release();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const handlePlace = menuBody => {
|
|
258
|
+
if (!menuBody) return;
|
|
259
|
+
menuBodyRef.current = menuBody;
|
|
260
|
+
const hasFocusin = 'onfocusin' in window;
|
|
261
|
+
const focusinEventName = hasFocusin ? 'focusin' : 'focus';
|
|
262
|
+
hFocusIn.current = on(menuBody.ownerDocument, focusinEventName, event => {
|
|
263
|
+
const target = event.target;
|
|
264
|
+
const triggerEl = triggerRef.current;
|
|
265
|
+
if (typeof target.matches === 'function') {
|
|
266
|
+
if (!menuBody.contains(target) && triggerEl && !target.matches(`.${prefix}--overflow-menu:first-child, .${prefix}--overflow-menu-options:first-child`)) {
|
|
267
|
+
closeMenuAndFocus();
|
|
268
|
+
}
|
|
267
269
|
}
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
} = this._triggerRef;
|
|
276
|
-
return triggerEl instanceof Element && triggerEl.closest('[data-floating-menu-container]') || document.body;
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
componentDidUpdate(_, prevState) {
|
|
280
|
-
const {
|
|
281
|
-
onClose = noopFn.noopFn
|
|
282
|
-
} = this.props;
|
|
283
|
-
if (!this.state.open && prevState.open) {
|
|
284
|
-
onClose();
|
|
270
|
+
}, !hasFocusin);
|
|
271
|
+
onOpen();
|
|
272
|
+
};
|
|
273
|
+
const getTarget = () => {
|
|
274
|
+
const triggerEl = triggerRef.current;
|
|
275
|
+
if (triggerEl instanceof Element) {
|
|
276
|
+
return triggerEl.closest('[data-floating-menu-container]') || document.body;
|
|
285
277
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
278
|
+
return document.body;
|
|
279
|
+
};
|
|
280
|
+
const menuBodyId = `overflow-menu-${instanceId.current}__menu-body`;
|
|
281
|
+
const overflowMenuClasses = cx__default["default"](className, `${prefix}--overflow-menu`, {
|
|
282
|
+
[`${prefix}--overflow-menu--open`]: open,
|
|
283
|
+
[`${prefix}--overflow-menu--light`]: light,
|
|
284
|
+
[`${prefix}--overflow-menu--${size}`]: size
|
|
285
|
+
});
|
|
286
|
+
const overflowMenuOptionsClasses = cx__default["default"](menuOptionsClass, `${prefix}--overflow-menu-options`, {
|
|
287
|
+
[`${prefix}--overflow-menu--flip`]: flipped,
|
|
288
|
+
[`${prefix}--overflow-menu-options--open`]: open,
|
|
289
|
+
[`${prefix}--overflow-menu-options--light`]: light,
|
|
290
|
+
[`${prefix}--overflow-menu-options--${size}`]: size
|
|
291
|
+
});
|
|
292
|
+
const overflowMenuIconClasses = cx__default["default"](`${prefix}--overflow-menu__icon`, iconClass);
|
|
293
|
+
const childrenWithProps = React.Children.toArray(children).map((child, index) => {
|
|
294
|
+
if (/*#__PURE__*/React.isValidElement(child)) {
|
|
295
|
+
const childElement = child;
|
|
296
|
+
return /*#__PURE__*/React.cloneElement(childElement, {
|
|
297
|
+
closeMenu: childElement.props.closeMenu || closeMenuAndFocus,
|
|
298
|
+
handleOverflowMenuItemFocus,
|
|
299
|
+
ref: el => {
|
|
300
|
+
menuItemRefs.current[index] = el;
|
|
301
|
+
},
|
|
302
|
+
index
|
|
293
303
|
});
|
|
294
304
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
} = this.props;
|
|
342
|
-
const {
|
|
343
|
-
open = false
|
|
344
|
-
} = this.state;
|
|
345
|
-
const overflowMenuClasses = cx__default["default"](this.props.className, `${prefix}--overflow-menu`, {
|
|
346
|
-
[`${prefix}--overflow-menu--open`]: open,
|
|
347
|
-
[`${prefix}--overflow-menu--light`]: light,
|
|
348
|
-
[`${prefix}--overflow-menu--${size}`]: size
|
|
349
|
-
});
|
|
350
|
-
const overflowMenuOptionsClasses = cx__default["default"](menuOptionsClass, `${prefix}--overflow-menu-options`, {
|
|
351
|
-
[`${prefix}--overflow-menu--flip`]: this.props.flipped,
|
|
352
|
-
[`${prefix}--overflow-menu-options--open`]: open,
|
|
353
|
-
[`${prefix}--overflow-menu-options--light`]: light,
|
|
354
|
-
[`${prefix}--overflow-menu-options--${size}`]: size
|
|
355
|
-
});
|
|
356
|
-
const overflowMenuIconClasses = cx__default["default"](`${prefix}--overflow-menu__icon`, iconClass);
|
|
357
|
-
const childrenWithProps = React__default["default"].Children.toArray(children).map((child, index) => /*#__PURE__*/React__default["default"].isValidElement(child) ? /*#__PURE__*/React__default["default"].cloneElement(child, {
|
|
358
|
-
// @ts-expect-error: PropTypes are not expressive enough to cover this case
|
|
359
|
-
closeMenu: child.props.closeMenu || this.closeMenuAndFocus,
|
|
360
|
-
handleOverflowMenuItemFocus: this.handleOverflowMenuItemFocus,
|
|
361
|
-
ref: e => {
|
|
362
|
-
this[`overflowMenuItem${index}`] = e;
|
|
363
|
-
},
|
|
364
|
-
index
|
|
365
|
-
}) : null);
|
|
366
|
-
const menuBodyId = `overflow-menu-${this.instanceId}__menu-body`;
|
|
367
|
-
const menuBody = /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
368
|
-
className: overflowMenuOptionsClasses,
|
|
369
|
-
tabIndex: -1,
|
|
370
|
-
role: "menu",
|
|
371
|
-
"aria-label": ariaLabel || deprecatedAriaLabel,
|
|
372
|
-
onKeyDown: this.handleKeyPress,
|
|
373
|
-
id: menuBodyId
|
|
374
|
-
}, childrenWithProps);
|
|
375
|
-
const wrappedMenuBody = /*#__PURE__*/React__default["default"].createElement(FloatingMenu.FloatingMenu, {
|
|
376
|
-
focusTrap: focusTrap,
|
|
377
|
-
triggerRef: this._triggerRef,
|
|
378
|
-
menuDirection: direction,
|
|
379
|
-
menuOffset: flipped ? menuOffsetFlip : menuOffset,
|
|
380
|
-
menuRef: this._bindMenuBody,
|
|
381
|
-
flipped: this.props.flipped,
|
|
382
|
-
target: this._getTarget,
|
|
383
|
-
onPlace: this._handlePlace,
|
|
384
|
-
selectorPrimaryFocus: this.props.selectorPrimaryFocus
|
|
385
|
-
}, /*#__PURE__*/React__default["default"].cloneElement(menuBody, {
|
|
386
|
-
'data-floating-menu-direction': direction
|
|
387
|
-
}));
|
|
388
|
-
const iconProps = {
|
|
389
|
-
className: overflowMenuIconClasses,
|
|
390
|
-
'aria-label': iconDescription
|
|
391
|
-
};
|
|
392
|
-
return /*#__PURE__*/React__default["default"].createElement(ClickListener["default"], {
|
|
393
|
-
onClickOutside: this.handleClickOutside
|
|
394
|
-
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
395
|
-
className: `${prefix}--overflow-menu__wrapper`,
|
|
396
|
-
"aria-owns": open ? menuBodyId : undefined
|
|
397
|
-
}, /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({}, other, {
|
|
398
|
-
type: "button",
|
|
399
|
-
"aria-haspopup": true,
|
|
400
|
-
"aria-expanded": open,
|
|
401
|
-
"aria-controls": open ? menuBodyId : undefined,
|
|
402
|
-
className: overflowMenuClasses,
|
|
403
|
-
onClick: this.handleClick,
|
|
404
|
-
id: id,
|
|
405
|
-
ref: mergeRefs["default"](this._triggerRef, ref),
|
|
406
|
-
size: size,
|
|
407
|
-
label: iconDescription,
|
|
408
|
-
kind: "ghost"
|
|
409
|
-
}), /*#__PURE__*/React__default["default"].createElement(IconElement, iconProps)), open && this.state.hasMountedTrigger && wrappedMenuBody));
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
_rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
|
|
305
|
+
return null;
|
|
306
|
+
});
|
|
307
|
+
const menuBody = /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
308
|
+
className: overflowMenuOptionsClasses,
|
|
309
|
+
tabIndex: -1,
|
|
310
|
+
role: "menu",
|
|
311
|
+
"aria-label": ariaLabel || deprecatedAriaLabel,
|
|
312
|
+
onKeyDown: handleKeyPress,
|
|
313
|
+
id: menuBodyId
|
|
314
|
+
}, childrenWithProps);
|
|
315
|
+
const wrappedMenuBody = /*#__PURE__*/React__default["default"].createElement(FloatingMenu.FloatingMenu, {
|
|
316
|
+
focusTrap: focusTrap,
|
|
317
|
+
triggerRef: triggerRef,
|
|
318
|
+
menuDirection: direction,
|
|
319
|
+
menuOffset: flipped ? menuOffsetFlip : menuOffset,
|
|
320
|
+
menuRef: bindMenuBody,
|
|
321
|
+
flipped: flipped,
|
|
322
|
+
target: getTarget,
|
|
323
|
+
onPlace: handlePlace,
|
|
324
|
+
selectorPrimaryFocus: selectorPrimaryFocus
|
|
325
|
+
}, /*#__PURE__*/React.cloneElement(menuBody, {
|
|
326
|
+
'data-floating-menu-direction': direction
|
|
327
|
+
}));
|
|
328
|
+
return /*#__PURE__*/React__default["default"].createElement(ClickListener["default"], {
|
|
329
|
+
onClickOutside: handleClickOutside
|
|
330
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
331
|
+
className: `${prefix}--overflow-menu__wrapper`,
|
|
332
|
+
"aria-owns": open ? menuBodyId : undefined
|
|
333
|
+
}, /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({}, other, {
|
|
334
|
+
type: "button",
|
|
335
|
+
"aria-haspopup": true,
|
|
336
|
+
"aria-expanded": open,
|
|
337
|
+
"aria-controls": open ? menuBodyId : undefined,
|
|
338
|
+
className: overflowMenuClasses,
|
|
339
|
+
onClick: handleClick,
|
|
340
|
+
id: id,
|
|
341
|
+
ref: mergeRefs["default"](triggerRef, ref),
|
|
342
|
+
size: size,
|
|
343
|
+
label: iconDescription,
|
|
344
|
+
kind: "ghost"
|
|
345
|
+
}), /*#__PURE__*/React__default["default"].createElement(IconElement, {
|
|
346
|
+
className: overflowMenuIconClasses,
|
|
347
|
+
"aria-label": iconDescription
|
|
348
|
+
})), open && hasMountedTrigger && wrappedMenuBody));
|
|
349
|
+
});
|
|
350
|
+
OverflowMenu.propTypes = {
|
|
413
351
|
/**
|
|
414
352
|
* Specify a label to be read by screen readers on the container node
|
|
415
353
|
*/
|
|
@@ -460,15 +398,15 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
|
|
|
460
398
|
* The adjustment in position applied to the floating menu.
|
|
461
399
|
*/
|
|
462
400
|
menuOffset: PropTypes__default["default"].oneOfType([PropTypes__default["default"].shape({
|
|
463
|
-
top: PropTypes__default["default"].number,
|
|
464
|
-
left: PropTypes__default["default"].number
|
|
401
|
+
top: PropTypes__default["default"].number.isRequired,
|
|
402
|
+
left: PropTypes__default["default"].number.isRequired
|
|
465
403
|
}), PropTypes__default["default"].func]),
|
|
466
404
|
/**
|
|
467
405
|
* The adjustment in position applied to the floating menu.
|
|
468
406
|
*/
|
|
469
407
|
menuOffsetFlip: PropTypes__default["default"].oneOfType([PropTypes__default["default"].shape({
|
|
470
|
-
top: PropTypes__default["default"].number,
|
|
471
|
-
left: PropTypes__default["default"].number
|
|
408
|
+
top: PropTypes__default["default"].number.isRequired,
|
|
409
|
+
left: PropTypes__default["default"].number.isRequired
|
|
472
410
|
}), PropTypes__default["default"].func]),
|
|
473
411
|
/**
|
|
474
412
|
* The class to apply to the menu options
|
|
@@ -501,6 +439,7 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
|
|
|
501
439
|
/**
|
|
502
440
|
* A component used to render an icon.
|
|
503
441
|
*/
|
|
442
|
+
// @ts-expect-error: PropTypes are not expressive enough to cover this case
|
|
504
443
|
renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
|
|
505
444
|
/**
|
|
506
445
|
* Specify a CSS selector that matches the DOM element that should
|
|
@@ -511,15 +450,8 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
|
|
|
511
450
|
* Specify the size of the OverflowMenu. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
|
|
512
451
|
*/
|
|
513
452
|
size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg'])
|
|
514
|
-
}
|
|
515
|
-
_rollupPluginBabelHelpers.defineProperty(OverflowMenu, "contextType", usePrefix.PrefixContext);
|
|
516
|
-
(() => {
|
|
517
|
-
const forwardRef = (props, ref) => /*#__PURE__*/React__default["default"].createElement(OverflowMenu, _rollupPluginBabelHelpers["extends"]({}, props, {
|
|
518
|
-
innerRef: ref
|
|
519
|
-
}));
|
|
520
|
-
forwardRef.displayName = 'OverflowMenu';
|
|
521
|
-
return /*#__PURE__*/React__default["default"].forwardRef(forwardRef);
|
|
522
|
-
})();
|
|
453
|
+
};
|
|
523
454
|
|
|
524
455
|
exports.OverflowMenu = OverflowMenu;
|
|
456
|
+
exports["default"] = OverflowMenu;
|
|
525
457
|
exports.getMenuOffset = getMenuOffset;
|