@contentful/f36-menu 4.0.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/LICENSE.md +7 -0
- package/README.mdx +159 -0
- package/dist/main.js +714 -0
- package/dist/main.js.map +1 -0
- package/dist/module.js +700 -0
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +627 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +39 -0
package/dist/module.js
ADDED
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import $eBAEH$react, {useRef as $eBAEH$useRef, useEffect as $eBAEH$useEffect, useCallback as $eBAEH$useCallback, useMemo as $eBAEH$useMemo, useState as $eBAEH$useState} from "react";
|
|
2
|
+
import {useId as $eBAEH$useId, mergeRefs as $eBAEH$mergeRefs} from "@contentful/f36-core";
|
|
3
|
+
import {Popover as $eBAEH$Popover} from "@contentful/f36-popover";
|
|
4
|
+
import {cx as $eBAEH$cx, css as $eBAEH$css} from "emotion";
|
|
5
|
+
import $eBAEH$contentfulf36tokens from "@contentful/f36-tokens";
|
|
6
|
+
import {SectionHeading as $eBAEH$SectionHeading} from "@contentful/f36-typography";
|
|
7
|
+
import {ChevronRightIcon as $eBAEH$ChevronRightIcon} from "@contentful/f36-icons";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const $d3c8cb97d16f8911$var$ARROW_KEY_TYPES = {
|
|
13
|
+
vertical: {
|
|
14
|
+
prev: 'ArrowUp',
|
|
15
|
+
next: 'ArrowDown'
|
|
16
|
+
},
|
|
17
|
+
horizontal: {
|
|
18
|
+
prev: 'ArrowLeft',
|
|
19
|
+
next: 'ArrowRight'
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const $d3c8cb97d16f8911$export$e8d01079a7f85a7 = ({ itemsContainerRef: itemsContainerRef , itemsSelector: itemsSelector , keyType: keyType = 'vertical' })=>{
|
|
23
|
+
const [focusedIndex, setFocusedIndex] = $eBAEH$useState(0);
|
|
24
|
+
const handleArrowsKeyDown = $eBAEH$useCallback((event)=>{
|
|
25
|
+
const container = itemsContainerRef.current;
|
|
26
|
+
if (!container) return;
|
|
27
|
+
const items = container.querySelectorAll(itemsSelector);
|
|
28
|
+
if (items.length === 0) return;
|
|
29
|
+
const lastItemIndex = items.length - 1;
|
|
30
|
+
const focusFirstItem = ()=>setFocusedIndex(0)
|
|
31
|
+
;
|
|
32
|
+
const focusLastItem = ()=>setFocusedIndex(lastItemIndex)
|
|
33
|
+
;
|
|
34
|
+
const focusNextItem = ()=>{
|
|
35
|
+
if (focusedIndex === lastItemIndex) focusFirstItem();
|
|
36
|
+
else setFocusedIndex(focusedIndex + 1);
|
|
37
|
+
};
|
|
38
|
+
const focusPrevItem = ()=>{
|
|
39
|
+
if (focusedIndex === 0) focusLastItem();
|
|
40
|
+
else setFocusedIndex(focusedIndex - 1);
|
|
41
|
+
};
|
|
42
|
+
const keyToFnMap = {
|
|
43
|
+
[$d3c8cb97d16f8911$var$ARROW_KEY_TYPES[keyType].next]: focusNextItem,
|
|
44
|
+
[$d3c8cb97d16f8911$var$ARROW_KEY_TYPES[keyType].prev]: focusPrevItem
|
|
45
|
+
};
|
|
46
|
+
const fn = keyToFnMap[event.key];
|
|
47
|
+
if (fn) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
fn();
|
|
50
|
+
}
|
|
51
|
+
}, [
|
|
52
|
+
focusedIndex,
|
|
53
|
+
itemsSelector,
|
|
54
|
+
itemsContainerRef,
|
|
55
|
+
keyType
|
|
56
|
+
]);
|
|
57
|
+
return {
|
|
58
|
+
focusedIndex: focusedIndex,
|
|
59
|
+
handleArrowsKeyDown: handleArrowsKeyDown,
|
|
60
|
+
setFocusedIndex: setFocusedIndex
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const $c66e4ce1999d7489$var$MenuContext = $eBAEH$react.createContext(undefined);
|
|
68
|
+
const $c66e4ce1999d7489$export$21c7ab35b39f78ec = ()=>{
|
|
69
|
+
const context = $eBAEH$react.useContext($c66e4ce1999d7489$var$MenuContext);
|
|
70
|
+
if (context === undefined) throw new Error('useMenuContext must be used within a MenuContextProvider');
|
|
71
|
+
return context;
|
|
72
|
+
};
|
|
73
|
+
const $c66e4ce1999d7489$export$2cad3fd48ac06579 = $c66e4ce1999d7489$var$MenuContext.Provider;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
const $815624c5c2e33d2d$var$MENU_ITEMS_SELECTOR = '[role="menuitem"]:not(:disabled)';
|
|
77
|
+
function $815624c5c2e33d2d$export$d9b273488cd8ce6f(props) {
|
|
78
|
+
const { closeOnSelect: closeOnSelect = true , closeOnBlur: closeOnBlur = true , closeOnEsc: closeOnEsc = true , children: children , onOpen: onOpen , ...otherProps } = props;
|
|
79
|
+
const { isOpen: isOpen , handleOpen: handleOpen , handleClose: handleClose , isControlled: isControlled } = $815624c5c2e33d2d$var$useMenuOpenState(props);
|
|
80
|
+
const triggerRef = $eBAEH$useRef(null);
|
|
81
|
+
const menuListRef = $eBAEH$useRef(null);
|
|
82
|
+
const menuId = $eBAEH$useId(null, 'menu');
|
|
83
|
+
const { focusedIndex: focusedIndex , handleArrowsKeyDown: handleArrowsKeyDown , setFocusedIndex: setFocusedIndex } = $d3c8cb97d16f8911$export$e8d01079a7f85a7({
|
|
84
|
+
itemsContainerRef: menuListRef,
|
|
85
|
+
itemsSelector: $815624c5c2e33d2d$var$MENU_ITEMS_SELECTOR
|
|
86
|
+
});
|
|
87
|
+
$eBAEH$useEffect(()=>{
|
|
88
|
+
if (isOpen && menuListRef.current) {
|
|
89
|
+
const menuItems = menuListRef.current.querySelectorAll($815624c5c2e33d2d$var$MENU_ITEMS_SELECTOR);
|
|
90
|
+
if (menuItems.length > 0 && focusedIndex < menuItems.length) // timeout trick to prevent scroll from jumping
|
|
91
|
+
// when the popover is not positioned correctly yet in the opening phase
|
|
92
|
+
setTimeout(()=>{
|
|
93
|
+
menuItems[focusedIndex].focus({
|
|
94
|
+
preventScroll: false
|
|
95
|
+
});
|
|
96
|
+
}, 0);
|
|
97
|
+
}
|
|
98
|
+
}, [
|
|
99
|
+
isOpen,
|
|
100
|
+
focusedIndex
|
|
101
|
+
]);
|
|
102
|
+
const focusMenuItem = $eBAEH$useCallback((item)=>{
|
|
103
|
+
const menuItems = menuListRef.current.querySelectorAll($815624c5c2e33d2d$var$MENU_ITEMS_SELECTOR);
|
|
104
|
+
const itemIndex = [
|
|
105
|
+
...menuItems
|
|
106
|
+
].findIndex((menuItem)=>item === menuItem
|
|
107
|
+
);
|
|
108
|
+
if (itemIndex !== -1) setFocusedIndex(itemIndex);
|
|
109
|
+
}, [
|
|
110
|
+
setFocusedIndex
|
|
111
|
+
]);
|
|
112
|
+
const closeAndFocusTrigger = $eBAEH$useCallback(()=>{
|
|
113
|
+
var ref;
|
|
114
|
+
handleClose();
|
|
115
|
+
(ref = triggerRef.current) === null || ref === void 0 ? void 0 : ref.focus({
|
|
116
|
+
preventScroll: true
|
|
117
|
+
});
|
|
118
|
+
}, [
|
|
119
|
+
handleClose
|
|
120
|
+
]);
|
|
121
|
+
const handleMenuListKeyDown = $eBAEH$useCallback((event)=>{
|
|
122
|
+
if (event.key === 'Tab') {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
closeAndFocusTrigger();
|
|
125
|
+
return;
|
|
126
|
+
} // we don't want to propagate other keydown events except `Tab`
|
|
127
|
+
event.stopPropagation();
|
|
128
|
+
if (event.key === 'ArrowLeft') {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
closeAndFocusTrigger();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
handleArrowsKeyDown(event);
|
|
134
|
+
}, [
|
|
135
|
+
closeAndFocusTrigger,
|
|
136
|
+
handleArrowsKeyDown
|
|
137
|
+
]);
|
|
138
|
+
const contextValue = $eBAEH$useMemo(()=>{
|
|
139
|
+
return {
|
|
140
|
+
isOpen: isOpen,
|
|
141
|
+
menuId: menuId,
|
|
142
|
+
focusMenuItem: focusMenuItem,
|
|
143
|
+
getTriggerProps: (_props = {
|
|
144
|
+
}, _ref = null)=>{
|
|
145
|
+
return {
|
|
146
|
+
onClick: (event)=>{
|
|
147
|
+
var ref;
|
|
148
|
+
// if the user made component controlled by providing isOpen prop
|
|
149
|
+
// but onOpen callback is not provided, we won't add toggle logic
|
|
150
|
+
// to the trigger component. So they can make any toggle logic on their own.
|
|
151
|
+
const isFullyControlled = isControlled && !onOpen;
|
|
152
|
+
if (!isFullyControlled) {
|
|
153
|
+
if (isOpen) handleClose();
|
|
154
|
+
else handleOpen();
|
|
155
|
+
}
|
|
156
|
+
(ref = _props.onClick) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
157
|
+
},
|
|
158
|
+
ref: $eBAEH$mergeRefs(triggerRef, _ref)
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
getMenuListProps: (_props = {
|
|
162
|
+
}, _ref = null)=>{
|
|
163
|
+
return {
|
|
164
|
+
ref: $eBAEH$mergeRefs(menuListRef, _ref),
|
|
165
|
+
onKeyDown: (event)=>{
|
|
166
|
+
var ref;
|
|
167
|
+
handleMenuListKeyDown(event);
|
|
168
|
+
(ref = _props.onKeyDown) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
169
|
+
},
|
|
170
|
+
onBlur: (event)=>{
|
|
171
|
+
var ref, ref1, ref2, ref3;
|
|
172
|
+
(ref = _props.onBlur) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
173
|
+
if (!closeOnBlur) return;
|
|
174
|
+
const relatedTarget = event.relatedTarget;
|
|
175
|
+
const targetIsMenu = menuListRef.current === relatedTarget || ((ref1 = menuListRef.current) === null || ref1 === void 0 ? void 0 : ref1.contains(relatedTarget));
|
|
176
|
+
const targetIsTrigger = triggerRef.current === relatedTarget || ((ref2 = triggerRef.current) === null || ref2 === void 0 ? void 0 : ref2.contains(relatedTarget));
|
|
177
|
+
const targetIsSubmenu = (relatedTarget === null || relatedTarget === void 0 ? void 0 : (ref3 = relatedTarget.parentElement) === null || ref3 === void 0 ? void 0 : ref3.dataset.parentMenu) === menuId;
|
|
178
|
+
if (targetIsMenu || targetIsTrigger || targetIsSubmenu) {
|
|
179
|
+
event.stopPropagation();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
handleClose();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
getMenuItemProps: (_props = {
|
|
187
|
+
})=>{
|
|
188
|
+
return {
|
|
189
|
+
onClick: (event)=>{
|
|
190
|
+
var ref;
|
|
191
|
+
(ref = _props.onClick) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
192
|
+
const isSubmenuTrigger = Boolean(event.target.getAttribute('aria-haspopup'));
|
|
193
|
+
if (closeOnSelect && !isSubmenuTrigger) closeAndFocusTrigger();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
propsToPropagateToSubmenus: {
|
|
198
|
+
closeOnSelect: closeOnSelect,
|
|
199
|
+
closeOnBlur: closeOnBlur,
|
|
200
|
+
closeOnEsc: closeOnEsc
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, [
|
|
204
|
+
menuId,
|
|
205
|
+
isOpen,
|
|
206
|
+
handleMenuListKeyDown,
|
|
207
|
+
closeOnSelect,
|
|
208
|
+
handleClose,
|
|
209
|
+
handleOpen,
|
|
210
|
+
focusMenuItem,
|
|
211
|
+
closeOnBlur,
|
|
212
|
+
closeOnEsc,
|
|
213
|
+
closeAndFocusTrigger,
|
|
214
|
+
isControlled,
|
|
215
|
+
onOpen
|
|
216
|
+
]);
|
|
217
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($c66e4ce1999d7489$export$2cad3fd48ac06579, {
|
|
218
|
+
value: contextValue
|
|
219
|
+
}, /*#__PURE__*/ $eBAEH$react.createElement($eBAEH$Popover, {
|
|
220
|
+
...otherProps,
|
|
221
|
+
isOpen: isOpen,
|
|
222
|
+
onClose: handleClose,
|
|
223
|
+
id: menuId,
|
|
224
|
+
closeOnEsc: closeOnEsc,
|
|
225
|
+
autoFocus: false,
|
|
226
|
+
closeOnBlur: false
|
|
227
|
+
}, children)));
|
|
228
|
+
}
|
|
229
|
+
const $815624c5c2e33d2d$var$useMenuOpenState = (props)=>{
|
|
230
|
+
const { isOpen: isOpen , defaultIsOpen: defaultIsOpen , onOpen: onOpen , onClose: onClose } = props;
|
|
231
|
+
const [isOpenState, setIsOpen] = $eBAEH$useState(defaultIsOpen || false);
|
|
232
|
+
const isControlled = isOpen !== undefined;
|
|
233
|
+
const isOpenValue = isControlled ? isOpen : isOpenState;
|
|
234
|
+
const handleClose = $eBAEH$useCallback(()=>{
|
|
235
|
+
if (!isControlled) setIsOpen(false);
|
|
236
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
237
|
+
}, [
|
|
238
|
+
isControlled,
|
|
239
|
+
onClose
|
|
240
|
+
]);
|
|
241
|
+
const handleOpen = $eBAEH$useCallback(()=>{
|
|
242
|
+
if (!isControlled) setIsOpen(true);
|
|
243
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
244
|
+
}, [
|
|
245
|
+
isControlled,
|
|
246
|
+
onOpen
|
|
247
|
+
]);
|
|
248
|
+
return {
|
|
249
|
+
isOpen: isOpenValue,
|
|
250
|
+
isControlled: isControlled,
|
|
251
|
+
handleClose: handleClose,
|
|
252
|
+
handleOpen: handleOpen
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
const $5f642d41e782730b$var$SubmenuContext = $eBAEH$react.createContext(undefined);
|
|
262
|
+
const $5f642d41e782730b$export$958673a266cbe049 = ()=>{
|
|
263
|
+
const context = $eBAEH$react.useContext($5f642d41e782730b$var$SubmenuContext);
|
|
264
|
+
return context;
|
|
265
|
+
};
|
|
266
|
+
const $5f642d41e782730b$export$81b3dbd1f003f0c7 = $5f642d41e782730b$var$SubmenuContext.Provider;
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
const $e1ca220e91193b42$export$396ce14bde1b7929 = ()=>{
|
|
273
|
+
return(/*#__PURE__*/ $eBAEH$css({
|
|
274
|
+
position: 'sticky',
|
|
275
|
+
top: 0,
|
|
276
|
+
left: 0,
|
|
277
|
+
backgroundColor: $eBAEH$contentfulf36tokens.colorWhite,
|
|
278
|
+
borderBottom: `1px solid ${$eBAEH$contentfulf36tokens.gray300}`,
|
|
279
|
+
padding: `${$eBAEH$contentfulf36tokens.spacingXs} 0`,
|
|
280
|
+
zIndex: 1001
|
|
281
|
+
}));
|
|
282
|
+
};
|
|
283
|
+
const $e1ca220e91193b42$export$fd3dbc8a890448f = ()=>{
|
|
284
|
+
return(/*#__PURE__*/ $eBAEH$css({
|
|
285
|
+
position: 'sticky',
|
|
286
|
+
bottom: 0,
|
|
287
|
+
left: 0,
|
|
288
|
+
backgroundColor: $eBAEH$contentfulf36tokens.colorWhite,
|
|
289
|
+
borderTop: `1px solid ${$eBAEH$contentfulf36tokens.gray300}`,
|
|
290
|
+
padding: `${$eBAEH$contentfulf36tokens.spacingXs} 0`,
|
|
291
|
+
zIndex: 1001
|
|
292
|
+
}));
|
|
293
|
+
};
|
|
294
|
+
const $e1ca220e91193b42$export$10ce7613b0465b57 = (props)=>({
|
|
295
|
+
container: /*#__PURE__*/ $eBAEH$css({
|
|
296
|
+
overflowY: 'auto',
|
|
297
|
+
position: 'relative',
|
|
298
|
+
padding: 0,
|
|
299
|
+
paddingTop: props.hasStickyHeader ? 0 : $eBAEH$contentfulf36tokens.spacingXs,
|
|
300
|
+
paddingBottom: props.hasStickyFooter ? 0 : $eBAEH$contentfulf36tokens.spacingXs
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
;
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
const $042de7e263db0945$export$77451990ddb9d17c = (props)=>{
|
|
310
|
+
const { children: children , testId: testId = 'cf-ui-menu-list-header' , className: className , ...otherProps } = props;
|
|
311
|
+
const styles = $e1ca220e91193b42$export$396ce14bde1b7929();
|
|
312
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement("div", {
|
|
313
|
+
"data-test-id": testId,
|
|
314
|
+
className: $eBAEH$cx(styles, className),
|
|
315
|
+
...otherProps
|
|
316
|
+
}, children));
|
|
317
|
+
};
|
|
318
|
+
$042de7e263db0945$export$77451990ddb9d17c.displayName = 'MenuListHeader';
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
const $5a5dcb1ec14dca9d$export$3e8a81e7ad0650f4 = (props)=>{
|
|
325
|
+
const { children: children , testId: testId = 'cf-ui-menu-list-footer' , className: className , ...otherProps } = props;
|
|
326
|
+
const styles = $e1ca220e91193b42$export$fd3dbc8a890448f();
|
|
327
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement("div", {
|
|
328
|
+
"data-test-id": testId,
|
|
329
|
+
className: $eBAEH$cx(styles, className),
|
|
330
|
+
...otherProps
|
|
331
|
+
}, children));
|
|
332
|
+
};
|
|
333
|
+
$5a5dcb1ec14dca9d$export$3e8a81e7ad0650f4.displayName = 'MenuListFooter';
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
function $511d273ec51beeae$var$assertChild(child) {
|
|
337
|
+
var ref;
|
|
338
|
+
return Boolean(child === null || child === void 0 ? void 0 : (ref = child.type) === null || ref === void 0 ? void 0 : ref.displayName);
|
|
339
|
+
}
|
|
340
|
+
const $511d273ec51beeae$var$_MenuList = (props, ref)=>{
|
|
341
|
+
const { children: children , testId: testId = 'cf-ui-menu-list' , className: className , ...otherProps } = props;
|
|
342
|
+
const { getMenuListProps: getMenuListProps } = $c66e4ce1999d7489$export$21c7ab35b39f78ec();
|
|
343
|
+
const submenuContext = $5f642d41e782730b$export$958673a266cbe049();
|
|
344
|
+
let header = null;
|
|
345
|
+
let footer = null;
|
|
346
|
+
const items = [];
|
|
347
|
+
$eBAEH$react.Children.forEach(children, (child)=>{
|
|
348
|
+
let appendChild = true;
|
|
349
|
+
if ($511d273ec51beeae$var$assertChild(child)) {
|
|
350
|
+
if (child.type.displayName === $042de7e263db0945$export$77451990ddb9d17c.displayName) {
|
|
351
|
+
header = child;
|
|
352
|
+
appendChild = false;
|
|
353
|
+
} else if (child.type.displayName === $5a5dcb1ec14dca9d$export$3e8a81e7ad0650f4.displayName) {
|
|
354
|
+
footer = child;
|
|
355
|
+
appendChild = false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (appendChild) items.push(child);
|
|
359
|
+
});
|
|
360
|
+
const styles = $e1ca220e91193b42$export$10ce7613b0465b57({
|
|
361
|
+
hasStickyHeader: Boolean(header),
|
|
362
|
+
hasStickyFooter: Boolean(footer)
|
|
363
|
+
});
|
|
364
|
+
const extendedOtherProps = submenuContext ? submenuContext.getSubmenuListProps(otherProps) : otherProps;
|
|
365
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($eBAEH$Popover.Content, {
|
|
366
|
+
role: "menu",
|
|
367
|
+
...extendedOtherProps,
|
|
368
|
+
...getMenuListProps(extendedOtherProps, ref),
|
|
369
|
+
className: $eBAEH$cx(styles.container, className),
|
|
370
|
+
testId: testId
|
|
371
|
+
}, header, items, footer));
|
|
372
|
+
};
|
|
373
|
+
const $511d273ec51beeae$export$d4c4e98c5044dc8 = /*#__PURE__*/ $eBAEH$react.forwardRef($511d273ec51beeae$var$_MenuList);
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
const $0cc53a77e90ceec6$export$adaad53e003c74d0 = ()=>{
|
|
386
|
+
return {
|
|
387
|
+
root: /*#__PURE__*/ $eBAEH$css({
|
|
388
|
+
display: 'block',
|
|
389
|
+
width: '100%',
|
|
390
|
+
background: 'none',
|
|
391
|
+
border: 0,
|
|
392
|
+
margin: 0,
|
|
393
|
+
outline: 'none',
|
|
394
|
+
fontSize: $eBAEH$contentfulf36tokens.fontSizeM,
|
|
395
|
+
lineHeight: $eBAEH$contentfulf36tokens.lineHeightM,
|
|
396
|
+
fontWeight: $eBAEH$contentfulf36tokens.fontWeightNormal,
|
|
397
|
+
position: 'relative',
|
|
398
|
+
textAlign: 'left',
|
|
399
|
+
padding: `${$eBAEH$contentfulf36tokens.spacingXs} ${$eBAEH$contentfulf36tokens.spacingM}`,
|
|
400
|
+
wordBreak: 'break-word',
|
|
401
|
+
whiteSpace: 'break-spaces',
|
|
402
|
+
cursor: 'pointer',
|
|
403
|
+
hyphens: 'auto',
|
|
404
|
+
minWidth: '150px',
|
|
405
|
+
textDecoration: 'none',
|
|
406
|
+
color: $eBAEH$contentfulf36tokens.gray800,
|
|
407
|
+
'&:focus, &:hover': {
|
|
408
|
+
backgroundColor: $eBAEH$contentfulf36tokens.gray100
|
|
409
|
+
},
|
|
410
|
+
'&:active': {
|
|
411
|
+
backgroundColor: $eBAEH$contentfulf36tokens.gray200
|
|
412
|
+
},
|
|
413
|
+
'&:disabled': {
|
|
414
|
+
opacity: 0.5,
|
|
415
|
+
cursor: 'auto'
|
|
416
|
+
}
|
|
417
|
+
})
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
const $ea346231d142cd67$var$MENU_ITEM_DEFAULT_TAG = 'button';
|
|
423
|
+
function $ea346231d142cd67$var$_MenuItem(props, ref) {
|
|
424
|
+
const { testId: testId , className: className , as: as , isInitiallyFocused: isInitiallyFocused , ...otherProps } = props;
|
|
425
|
+
const id = $eBAEH$useId(null, 'menu-item');
|
|
426
|
+
const itemTestId = testId || `cf-ui-${id}`;
|
|
427
|
+
const styles = $0cc53a77e90ceec6$export$adaad53e003c74d0();
|
|
428
|
+
const { getMenuItemProps: getMenuItemProps , focusMenuItem: focusMenuItem } = $c66e4ce1999d7489$export$21c7ab35b39f78ec();
|
|
429
|
+
const itemRef = $eBAEH$useRef(null);
|
|
430
|
+
$eBAEH$useEffect(()=>{
|
|
431
|
+
if (isInitiallyFocused && itemRef.current) focusMenuItem(itemRef.current);
|
|
432
|
+
}, [
|
|
433
|
+
isInitiallyFocused,
|
|
434
|
+
focusMenuItem
|
|
435
|
+
]);
|
|
436
|
+
const Element = as !== null && as !== void 0 ? as : $ea346231d142cd67$var$MENU_ITEM_DEFAULT_TAG;
|
|
437
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement(Element, {
|
|
438
|
+
role: "menuitem",
|
|
439
|
+
...otherProps,
|
|
440
|
+
...getMenuItemProps(otherProps),
|
|
441
|
+
className: $eBAEH$cx(styles.root, className),
|
|
442
|
+
"data-test-id": itemTestId,
|
|
443
|
+
ref: $eBAEH$mergeRefs(itemRef, ref),
|
|
444
|
+
tabIndex: -1
|
|
445
|
+
}, props.children));
|
|
446
|
+
}
|
|
447
|
+
const $ea346231d142cd67$export$2ce376c2cc3355c8 = /*#__PURE__*/ $eBAEH$react.forwardRef($ea346231d142cd67$var$_MenuItem);
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
const $94016b6f927b504d$export$27d2ad3c5815583e = (props)=>{
|
|
454
|
+
const child = $eBAEH$react.Children.only(props.children);
|
|
455
|
+
const { getTriggerProps: getTriggerProps } = $c66e4ce1999d7489$export$21c7ab35b39f78ec();
|
|
456
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($eBAEH$Popover.Trigger, null, /*#__PURE__*/ $eBAEH$react.cloneElement(child, {
|
|
457
|
+
...getTriggerProps(child.props, child.ref),
|
|
458
|
+
['aria-haspopup']: 'menu'
|
|
459
|
+
})));
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
const $90fd1006b83bc4dd$export$4605da6f9a8ef405 = ()=>/*#__PURE__*/ $eBAEH$css({
|
|
468
|
+
border: 'none',
|
|
469
|
+
width: '100%',
|
|
470
|
+
height: '1px',
|
|
471
|
+
background: $eBAEH$contentfulf36tokens.gray300,
|
|
472
|
+
margin: `${$eBAEH$contentfulf36tokens.spacingXs} 0`
|
|
473
|
+
})
|
|
474
|
+
;
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
const $a6a319b65dbbd900$export$acb07b4664ac227c = (props)=>{
|
|
478
|
+
const { children: children , testId: testId = 'cf-ui-menu-divider' , className: className , ...otherProps } = props;
|
|
479
|
+
const styles = $90fd1006b83bc4dd$export$4605da6f9a8ef405();
|
|
480
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement("hr", {
|
|
481
|
+
"aria-orientation": "horizontal",
|
|
482
|
+
"data-test-id": testId,
|
|
483
|
+
className: $eBAEH$cx(styles, className),
|
|
484
|
+
...otherProps
|
|
485
|
+
}));
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
const $7f43fb9a4d140447$export$2698fa8b3a0a79e6 = ()=>/*#__PURE__*/ $eBAEH$css({
|
|
494
|
+
textAlign: 'left',
|
|
495
|
+
padding: `${$eBAEH$contentfulf36tokens.spacingXs} ${$eBAEH$contentfulf36tokens.spacingM}`,
|
|
496
|
+
lineHeight: $eBAEH$contentfulf36tokens.lineHeightM,
|
|
497
|
+
'hr + &': {
|
|
498
|
+
marginTop: '-8px'
|
|
499
|
+
}
|
|
500
|
+
})
|
|
501
|
+
;
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
const $7c6385c774644580$export$5d1e6c648985631e = (props)=>{
|
|
506
|
+
const { children: children , testId: testId = 'cf-ui-menu-section-title' , className: className , ...otherProps } = props;
|
|
507
|
+
const styles = $7f43fb9a4d140447$export$2698fa8b3a0a79e6();
|
|
508
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($eBAEH$SectionHeading // Techincally, menus cannot contain headings according to ARIA.
|
|
509
|
+
, {
|
|
510
|
+
// We hide the heading from assistive technology, and only use it
|
|
511
|
+
// as a label
|
|
512
|
+
"aria-hidden": "true",
|
|
513
|
+
testId: testId,
|
|
514
|
+
className: $eBAEH$cx(styles, className),
|
|
515
|
+
marginBottom: "none",
|
|
516
|
+
...otherProps
|
|
517
|
+
}, children));
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
const $407bba9f98210b35$var$SUBMENU_OFFSET = [
|
|
527
|
+
-8,
|
|
528
|
+
2
|
|
529
|
+
];
|
|
530
|
+
const $407bba9f98210b35$export$49229ebf838c159b = (props)=>{
|
|
531
|
+
const { onClose: onClose , onOpen: onOpen , ...otherProps } = props;
|
|
532
|
+
const { isOpen: isParentMenuOpen , menuId: menuId , propsToPropagateToSubmenus: propsToPropagateToSubmenus } = $c66e4ce1999d7489$export$21c7ab35b39f78ec();
|
|
533
|
+
const triggerRef = $eBAEH$useRef(null);
|
|
534
|
+
const mouseLeaveTimerRef = $eBAEH$useRef(null);
|
|
535
|
+
const [isOpen, setIsOpen] = $eBAEH$useState(false);
|
|
536
|
+
const handleOpen = $eBAEH$useCallback(()=>{
|
|
537
|
+
setIsOpen(true);
|
|
538
|
+
window.clearTimeout(mouseLeaveTimerRef.current);
|
|
539
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
540
|
+
}, [
|
|
541
|
+
onOpen
|
|
542
|
+
]);
|
|
543
|
+
const handleClose = $eBAEH$useCallback(()=>{
|
|
544
|
+
setIsOpen(false);
|
|
545
|
+
window.clearTimeout(mouseLeaveTimerRef.current);
|
|
546
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
547
|
+
}, [
|
|
548
|
+
onClose
|
|
549
|
+
]);
|
|
550
|
+
const closeAndFocusTrigger = $eBAEH$useCallback(()=>{
|
|
551
|
+
var ref;
|
|
552
|
+
handleClose();
|
|
553
|
+
(ref = triggerRef.current) === null || ref === void 0 ? void 0 : ref.focus({
|
|
554
|
+
preventScroll: true
|
|
555
|
+
});
|
|
556
|
+
}, [
|
|
557
|
+
handleClose
|
|
558
|
+
]);
|
|
559
|
+
$eBAEH$useEffect(()=>{
|
|
560
|
+
// close when parent menu closed
|
|
561
|
+
if (isParentMenuOpen === false) setIsOpen(false);
|
|
562
|
+
}, [
|
|
563
|
+
isParentMenuOpen
|
|
564
|
+
]);
|
|
565
|
+
const contextValue = $eBAEH$useMemo(()=>{
|
|
566
|
+
return {
|
|
567
|
+
isOpen: isOpen,
|
|
568
|
+
getSubmenuListProps: (_props)=>{
|
|
569
|
+
return {
|
|
570
|
+
'data-parent-menu': menuId,
|
|
571
|
+
onMouseOver: (event)=>{
|
|
572
|
+
var ref;
|
|
573
|
+
handleOpen();
|
|
574
|
+
(ref = _props.onMouseOver) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
575
|
+
},
|
|
576
|
+
onMouseLeave: (event)=>{
|
|
577
|
+
var ref;
|
|
578
|
+
closeAndFocusTrigger();
|
|
579
|
+
(ref = _props.onMouseLeave) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
getSubmenuTriggerProps: (_props, _ref)=>{
|
|
584
|
+
return {
|
|
585
|
+
ref: $eBAEH$mergeRefs(triggerRef, _ref),
|
|
586
|
+
onKeyDown: (event)=>{
|
|
587
|
+
var ref;
|
|
588
|
+
if (event.key === 'ArrowRight') {
|
|
589
|
+
event.preventDefault();
|
|
590
|
+
handleOpen();
|
|
591
|
+
}
|
|
592
|
+
(ref = _props.onKeyDown) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
593
|
+
},
|
|
594
|
+
onMouseOver: (event)=>{
|
|
595
|
+
var ref;
|
|
596
|
+
handleOpen();
|
|
597
|
+
(ref = _props.onMouseOver) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
598
|
+
},
|
|
599
|
+
onMouseLeave: (event)=>{
|
|
600
|
+
var ref;
|
|
601
|
+
mouseLeaveTimerRef.current = window.setTimeout(closeAndFocusTrigger, 300);
|
|
602
|
+
(ref = _props.onMouseLeave) === null || ref === void 0 ? void 0 : ref.call(_props, event);
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
}, [
|
|
608
|
+
isOpen,
|
|
609
|
+
menuId,
|
|
610
|
+
handleOpen,
|
|
611
|
+
closeAndFocusTrigger
|
|
612
|
+
]);
|
|
613
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($5f642d41e782730b$export$81b3dbd1f003f0c7, {
|
|
614
|
+
value: contextValue
|
|
615
|
+
}, /*#__PURE__*/ $eBAEH$react.createElement($815624c5c2e33d2d$export$d9b273488cd8ce6f, {
|
|
616
|
+
...propsToPropagateToSubmenus,
|
|
617
|
+
...otherProps,
|
|
618
|
+
isOpen: isOpen,
|
|
619
|
+
onClose: handleClose,
|
|
620
|
+
onOpen: handleOpen,
|
|
621
|
+
placement: "right-start",
|
|
622
|
+
offset: $407bba9f98210b35$var$SUBMENU_OFFSET,
|
|
623
|
+
isAutoalignmentEnabled: false
|
|
624
|
+
})));
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
const $f5b15ecf1bfa860d$export$ce276565acbba1c9 = ()=>{
|
|
637
|
+
return {
|
|
638
|
+
root: ({ isActive: isActive })=>/*#__PURE__*/ $eBAEH$css({
|
|
639
|
+
display: 'flex',
|
|
640
|
+
alignItems: 'center',
|
|
641
|
+
paddingRight: $eBAEH$contentfulf36tokens.spacingXs,
|
|
642
|
+
...isActive ? {
|
|
643
|
+
backgroundColor: $eBAEH$contentfulf36tokens.gray100
|
|
644
|
+
} : {
|
|
645
|
+
}
|
|
646
|
+
})
|
|
647
|
+
,
|
|
648
|
+
content: /*#__PURE__*/ $eBAEH$css({
|
|
649
|
+
marginRight: $eBAEH$contentfulf36tokens.spacingM
|
|
650
|
+
}),
|
|
651
|
+
icon: /*#__PURE__*/ $eBAEH$css({
|
|
652
|
+
name: "1hapt0s",
|
|
653
|
+
styles: "margin-left:auto;fill:currentColor;"
|
|
654
|
+
})
|
|
655
|
+
};
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
const $423d6b42721d64f8$var$_SubmenuTrigger = (props, ref)=>{
|
|
660
|
+
const { className: className , children: children } = props;
|
|
661
|
+
const { getSubmenuTriggerProps: getSubmenuTriggerProps , isOpen: isOpen } = $5f642d41e782730b$export$958673a266cbe049();
|
|
662
|
+
const styles = $f5b15ecf1bfa860d$export$ce276565acbba1c9();
|
|
663
|
+
return(/*#__PURE__*/ $eBAEH$react.createElement($94016b6f927b504d$export$27d2ad3c5815583e, null, /*#__PURE__*/ $eBAEH$react.createElement($ea346231d142cd67$export$2ce376c2cc3355c8, {
|
|
664
|
+
...props,
|
|
665
|
+
...getSubmenuTriggerProps(props, ref),
|
|
666
|
+
className: $eBAEH$cx(styles.root({
|
|
667
|
+
isActive: isOpen
|
|
668
|
+
}), className)
|
|
669
|
+
}, /*#__PURE__*/ $eBAEH$react.createElement("span", {
|
|
670
|
+
className: styles.content
|
|
671
|
+
}, children), /*#__PURE__*/ $eBAEH$react.createElement($eBAEH$ChevronRightIcon, {
|
|
672
|
+
className: styles.icon
|
|
673
|
+
}))));
|
|
674
|
+
};
|
|
675
|
+
const $423d6b42721d64f8$export$ecabc99eeffab7ca = /*#__PURE__*/ $eBAEH$react.forwardRef($423d6b42721d64f8$var$_SubmenuTrigger);
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
const $e1cb616583324cbb$export$d9b273488cd8ce6f = $815624c5c2e33d2d$export$d9b273488cd8ce6f;
|
|
679
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.List = $511d273ec51beeae$export$d4c4e98c5044dc8;
|
|
680
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.ListHeader = $042de7e263db0945$export$77451990ddb9d17c;
|
|
681
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.ListFooter = $5a5dcb1ec14dca9d$export$3e8a81e7ad0650f4;
|
|
682
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.Item = $ea346231d142cd67$export$2ce376c2cc3355c8;
|
|
683
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.Trigger = $94016b6f927b504d$export$27d2ad3c5815583e;
|
|
684
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.Divider = $a6a319b65dbbd900$export$acb07b4664ac227c;
|
|
685
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.SectionTitle = $7c6385c774644580$export$5d1e6c648985631e;
|
|
686
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.Submenu = $407bba9f98210b35$export$49229ebf838c159b;
|
|
687
|
+
$e1cb616583324cbb$export$d9b273488cd8ce6f.SubmenuTrigger = $423d6b42721d64f8$export$ecabc99eeffab7ca;
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
export {$e1cb616583324cbb$export$d9b273488cd8ce6f as Menu, $511d273ec51beeae$export$d4c4e98c5044dc8 as MenuList, $ea346231d142cd67$export$2ce376c2cc3355c8 as MenuItem, $94016b6f927b504d$export$27d2ad3c5815583e as MenuTrigger, $a6a319b65dbbd900$export$acb07b4664ac227c as MenuDivider, $7c6385c774644580$export$5d1e6c648985631e as MenuSectionTitle, $407bba9f98210b35$export$49229ebf838c159b as Submenu, $423d6b42721d64f8$export$ecabc99eeffab7ca as SubmenuTrigger};
|
|
700
|
+
//# sourceMappingURL=module.js.map
|