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