@yamada-ui/menu 0.1.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/index.js ADDED
@@ -0,0 +1,504 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Menu: () => Menu,
24
+ MenuButton: () => MenuButton,
25
+ MenuDivider: () => MenuDivider,
26
+ MenuGroup: () => MenuGroup,
27
+ MenuItem: () => MenuItem,
28
+ MenuList: () => MenuList,
29
+ MenuOptionGroup: () => MenuOptionGroup,
30
+ MenuOptionItem: () => MenuOptionItem,
31
+ useMenu: () => useMenu,
32
+ useMenuDescendant: () => useMenuDescendant,
33
+ useMenuDescendantsContext: () => useMenuDescendantsContext
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // src/menu.tsx
38
+ var import_core = require("@yamada-ui/core");
39
+ var import_popover = require("@yamada-ui/popover");
40
+ var import_use_descendant = require("@yamada-ui/use-descendant");
41
+ var import_use_disclosure = require("@yamada-ui/use-disclosure");
42
+ var import_utils = require("@yamada-ui/utils");
43
+ var import_react = require("react");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
45
+ var {
46
+ DescendantsContextProvider,
47
+ useDescendantsContext: useMenuDescendantsContext,
48
+ useDescendants,
49
+ useDescendant: useMenuDescendant
50
+ } = (0, import_use_descendant.createDescendant)();
51
+ var [MenuProvider, useMenu] = (0, import_utils.createContext)({
52
+ name: "MenuContext",
53
+ errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
54
+ });
55
+ var Menu = (props) => {
56
+ const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Menu", props);
57
+ const {
58
+ initialFocusRef,
59
+ closeOnSelect = true,
60
+ placement = "bottom-start",
61
+ duration = 0.2,
62
+ ...rest
63
+ } = (0, import_core.omitThemeProps)(mergedProps);
64
+ const descendants = useDescendants();
65
+ const [focusedIndex, setFocusedIndex] = (0, import_react.useState)(-1);
66
+ const menuRef = (0, import_react.useRef)(null);
67
+ const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
68
+ const onFocusMenu = (0, import_react.useCallback)(() => {
69
+ requestAnimationFrame(() => {
70
+ var _a;
71
+ return (_a = menuRef.current) == null ? void 0 : _a.focus({ preventScroll: false });
72
+ });
73
+ }, []);
74
+ const onFocusFirstItem = (0, import_react.useCallback)(() => {
75
+ const id = setTimeout(() => {
76
+ if (initialFocusRef)
77
+ return;
78
+ const first = descendants.enabledfirstValue();
79
+ if (first)
80
+ setFocusedIndex(first.index);
81
+ });
82
+ timeoutIds.current.add(id);
83
+ }, [descendants, initialFocusRef]);
84
+ const onFocusLastItem = (0, import_react.useCallback)(() => {
85
+ const id = setTimeout(() => {
86
+ if (initialFocusRef)
87
+ return;
88
+ const last = descendants.enabledlastValue();
89
+ if (last)
90
+ setFocusedIndex(last.index);
91
+ });
92
+ timeoutIds.current.add(id);
93
+ }, [descendants, initialFocusRef]);
94
+ const onOpenInternal = (0, import_react.useCallback)(() => {
95
+ var _a;
96
+ (_a = rest.onOpen) == null ? void 0 : _a.call(rest);
97
+ onFocusMenu();
98
+ }, [onFocusMenu, rest]);
99
+ const [isOpen, onOpen, onClose] = (0, import_use_disclosure.useDisclosure)({ ...props, onOpen: onOpenInternal });
100
+ (0, import_utils.useUpdateEffect)(() => {
101
+ if (!isOpen)
102
+ setFocusedIndex(-1);
103
+ }, [isOpen]);
104
+ (0, import_utils.useUnmountEffect)(() => {
105
+ timeoutIds.current.forEach((id) => clearTimeout(id));
106
+ timeoutIds.current.clear();
107
+ });
108
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
109
+ MenuProvider,
110
+ {
111
+ value: {
112
+ isOpen,
113
+ onOpen,
114
+ onClose,
115
+ onFocusFirstItem,
116
+ onFocusLastItem,
117
+ closeOnSelect,
118
+ focusedIndex,
119
+ setFocusedIndex,
120
+ menuRef,
121
+ styles
122
+ },
123
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
124
+ import_popover.Popover,
125
+ {
126
+ ...{
127
+ ...rest,
128
+ isOpen,
129
+ onOpen,
130
+ onClose,
131
+ placement,
132
+ duration,
133
+ initialFocusRef,
134
+ closeOnButton: false
135
+ }
136
+ }
137
+ )
138
+ }
139
+ ) });
140
+ };
141
+
142
+ // src/menu-button.tsx
143
+ var import_core2 = require("@yamada-ui/core");
144
+ var import_popover2 = require("@yamada-ui/popover");
145
+ var import_utils2 = require("@yamada-ui/utils");
146
+ var import_react2 = require("react");
147
+ var import_jsx_runtime2 = require("react/jsx-runtime");
148
+ var MenuButton = (0, import_core2.forwardRef)(
149
+ ({ className, children, as: As, ...rest }, ref) => {
150
+ const { isOpen, onOpen, onFocusFirstItem, onFocusLastItem } = useMenu();
151
+ const onKeyDown = (0, import_react2.useCallback)(
152
+ (ev) => {
153
+ const actions = {
154
+ Enter: (0, import_utils2.funcAll)(onOpen, onFocusFirstItem),
155
+ ArrowDown: (0, import_utils2.funcAll)(onOpen, onFocusFirstItem),
156
+ ArrowUp: (0, import_utils2.funcAll)(onOpen, onFocusLastItem)
157
+ };
158
+ const action = actions[ev.key];
159
+ if (!action)
160
+ return;
161
+ ev.preventDefault();
162
+ ev.stopPropagation();
163
+ action();
164
+ },
165
+ [onFocusFirstItem, onFocusLastItem, onOpen]
166
+ );
167
+ const Component = As || Button;
168
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
169
+ Component,
170
+ {
171
+ ref,
172
+ className: (0, import_utils2.cx)("ui-menu-button", className),
173
+ ...rest,
174
+ "data-active": (0, import_utils2.dataAttr)(isOpen),
175
+ "aria-expanded": (0, import_utils2.ariaAttr)(isOpen),
176
+ onKeyDown: (0, import_utils2.handlerAll)(rest.onKeyDown, onKeyDown),
177
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { __css: { pointerEvents: "none", flex: "1 1 auto", minW: 0 }, children })
178
+ }
179
+ ) });
180
+ }
181
+ );
182
+ var Button = (0, import_core2.forwardRef)((rest, ref) => {
183
+ const { styles } = useMenu();
184
+ const css = {
185
+ display: "inline-flex",
186
+ appearance: "none",
187
+ alignItems: "center",
188
+ outline: 0,
189
+ ...styles.button
190
+ };
191
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.button, { ref, __css: css, ...rest });
192
+ });
193
+
194
+ // src/menu-list.tsx
195
+ var import_core3 = require("@yamada-ui/core");
196
+ var import_popover3 = require("@yamada-ui/popover");
197
+ var import_utils3 = require("@yamada-ui/utils");
198
+ var import_react3 = require("react");
199
+ var import_jsx_runtime3 = require("react/jsx-runtime");
200
+ var MenuList = (0, import_core3.forwardRef)(({ className, ...rest }, ref) => {
201
+ const { menuRef, focusedIndex, setFocusedIndex, onClose, styles } = useMenu();
202
+ const descendants = useMenuDescendantsContext();
203
+ const onNext = (0, import_react3.useCallback)(() => {
204
+ const next = descendants.enabledNextValue(focusedIndex);
205
+ if (next)
206
+ setFocusedIndex(next.index);
207
+ }, [descendants, focusedIndex, setFocusedIndex]);
208
+ const onPrev = (0, import_react3.useCallback)(() => {
209
+ const prev = descendants.enabledPrevValue(focusedIndex);
210
+ if (prev)
211
+ setFocusedIndex(prev.index);
212
+ }, [descendants, focusedIndex, setFocusedIndex]);
213
+ const onFirst = (0, import_react3.useCallback)(() => {
214
+ const first = descendants.enabledfirstValue();
215
+ if (first)
216
+ setFocusedIndex(first.index);
217
+ }, [descendants, setFocusedIndex]);
218
+ const onLast = (0, import_react3.useCallback)(() => {
219
+ const last = descendants.enabledlastValue();
220
+ if (last)
221
+ setFocusedIndex(last.index);
222
+ }, [descendants, setFocusedIndex]);
223
+ const onKeyDown = (0, import_react3.useCallback)(
224
+ (ev) => {
225
+ const actions = {
226
+ Tab: (ev2) => ev2.preventDefault(),
227
+ Escape: onClose,
228
+ ArrowDown: focusedIndex === -1 ? onFirst : onNext,
229
+ ArrowUp: focusedIndex === -1 ? onLast : onPrev,
230
+ Home: onFirst,
231
+ End: onLast
232
+ };
233
+ const action = actions[ev.key];
234
+ if (!action)
235
+ return;
236
+ ev.preventDefault();
237
+ action(ev);
238
+ },
239
+ [focusedIndex, onClose, onFirst, onLast, onNext, onPrev]
240
+ );
241
+ const css = { ...styles.list };
242
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
243
+ import_popover3.PopoverContent,
244
+ {
245
+ ref: (0, import_utils3.mergeRefs)(menuRef, ref),
246
+ className: (0, import_utils3.cx)("ui-menu-list", className),
247
+ role: "menu",
248
+ tabIndex: -1,
249
+ __css: css,
250
+ ...rest,
251
+ onKeyDown: (0, import_utils3.handlerAll)(rest.onKeyDown, onKeyDown)
252
+ }
253
+ );
254
+ });
255
+
256
+ // src/menu-item.tsx
257
+ var import_core4 = require("@yamada-ui/core");
258
+ var import_use_clickable = require("@yamada-ui/use-clickable");
259
+ var import_utils4 = require("@yamada-ui/utils");
260
+ var import_react4 = require("react");
261
+ var import_jsx_runtime4 = require("react/jsx-runtime");
262
+ var isTargetMenuItem = (target) => {
263
+ var _a;
264
+ return (0, import_utils4.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("menu-item"));
265
+ };
266
+ var MenuItem = (0, import_core4.forwardRef)(
267
+ ({
268
+ as,
269
+ className,
270
+ type,
271
+ isDisabled,
272
+ isFocusable,
273
+ closeOnSelect: customCloseOnSelect,
274
+ icon,
275
+ command,
276
+ children,
277
+ ...props
278
+ }, ref) => {
279
+ const {
280
+ focusedIndex,
281
+ setFocusedIndex,
282
+ isOpen,
283
+ onClose,
284
+ closeOnSelect: generalCloseOnSelect,
285
+ menuRef,
286
+ styles
287
+ } = useMenu();
288
+ const trulyDisabled = isDisabled && !isFocusable;
289
+ const buttonRef = (0, import_react4.useRef)(null);
290
+ const { index, register } = useMenuDescendant({ disabled: trulyDisabled });
291
+ const isFocused = index === focusedIndex;
292
+ const onClick = (0, import_react4.useCallback)(
293
+ (ev) => {
294
+ var _a;
295
+ (_a = props.onClick) == null ? void 0 : _a.call(props, ev);
296
+ if (!isTargetMenuItem(ev.currentTarget))
297
+ return;
298
+ if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect)
299
+ onClose();
300
+ },
301
+ [props, customCloseOnSelect, generalCloseOnSelect, onClose]
302
+ );
303
+ const onFocus = (0, import_react4.useCallback)(
304
+ (ev) => {
305
+ var _a;
306
+ (_a = props.onFocus) == null ? void 0 : _a.call(props, ev);
307
+ setFocusedIndex(index);
308
+ },
309
+ [props, setFocusedIndex, index]
310
+ );
311
+ const rest = (0, import_use_clickable.useClickable)({
312
+ onClick,
313
+ onFocus,
314
+ ref: (0, import_utils4.mergeRefs)(register, buttonRef, ref),
315
+ isDisabled,
316
+ isFocusable
317
+ });
318
+ (0, import_utils4.useUpdateEffect)(() => {
319
+ if (!isOpen)
320
+ return;
321
+ if (isFocused && !trulyDisabled && buttonRef.current) {
322
+ requestAnimationFrame(() => {
323
+ var _a;
324
+ return (_a = buttonRef.current) == null ? void 0 : _a.focus();
325
+ });
326
+ } else if (menuRef.current && !(0, import_utils4.isActiveElement)(menuRef.current)) {
327
+ menuRef.current.focus();
328
+ }
329
+ }, [isFocused, trulyDisabled, menuRef, isOpen]);
330
+ type = as || type ? type != null ? type : void 0 : "button";
331
+ children = icon || command ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core4.ui.span, { style: { pointerEvents: "none", flex: 1 }, children }) : children;
332
+ const css = {
333
+ textDecoration: "none",
334
+ color: "inherit",
335
+ userSelect: "none",
336
+ display: "flex",
337
+ width: "100%",
338
+ alignItems: "center",
339
+ textAlign: "start",
340
+ flex: "0 0 auto",
341
+ outline: 0,
342
+ gap: "0.75rem",
343
+ ...styles.item
344
+ };
345
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
346
+ import_core4.ui.button,
347
+ {
348
+ ...props,
349
+ ...rest,
350
+ as,
351
+ type,
352
+ role: "menu-item",
353
+ tabInde: isFocused ? 0 : -1,
354
+ className: (0, import_utils4.cx)("ui-menu-item", className),
355
+ __css: css,
356
+ children: [
357
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MenuIcon, { children: icon }) : null,
358
+ children,
359
+ command ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MenuCommand, { children: command }) : null
360
+ ]
361
+ }
362
+ );
363
+ }
364
+ );
365
+ var MenuOptionItem = (0, import_core4.forwardRef)(
366
+ ({ className, icon, isChecked, closeOnSelect = false, children, ...rest }, ref) => {
367
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
368
+ MenuItem,
369
+ {
370
+ ref,
371
+ className: (0, import_utils4.cx)("ui-menu-option-item", className),
372
+ "aria-checked": (0, import_utils4.ariaAttr)(isChecked),
373
+ closeOnSelect,
374
+ ...rest,
375
+ children: [
376
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MenuIcon, { opacity: isChecked ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CheckIcon, {}) }) : null,
377
+ children
378
+ ]
379
+ }
380
+ );
381
+ }
382
+ );
383
+ var MenuIcon = (0, import_core4.forwardRef)(({ className, ...rest }, ref) => {
384
+ const { styles } = useMenu();
385
+ const css = {
386
+ flexShrink: 0,
387
+ display: "inline-flex",
388
+ justifyContent: "center",
389
+ alignItems: "center",
390
+ fontSize: "0.85em",
391
+ ...styles.icon
392
+ };
393
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core4.ui.span, { ref, className: (0, import_utils4.cx)("ui-menu-icon", className), __css: css, ...rest });
394
+ });
395
+ var MenuCommand = (0, import_core4.forwardRef)(({ className, ...rest }, ref) => {
396
+ const { styles } = useMenu();
397
+ const css = { ...styles.command };
398
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core4.ui.span, { ref, className: (0, import_utils4.cx)("ui-menu-command", className), __css: css, ...rest });
399
+ });
400
+ var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
401
+ "polygon",
402
+ {
403
+ fill: "currentColor",
404
+ points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
405
+ }
406
+ ) });
407
+
408
+ // src/menu-group.tsx
409
+ var import_core5 = require("@yamada-ui/core");
410
+ var import_utils5 = require("@yamada-ui/utils");
411
+ var import_jsx_runtime5 = require("react/jsx-runtime");
412
+ var MenuGroup = (0, import_core5.forwardRef)(
413
+ ({ className, title, children, ...rest }, ref) => {
414
+ const { styles } = useMenu();
415
+ const css = { ...styles.group };
416
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
417
+ import_core5.ui.div,
418
+ {
419
+ ref,
420
+ className: (0, import_utils5.cx)("ui-menu-group", className),
421
+ role: "group",
422
+ __css: css,
423
+ ...rest,
424
+ children: [
425
+ title ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.span, { className: (0, import_utils5.cx)("ui-menu-group-title"), __css: styles.groupTitle, children: title }) : null,
426
+ children
427
+ ]
428
+ }
429
+ );
430
+ }
431
+ );
432
+
433
+ // src/menu-option-group.tsx
434
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
435
+ var import_utils6 = require("@yamada-ui/utils");
436
+ var import_react5 = require("react");
437
+ var import_jsx_runtime6 = require("react/jsx-runtime");
438
+ var MenuOptionGroup = (0, import_react5.forwardRef)(
439
+ ({ className, defaultValue, type, children, ...rest }, ref) => {
440
+ const isRadio = type === "radio";
441
+ defaultValue = isRadio ? "" : [];
442
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
443
+ ...rest,
444
+ defaultValue
445
+ });
446
+ const onChange = (0, import_react5.useCallback)(
447
+ (selectedValue) => {
448
+ if (isRadio && typeof value === "string")
449
+ setValue(selectedValue);
450
+ if (!isRadio && (0, import_utils6.isArray)(value)) {
451
+ const nextValue = value.includes(selectedValue) ? value.filter((item) => item !== selectedValue) : value.concat(selectedValue);
452
+ setValue(nextValue);
453
+ }
454
+ },
455
+ [isRadio, value, setValue]
456
+ );
457
+ const validChildren = (0, import_utils6.getValidChildren)(children);
458
+ const cloneChildren = validChildren.map((child) => {
459
+ if (child.type !== MenuOptionItem)
460
+ return child;
461
+ const onClick = (ev) => {
462
+ var _a, _b;
463
+ onChange(child.props.value);
464
+ (_b = (_a = child.props).onClick) == null ? void 0 : _b.call(_a, ev);
465
+ };
466
+ const isChecked = !isRadio && (0, import_utils6.isArray)(value) ? value.includes(child.props.value) : child.props.value === value;
467
+ return (0, import_react5.cloneElement)(child, { type, onClick, isChecked });
468
+ });
469
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
470
+ MenuGroup,
471
+ {
472
+ ref,
473
+ className: (0, import_utils6.cx)("ui-menu-option-group", className),
474
+ ...(0, import_utils6.omitObject)(rest, ["value", "onChange"]),
475
+ children: cloneChildren
476
+ }
477
+ );
478
+ }
479
+ );
480
+ MenuOptionGroup.displayName = "MenuOptionGroup";
481
+
482
+ // src/menu-divider.tsx
483
+ var import_core6 = require("@yamada-ui/core");
484
+ var import_utils7 = require("@yamada-ui/utils");
485
+ var import_jsx_runtime7 = require("react/jsx-runtime");
486
+ var MenuDivider = (0, import_core6.forwardRef)(({ className, ...rest }, ref) => {
487
+ const { styles } = useMenu();
488
+ const css = { ...styles.divider };
489
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core6.ui.hr, { ref, className: (0, import_utils7.cx)("ui-menu-divider", className), __css: css, ...rest });
490
+ });
491
+ // Annotate the CommonJS export names for ESM import in node:
492
+ 0 && (module.exports = {
493
+ Menu,
494
+ MenuButton,
495
+ MenuDivider,
496
+ MenuGroup,
497
+ MenuItem,
498
+ MenuList,
499
+ MenuOptionGroup,
500
+ MenuOptionItem,
501
+ useMenu,
502
+ useMenuDescendant,
503
+ useMenuDescendantsContext
504
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import {
2
+ MenuButton,
3
+ MenuDivider,
4
+ MenuGroup,
5
+ MenuItem,
6
+ MenuList,
7
+ MenuOptionGroup,
8
+ MenuOptionItem
9
+ } from "./chunk-OFZGIB33.mjs";
10
+ import {
11
+ Menu,
12
+ useMenu,
13
+ useMenuDescendant,
14
+ useMenuDescendantsContext
15
+ } from "./chunk-6ALPY7K4.mjs";
16
+ export {
17
+ Menu,
18
+ MenuButton,
19
+ MenuDivider,
20
+ MenuGroup,
21
+ MenuItem,
22
+ MenuList,
23
+ MenuOptionGroup,
24
+ MenuOptionItem,
25
+ useMenu,
26
+ useMenuDescendant,
27
+ useMenuDescendantsContext
28
+ };
@@ -0,0 +1,7 @@
1
+ import * as _yamada_ui_core from '@yamada-ui/core';
2
+ import { HTMLUIProps } from '@yamada-ui/core';
3
+
4
+ type MenuButtonProps = HTMLUIProps<'button'>;
5
+ declare const MenuButton: _yamada_ui_core.Component<"button", MenuButtonProps>;
6
+
7
+ export { MenuButton, MenuButtonProps };
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/menu-button.tsx
21
+ var menu_button_exports = {};
22
+ __export(menu_button_exports, {
23
+ MenuButton: () => MenuButton
24
+ });
25
+ module.exports = __toCommonJS(menu_button_exports);
26
+ var import_core2 = require("@yamada-ui/core");
27
+ var import_popover2 = require("@yamada-ui/popover");
28
+ var import_utils2 = require("@yamada-ui/utils");
29
+ var import_react2 = require("react");
30
+
31
+ // src/menu.tsx
32
+ var import_core = require("@yamada-ui/core");
33
+ var import_popover = require("@yamada-ui/popover");
34
+ var import_use_descendant = require("@yamada-ui/use-descendant");
35
+ var import_use_disclosure = require("@yamada-ui/use-disclosure");
36
+ var import_utils = require("@yamada-ui/utils");
37
+ var import_react = require("react");
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var {
40
+ DescendantsContextProvider,
41
+ useDescendantsContext: useMenuDescendantsContext,
42
+ useDescendants,
43
+ useDescendant: useMenuDescendant
44
+ } = (0, import_use_descendant.createDescendant)();
45
+ var [MenuProvider, useMenu] = (0, import_utils.createContext)({
46
+ name: "MenuContext",
47
+ errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
48
+ });
49
+
50
+ // src/menu-button.tsx
51
+ var import_jsx_runtime2 = require("react/jsx-runtime");
52
+ var MenuButton = (0, import_core2.forwardRef)(
53
+ ({ className, children, as: As, ...rest }, ref) => {
54
+ const { isOpen, onOpen, onFocusFirstItem, onFocusLastItem } = useMenu();
55
+ const onKeyDown = (0, import_react2.useCallback)(
56
+ (ev) => {
57
+ const actions = {
58
+ Enter: (0, import_utils2.funcAll)(onOpen, onFocusFirstItem),
59
+ ArrowDown: (0, import_utils2.funcAll)(onOpen, onFocusFirstItem),
60
+ ArrowUp: (0, import_utils2.funcAll)(onOpen, onFocusLastItem)
61
+ };
62
+ const action = actions[ev.key];
63
+ if (!action)
64
+ return;
65
+ ev.preventDefault();
66
+ ev.stopPropagation();
67
+ action();
68
+ },
69
+ [onFocusFirstItem, onFocusLastItem, onOpen]
70
+ );
71
+ const Component = As || Button;
72
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
73
+ Component,
74
+ {
75
+ ref,
76
+ className: (0, import_utils2.cx)("ui-menu-button", className),
77
+ ...rest,
78
+ "data-active": (0, import_utils2.dataAttr)(isOpen),
79
+ "aria-expanded": (0, import_utils2.ariaAttr)(isOpen),
80
+ onKeyDown: (0, import_utils2.handlerAll)(rest.onKeyDown, onKeyDown),
81
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { __css: { pointerEvents: "none", flex: "1 1 auto", minW: 0 }, children })
82
+ }
83
+ ) });
84
+ }
85
+ );
86
+ var Button = (0, import_core2.forwardRef)((rest, ref) => {
87
+ const { styles } = useMenu();
88
+ const css = {
89
+ display: "inline-flex",
90
+ appearance: "none",
91
+ alignItems: "center",
92
+ outline: 0,
93
+ ...styles.button
94
+ };
95
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.button, { ref, __css: css, ...rest });
96
+ });
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ MenuButton
100
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ MenuButton
3
+ } from "./chunk-OFZGIB33.mjs";
4
+ import "./chunk-6ALPY7K4.mjs";
5
+ export {
6
+ MenuButton
7
+ };
@@ -0,0 +1,7 @@
1
+ import * as _yamada_ui_core from '@yamada-ui/core';
2
+ import { HTMLUIProps } from '@yamada-ui/core';
3
+
4
+ type MenuDividerProps = HTMLUIProps<'hr'>;
5
+ declare const MenuDivider: _yamada_ui_core.Component<_yamada_ui_core.As, object>;
6
+
7
+ export { MenuDivider, MenuDividerProps };