@yamada-ui/menu 1.3.12 → 1.3.13-dev-20240917033401
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-5ZWRZF6M.mjs → chunk-DPC5A6DV.mjs} +2 -2
- package/dist/chunk-DPC5A6DV.mjs.map +1 -0
- package/dist/{chunk-AG6UJA7D.mjs → chunk-HVOHR2NQ.mjs} +2 -2
- package/dist/chunk-HVOHR2NQ.mjs.map +1 -0
- package/dist/{chunk-G4OMCC2Y.mjs → chunk-M4PPRRRC.mjs} +5 -3
- package/dist/chunk-M4PPRRRC.mjs.map +1 -0
- package/dist/chunk-NNSVX2GX.mjs +170 -0
- package/dist/chunk-NNSVX2GX.mjs.map +1 -0
- package/dist/{chunk-73KHS3JD.mjs → chunk-O5D4LR5P.mjs} +2 -2
- package/dist/chunk-O5D4LR5P.mjs.map +1 -0
- package/dist/chunk-OFCEMPQW.mjs +29 -0
- package/dist/chunk-OFCEMPQW.mjs.map +1 -0
- package/dist/{chunk-6YBKZRIZ.mjs → chunk-SI3WI4AI.mjs} +3 -3
- package/dist/chunk-SI3WI4AI.mjs.map +1 -0
- package/dist/chunk-T7CXLEBW.mjs +243 -0
- package/dist/chunk-T7CXLEBW.mjs.map +1 -0
- package/dist/chunk-ZUOFHOX6.mjs +43 -0
- package/dist/chunk-ZUOFHOX6.mjs.map +1 -0
- package/dist/chunk-ZV73JKM5.mjs +21 -0
- package/dist/chunk-ZV73JKM5.mjs.map +1 -0
- package/dist/context-menu-trigger.d.mts +2 -1
- package/dist/context-menu-trigger.d.ts +2 -1
- package/dist/context-menu-trigger.js +32 -17
- package/dist/context-menu-trigger.js.map +1 -1
- package/dist/context-menu-trigger.mjs +2 -2
- package/dist/context-menu.d.mts +4 -10
- package/dist/context-menu.d.ts +4 -10
- package/dist/context-menu.js +43 -264
- package/dist/context-menu.js.map +1 -1
- package/dist/context-menu.mjs +5 -5
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +259 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -11
- package/dist/menu-button.d.mts +4 -3
- package/dist/menu-button.d.ts +4 -3
- package/dist/menu-button.js +55 -58
- package/dist/menu-button.js.map +1 -1
- package/dist/menu-button.mjs +3 -2
- package/dist/menu-context.d.mts +210 -0
- package/dist/menu-context.d.ts +210 -0
- package/dist/menu-context.js +77 -0
- package/dist/menu-context.js.map +1 -0
- package/dist/menu-context.mjs +30 -0
- package/dist/menu-context.mjs.map +1 -0
- package/dist/menu-divider.d.mts +3 -2
- package/dist/menu-divider.d.ts +3 -2
- package/dist/menu-divider.js +26 -21
- package/dist/menu-divider.js.map +1 -1
- package/dist/menu-divider.mjs +2 -2
- package/dist/menu-group.d.mts +3 -3
- package/dist/menu-group.d.ts +3 -3
- package/dist/menu-group.js +17 -14
- package/dist/menu-group.js.map +1 -1
- package/dist/menu-group.mjs +2 -2
- package/dist/menu-item.d.mts +14 -19
- package/dist/menu-item.d.ts +14 -19
- package/dist/menu-item.js +40 -45
- package/dist/menu-item.js.map +1 -1
- package/dist/menu-item.mjs +4 -7
- package/dist/menu-list.d.mts +2 -2
- package/dist/menu-list.d.ts +2 -2
- package/dist/menu-list.js +23 -20
- package/dist/menu-list.js.map +1 -1
- package/dist/menu-list.mjs +2 -2
- package/dist/menu-option-group.d.mts +6 -7
- package/dist/menu-option-group.d.ts +6 -7
- package/dist/menu-option-group.js +97 -100
- package/dist/menu-option-group.js.map +1 -1
- package/dist/menu-option-group.mjs +4 -3
- package/dist/menu.d.mts +7 -87
- package/dist/menu.d.ts +7 -87
- package/dist/menu.js +41 -274
- package/dist/menu.js.map +1 -1
- package/dist/menu.mjs +4 -13
- package/package.json +11 -11
- package/dist/chunk-5ZWRZF6M.mjs.map +0 -1
- package/dist/chunk-6IPLI42Z.mjs +0 -447
- package/dist/chunk-6IPLI42Z.mjs.map +0 -1
- package/dist/chunk-6YBKZRIZ.mjs.map +0 -1
- package/dist/chunk-73KHS3JD.mjs.map +0 -1
- package/dist/chunk-AG6UJA7D.mjs.map +0 -1
- package/dist/chunk-G4OMCC2Y.mjs.map +0 -1
- package/dist/chunk-ZOUBZWDN.mjs +0 -27
- package/dist/chunk-ZOUBZWDN.mjs.map +0 -1
package/dist/index.js
CHANGED
@@ -38,42 +38,204 @@ __export(src_exports, {
|
|
38
38
|
module.exports = __toCommonJS(src_exports);
|
39
39
|
|
40
40
|
// src/menu.tsx
|
41
|
-
var
|
41
|
+
var import_core = require("@yamada-ui/core");
|
42
42
|
var import_popover = require("@yamada-ui/popover");
|
43
|
-
var import_use_descendant = require("@yamada-ui/use-descendant");
|
44
43
|
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
45
|
-
var
|
46
|
-
var
|
44
|
+
var import_utils2 = require("@yamada-ui/utils");
|
45
|
+
var import_react = require("react");
|
47
46
|
|
48
|
-
// src/context
|
49
|
-
var
|
47
|
+
// src/menu-context.ts
|
48
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
50
49
|
var import_utils = require("@yamada-ui/utils");
|
50
|
+
var {
|
51
|
+
DescendantsContextProvider,
|
52
|
+
useDescendantsContext: useMenuDescendantsContext,
|
53
|
+
useDescendants,
|
54
|
+
useDescendant: useMenuDescendant
|
55
|
+
} = (0, import_use_descendant.createDescendant)();
|
56
|
+
var [MenuProvider, useMenu] = (0, import_utils.createContext)({
|
57
|
+
name: "MenuContext",
|
58
|
+
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
59
|
+
});
|
60
|
+
var [ContextMenuProvider, useContextMenu] = (0, import_utils.createContext)({
|
61
|
+
strict: false,
|
62
|
+
name: "ContextMenuContext"
|
63
|
+
});
|
64
|
+
var [UpstreamMenuProvider, useUpstreamMenu] = (0, import_utils.createContext)({
|
65
|
+
strict: false,
|
66
|
+
name: "UpstreamMenuContext"
|
67
|
+
});
|
68
|
+
var [UpstreamMenuItemProvider, useUpstreamMenuItem] = (0, import_utils.createContext)({
|
69
|
+
strict: false,
|
70
|
+
name: "UpstreamMenuItemContext"
|
71
|
+
});
|
72
|
+
|
73
|
+
// src/menu.tsx
|
51
74
|
var import_jsx_runtime = require("react/jsx-runtime");
|
52
|
-
var
|
53
|
-
|
54
|
-
|
55
|
-
|
75
|
+
var Menu = (props) => {
|
76
|
+
var _a, _b, _c;
|
77
|
+
const { styles: contextMenuStyles } = (_a = useContextMenu()) != null ? _a : {};
|
78
|
+
const [styles, mergedProps] = (0, import_core.useComponentMultiStyle)("Menu", props, {
|
79
|
+
isProcessSkip: !!contextMenuStyles,
|
80
|
+
styles: contextMenuStyles
|
81
|
+
});
|
82
|
+
let {
|
83
|
+
initialFocusRef,
|
84
|
+
closeOnSelect = true,
|
85
|
+
closeOnBlur,
|
86
|
+
placement,
|
87
|
+
duration = 0.2,
|
88
|
+
offset,
|
89
|
+
onOpen: onOpenProp,
|
90
|
+
onClose: onCloseProp,
|
91
|
+
...rest
|
92
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
93
|
+
const { relatedRef, onUpstreamClose, onDownstreamCloseMapRef } = (_b = useUpstreamMenu()) != null ? _b : {};
|
94
|
+
const { setDownstreamOpen, hasDownstreamRef } = (_c = useUpstreamMenuItem()) != null ? _c : {};
|
95
|
+
const isNested = !!relatedRef;
|
96
|
+
if (isNested) {
|
97
|
+
placement != null ? placement : placement = "right-start";
|
98
|
+
offset != null ? offset : offset = [-8, 8];
|
99
|
+
closeOnBlur != null ? closeOnBlur : closeOnBlur = false;
|
100
|
+
} else {
|
101
|
+
placement != null ? placement : placement = "bottom-start";
|
56
102
|
}
|
57
|
-
);
|
58
|
-
|
59
|
-
const
|
60
|
-
const
|
61
|
-
|
103
|
+
const descendants = useDescendants();
|
104
|
+
const [focusedIndex, setFocusedIndex] = (0, import_react.useState)(-1);
|
105
|
+
const menuRef = (0, import_react.useRef)(null);
|
106
|
+
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
107
|
+
const requestAnimationFrameId = (0, import_react.useRef)(null);
|
108
|
+
const onCloseMapRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
109
|
+
const onFocusMenu = (0, import_react.useCallback)(() => {
|
110
|
+
requestAnimationFrame(
|
111
|
+
() => {
|
112
|
+
var _a2;
|
113
|
+
return (_a2 = menuRef.current) == null ? void 0 : _a2.focus({ preventScroll: false });
|
114
|
+
}
|
115
|
+
);
|
116
|
+
}, []);
|
117
|
+
const onFocusFirstItem = (0, import_react.useCallback)(() => {
|
118
|
+
const id2 = setTimeout(() => {
|
119
|
+
if (initialFocusRef) return;
|
120
|
+
const first = descendants.enabledFirstValue();
|
121
|
+
if (first) setFocusedIndex(first.index);
|
122
|
+
});
|
123
|
+
timeoutIds.current.add(id2);
|
124
|
+
}, [descendants, initialFocusRef]);
|
125
|
+
const onFocusLastItem = (0, import_react.useCallback)(() => {
|
126
|
+
const id2 = setTimeout(() => {
|
127
|
+
if (initialFocusRef) return;
|
128
|
+
const last = descendants.enabledLastValue();
|
129
|
+
if (last) setFocusedIndex(last.index);
|
130
|
+
});
|
131
|
+
timeoutIds.current.add(id2);
|
132
|
+
}, [descendants, initialFocusRef]);
|
133
|
+
const onOpenInternal = (0, import_react.useCallback)(() => {
|
134
|
+
onOpenProp == null ? void 0 : onOpenProp();
|
135
|
+
if (!isNested) onFocusMenu();
|
136
|
+
}, [onOpenProp, isNested, onFocusMenu]);
|
137
|
+
const onCloseInternal = (0, import_react.useCallback)(() => {
|
138
|
+
onCloseProp == null ? void 0 : onCloseProp();
|
139
|
+
for (const onClose2 of onCloseMapRef.current.values()) {
|
140
|
+
onClose2();
|
141
|
+
}
|
142
|
+
}, [onCloseProp]);
|
143
|
+
const id = (0, import_react.useId)();
|
144
|
+
const { isOpen, onOpen, onClose } = (0, import_use_disclosure.useDisclosure)({
|
145
|
+
...props,
|
146
|
+
onOpen: onOpenInternal,
|
147
|
+
onClose: onCloseInternal
|
148
|
+
});
|
149
|
+
(0, import_react.useEffect)(() => {
|
150
|
+
const onCloseMap = onDownstreamCloseMapRef == null ? void 0 : onDownstreamCloseMapRef.current;
|
151
|
+
onCloseMap == null ? void 0 : onCloseMap.set(id, onClose);
|
152
|
+
return () => {
|
153
|
+
onCloseMap == null ? void 0 : onCloseMap.delete(id);
|
154
|
+
};
|
155
|
+
}, [id, onClose, onDownstreamCloseMapRef]);
|
156
|
+
(0, import_react.useEffect)(() => {
|
157
|
+
if (setDownstreamOpen) setDownstreamOpen(isOpen);
|
158
|
+
}, [setDownstreamOpen, isOpen]);
|
159
|
+
(0, import_react.useEffect)(() => {
|
160
|
+
if (hasDownstreamRef) hasDownstreamRef.current = true;
|
161
|
+
return () => {
|
162
|
+
if (hasDownstreamRef) hasDownstreamRef.current = false;
|
163
|
+
};
|
164
|
+
});
|
165
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
166
|
+
if (!isOpen) setFocusedIndex(-1);
|
167
|
+
}, [isOpen]);
|
168
|
+
(0, import_utils2.useUnmountEffect)(() => {
|
169
|
+
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
170
|
+
timeoutIds.current.clear();
|
171
|
+
});
|
172
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
173
|
+
UpstreamMenuProvider,
|
174
|
+
{
|
175
|
+
value: {
|
176
|
+
relatedRef: menuRef,
|
177
|
+
onDownstreamCloseMapRef: onCloseMapRef,
|
178
|
+
onUpstreamClose: (0, import_utils2.funcAll)(onUpstreamClose, onClose)
|
179
|
+
},
|
180
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
181
|
+
MenuProvider,
|
182
|
+
{
|
183
|
+
value: {
|
184
|
+
isOpen,
|
185
|
+
onOpen,
|
186
|
+
onClose,
|
187
|
+
onUpstreamClose,
|
188
|
+
onFocusFirstItem,
|
189
|
+
onFocusLastItem,
|
190
|
+
closeOnSelect,
|
191
|
+
focusedIndex,
|
192
|
+
setFocusedIndex,
|
193
|
+
menuRef,
|
194
|
+
requestAnimationFrameId,
|
195
|
+
isNested,
|
196
|
+
styles
|
197
|
+
},
|
198
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
199
|
+
import_popover.Popover,
|
200
|
+
{
|
201
|
+
...{
|
202
|
+
trigger: isNested ? "hover" : "click",
|
203
|
+
...rest,
|
204
|
+
isOpen,
|
205
|
+
onOpen,
|
206
|
+
onClose,
|
207
|
+
placement,
|
208
|
+
offset,
|
209
|
+
duration,
|
210
|
+
initialFocusRef,
|
211
|
+
relatedRef,
|
212
|
+
closeOnButton: false,
|
213
|
+
closeOnBlur
|
214
|
+
}
|
215
|
+
}
|
216
|
+
)
|
217
|
+
}
|
218
|
+
)
|
219
|
+
}
|
220
|
+
) });
|
62
221
|
};
|
63
222
|
|
223
|
+
// src/menu-button.tsx
|
224
|
+
var import_core3 = require("@yamada-ui/core");
|
225
|
+
var import_icon = require("@yamada-ui/icon");
|
226
|
+
var import_popover2 = require("@yamada-ui/popover");
|
227
|
+
var import_utils4 = require("@yamada-ui/utils");
|
228
|
+
var import_react3 = require("react");
|
229
|
+
|
64
230
|
// src/menu-item.tsx
|
65
231
|
var import_core2 = require("@yamada-ui/core");
|
66
232
|
var import_use_clickable = require("@yamada-ui/use-clickable");
|
67
|
-
var
|
68
|
-
var
|
233
|
+
var import_utils3 = require("@yamada-ui/utils");
|
234
|
+
var import_react2 = require("react");
|
69
235
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
70
|
-
var [UpstreamMenuItemProvider, useUpstreamMenuItem] = (0, import_utils2.createContext)({
|
71
|
-
strict: false,
|
72
|
-
name: "UpstreamMenuItemContext"
|
73
|
-
});
|
74
236
|
var isTargetMenuItem = (target) => {
|
75
237
|
var _a;
|
76
|
-
return (0,
|
238
|
+
return (0, import_utils3.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("menuitem"));
|
77
239
|
};
|
78
240
|
var MenuItem = (0, import_core2.forwardRef)(
|
79
241
|
({
|
@@ -101,23 +263,23 @@ var MenuItem = (0, import_core2.forwardRef)(
|
|
101
263
|
} = useMenu();
|
102
264
|
const { onUpstreamRestoreFocus } = (_a = useUpstreamMenuItem()) != null ? _a : {};
|
103
265
|
const trulyDisabled = isDisabled && !isFocusable;
|
104
|
-
const itemRef = (0,
|
105
|
-
const hasDownstreamRef = (0,
|
106
|
-
const onKeyDownRef = (0,
|
266
|
+
const itemRef = (0, import_react2.useRef)(null);
|
267
|
+
const hasDownstreamRef = (0, import_react2.useRef)(false);
|
268
|
+
const onKeyDownRef = (0, import_react2.useRef)(
|
107
269
|
() => void 0
|
108
270
|
);
|
109
271
|
const { index, register } = useMenuDescendant({ disabled: trulyDisabled });
|
110
|
-
const [isDownstreamOpen, setDownstreamOpen] = (0,
|
272
|
+
const [isDownstreamOpen, setDownstreamOpen] = (0, import_react2.useState)(false);
|
111
273
|
const isFocused = index === focusedIndex;
|
112
|
-
const onMouseOver = (0,
|
274
|
+
const onMouseOver = (0, import_react2.useCallback)(() => {
|
113
275
|
if (isDisabled) return;
|
114
276
|
setFocusedIndex(index);
|
115
277
|
}, [index, isDisabled, setFocusedIndex]);
|
116
|
-
const onMouseLeave = (0,
|
278
|
+
const onMouseLeave = (0, import_react2.useCallback)(() => {
|
117
279
|
if (isDisabled) return;
|
118
280
|
setFocusedIndex(-1);
|
119
281
|
}, [setFocusedIndex, isDisabled]);
|
120
|
-
const onClick = (0,
|
282
|
+
const onClick = (0, import_react2.useCallback)(
|
121
283
|
(ev) => {
|
122
284
|
if (!isTargetMenuItem(ev.currentTarget)) return;
|
123
285
|
const hasDownstream = hasDownstreamRef.current;
|
@@ -128,18 +290,18 @@ var MenuItem = (0, import_core2.forwardRef)(
|
|
128
290
|
},
|
129
291
|
[customCloseOnSelect, generalCloseOnSelect, onClose, onUpstreamClose]
|
130
292
|
);
|
131
|
-
const onFocus = (0,
|
293
|
+
const onFocus = (0, import_react2.useCallback)(() => {
|
132
294
|
setFocusedIndex(index);
|
133
295
|
}, [setFocusedIndex, index]);
|
134
|
-
const onRestoreFocus = (0,
|
296
|
+
const onRestoreFocus = (0, import_react2.useCallback)(() => {
|
135
297
|
var _a2;
|
136
298
|
(_a2 = itemRef.current) == null ? void 0 : _a2.focus();
|
137
299
|
setFocusedIndex(index);
|
138
300
|
}, [setFocusedIndex, index]);
|
139
|
-
const onKeyDown = (0,
|
301
|
+
const onKeyDown = (0, import_react2.useCallback)(
|
140
302
|
(ev) => {
|
141
303
|
const actions = {
|
142
|
-
ArrowLeft: isNested ? (0,
|
304
|
+
ArrowLeft: isNested ? (0, import_utils3.funcAll)(onUpstreamRestoreFocus, onClose) : void 0
|
143
305
|
};
|
144
306
|
const action = actions[ev.key];
|
145
307
|
if (!action) return;
|
@@ -152,16 +314,16 @@ var MenuItem = (0, import_core2.forwardRef)(
|
|
152
314
|
const rest = (0, import_use_clickable.useClickable)({
|
153
315
|
focusOnClick: false,
|
154
316
|
...props,
|
155
|
-
onClick: (0,
|
156
|
-
onFocus: (0,
|
157
|
-
onMouseOver: (0,
|
158
|
-
onMouseLeave: (0,
|
159
|
-
onKeyDown: (0,
|
160
|
-
ref: (0,
|
317
|
+
onClick: (0, import_utils3.handlerAll)(props.onClick, onClick),
|
318
|
+
onFocus: (0, import_utils3.handlerAll)(props.onFocus, onFocus),
|
319
|
+
onMouseOver: (0, import_utils3.handlerAll)(props.onMouseOver, onMouseOver),
|
320
|
+
onMouseLeave: (0, import_utils3.handlerAll)(props.onMouseLeave, onMouseLeave),
|
321
|
+
onKeyDown: (0, import_utils3.handlerAll)(props.onKeyDown, onKeyDown, onKeyDownRef.current),
|
322
|
+
ref: (0, import_utils3.mergeRefs)(register, itemRef, ref),
|
161
323
|
isDisabled,
|
162
324
|
isFocusable
|
163
325
|
});
|
164
|
-
(0,
|
326
|
+
(0, import_utils3.useUpdateEffect)(() => {
|
165
327
|
if (!isOpen) return;
|
166
328
|
const id = requestAnimationFrameId.current;
|
167
329
|
if (isFocused && !trulyDisabled && itemRef.current) {
|
@@ -171,7 +333,7 @@ var MenuItem = (0, import_core2.forwardRef)(
|
|
171
333
|
(_a2 = itemRef.current) == null ? void 0 : _a2.focus({ preventScroll: true });
|
172
334
|
requestAnimationFrameId.current = null;
|
173
335
|
});
|
174
|
-
} else if (menuRef.current && !(0,
|
336
|
+
} else if (menuRef.current && !(0, import_utils3.isActiveElement)(menuRef.current)) {
|
175
337
|
menuRef.current.focus({ preventScroll: true });
|
176
338
|
}
|
177
339
|
return () => {
|
@@ -208,7 +370,7 @@ var MenuItem = (0, import_core2.forwardRef)(
|
|
208
370
|
...isDownstreamOpen ? { "data-active": "" } : {},
|
209
371
|
role: "menuitem",
|
210
372
|
tabIndex: isFocused ? 0 : -1,
|
211
|
-
className: (0,
|
373
|
+
className: (0, import_utils3.cx)("ui-menu__item", className),
|
212
374
|
__css: css,
|
213
375
|
children: [
|
214
376
|
icon ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MenuIcon, { children: icon }) : null,
|
@@ -227,8 +389,8 @@ var MenuOptionItem = (0, import_core2.forwardRef)(
|
|
227
389
|
MenuItem,
|
228
390
|
{
|
229
391
|
ref,
|
230
|
-
className: (0,
|
231
|
-
"aria-checked": (0,
|
392
|
+
className: (0, import_utils3.cx)("ui-menu__item--option", className),
|
393
|
+
"aria-checked": (0, import_utils3.ariaAttr)(isChecked),
|
232
394
|
closeOnSelect,
|
233
395
|
...rest,
|
234
396
|
children: [
|
@@ -254,7 +416,7 @@ var MenuIcon = (0, import_core2.forwardRef)(
|
|
254
416
|
import_core2.ui.span,
|
255
417
|
{
|
256
418
|
ref,
|
257
|
-
className: (0,
|
419
|
+
className: (0, import_utils3.cx)("ui-menu__item__icon", className),
|
258
420
|
__css: css,
|
259
421
|
...rest
|
260
422
|
}
|
@@ -269,7 +431,7 @@ var MenuCommand = (0, import_core2.forwardRef)(
|
|
269
431
|
import_core2.ui.span,
|
270
432
|
{
|
271
433
|
ref,
|
272
|
-
className: (0,
|
434
|
+
className: (0, import_utils3.cx)("ui-menu__item__command", className),
|
273
435
|
__css: css,
|
274
436
|
...rest
|
275
437
|
}
|
@@ -284,178 +446,9 @@ var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { view
|
|
284
446
|
}
|
285
447
|
) });
|
286
448
|
|
287
|
-
// src/menu.tsx
|
288
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
289
|
-
var {
|
290
|
-
DescendantsContextProvider,
|
291
|
-
useDescendantsContext: useMenuDescendantsContext,
|
292
|
-
useDescendants,
|
293
|
-
useDescendant: useMenuDescendant
|
294
|
-
} = (0, import_use_descendant.createDescendant)();
|
295
|
-
var [MenuProvider, useMenu] = (0, import_utils3.createContext)({
|
296
|
-
name: "MenuContext",
|
297
|
-
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
298
|
-
});
|
299
|
-
var [UpstreamMenuProvider, useUpstreamMenu] = (0, import_utils3.createContext)({
|
300
|
-
strict: false,
|
301
|
-
name: "UpstreamMenuContext"
|
302
|
-
});
|
303
|
-
var Menu = (props) => {
|
304
|
-
var _a, _b, _c;
|
305
|
-
const { styles: contextMenuStyles } = (_a = useContextMenu()) != null ? _a : {};
|
306
|
-
const [styles, mergedProps] = (0, import_core3.useMultiComponentStyle)("Menu", props, {
|
307
|
-
isProcessSkip: !!contextMenuStyles,
|
308
|
-
styles: contextMenuStyles
|
309
|
-
});
|
310
|
-
let {
|
311
|
-
initialFocusRef,
|
312
|
-
closeOnSelect = true,
|
313
|
-
closeOnBlur,
|
314
|
-
placement,
|
315
|
-
duration = 0.2,
|
316
|
-
offset,
|
317
|
-
onOpen: onOpenProp,
|
318
|
-
onClose: onCloseProp,
|
319
|
-
...rest
|
320
|
-
} = (0, import_core3.omitThemeProps)(mergedProps);
|
321
|
-
const { relatedRef, onUpstreamClose, onDownstreamCloseMapRef } = (_b = useUpstreamMenu()) != null ? _b : {};
|
322
|
-
const { setDownstreamOpen, hasDownstreamRef } = (_c = useUpstreamMenuItem()) != null ? _c : {};
|
323
|
-
const isNested = !!relatedRef;
|
324
|
-
if (isNested) {
|
325
|
-
placement != null ? placement : placement = "right-start";
|
326
|
-
offset != null ? offset : offset = [-8, 8];
|
327
|
-
closeOnBlur != null ? closeOnBlur : closeOnBlur = false;
|
328
|
-
} else {
|
329
|
-
placement != null ? placement : placement = "bottom-start";
|
330
|
-
}
|
331
|
-
const descendants = useDescendants();
|
332
|
-
const [focusedIndex, setFocusedIndex] = (0, import_react2.useState)(-1);
|
333
|
-
const menuRef = (0, import_react2.useRef)(null);
|
334
|
-
const timeoutIds = (0, import_react2.useRef)(/* @__PURE__ */ new Set([]));
|
335
|
-
const requestAnimationFrameId = (0, import_react2.useRef)(null);
|
336
|
-
const onCloseMapRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
337
|
-
const onFocusMenu = (0, import_react2.useCallback)(() => {
|
338
|
-
requestAnimationFrame(
|
339
|
-
() => {
|
340
|
-
var _a2;
|
341
|
-
return (_a2 = menuRef.current) == null ? void 0 : _a2.focus({ preventScroll: false });
|
342
|
-
}
|
343
|
-
);
|
344
|
-
}, []);
|
345
|
-
const onFocusFirstItem = (0, import_react2.useCallback)(() => {
|
346
|
-
const id2 = setTimeout(() => {
|
347
|
-
if (initialFocusRef) return;
|
348
|
-
const first = descendants.enabledFirstValue();
|
349
|
-
if (first) setFocusedIndex(first.index);
|
350
|
-
});
|
351
|
-
timeoutIds.current.add(id2);
|
352
|
-
}, [descendants, initialFocusRef]);
|
353
|
-
const onFocusLastItem = (0, import_react2.useCallback)(() => {
|
354
|
-
const id2 = setTimeout(() => {
|
355
|
-
if (initialFocusRef) return;
|
356
|
-
const last = descendants.enabledLastValue();
|
357
|
-
if (last) setFocusedIndex(last.index);
|
358
|
-
});
|
359
|
-
timeoutIds.current.add(id2);
|
360
|
-
}, [descendants, initialFocusRef]);
|
361
|
-
const onOpenInternal = (0, import_react2.useCallback)(() => {
|
362
|
-
onOpenProp == null ? void 0 : onOpenProp();
|
363
|
-
if (!isNested) onFocusMenu();
|
364
|
-
}, [onOpenProp, isNested, onFocusMenu]);
|
365
|
-
const onCloseInternal = (0, import_react2.useCallback)(() => {
|
366
|
-
onCloseProp == null ? void 0 : onCloseProp();
|
367
|
-
for (const onClose2 of onCloseMapRef.current.values()) {
|
368
|
-
onClose2();
|
369
|
-
}
|
370
|
-
}, [onCloseProp]);
|
371
|
-
const id = (0, import_react2.useId)();
|
372
|
-
const { isOpen, onOpen, onClose } = (0, import_use_disclosure.useDisclosure)({
|
373
|
-
...props,
|
374
|
-
onOpen: onOpenInternal,
|
375
|
-
onClose: onCloseInternal
|
376
|
-
});
|
377
|
-
(0, import_react2.useEffect)(() => {
|
378
|
-
const onCloseMap = onDownstreamCloseMapRef == null ? void 0 : onDownstreamCloseMapRef.current;
|
379
|
-
onCloseMap == null ? void 0 : onCloseMap.set(id, onClose);
|
380
|
-
return () => {
|
381
|
-
onCloseMap == null ? void 0 : onCloseMap.delete(id);
|
382
|
-
};
|
383
|
-
}, [id, onClose, onDownstreamCloseMapRef]);
|
384
|
-
(0, import_react2.useEffect)(() => {
|
385
|
-
if (setDownstreamOpen) setDownstreamOpen(isOpen);
|
386
|
-
}, [setDownstreamOpen, isOpen]);
|
387
|
-
(0, import_react2.useEffect)(() => {
|
388
|
-
if (hasDownstreamRef) hasDownstreamRef.current = true;
|
389
|
-
return () => {
|
390
|
-
if (hasDownstreamRef) hasDownstreamRef.current = false;
|
391
|
-
};
|
392
|
-
});
|
393
|
-
(0, import_utils3.useUpdateEffect)(() => {
|
394
|
-
if (!isOpen) setFocusedIndex(-1);
|
395
|
-
}, [isOpen]);
|
396
|
-
(0, import_utils3.useUnmountEffect)(() => {
|
397
|
-
timeoutIds.current.forEach((id2) => clearTimeout(id2));
|
398
|
-
timeoutIds.current.clear();
|
399
|
-
});
|
400
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
401
|
-
UpstreamMenuProvider,
|
402
|
-
{
|
403
|
-
value: {
|
404
|
-
relatedRef: menuRef,
|
405
|
-
onDownstreamCloseMapRef: onCloseMapRef,
|
406
|
-
onUpstreamClose: (0, import_utils3.funcAll)(onUpstreamClose, onClose)
|
407
|
-
},
|
408
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
409
|
-
MenuProvider,
|
410
|
-
{
|
411
|
-
value: {
|
412
|
-
isOpen,
|
413
|
-
onOpen,
|
414
|
-
onClose,
|
415
|
-
onUpstreamClose,
|
416
|
-
onFocusFirstItem,
|
417
|
-
onFocusLastItem,
|
418
|
-
closeOnSelect,
|
419
|
-
focusedIndex,
|
420
|
-
setFocusedIndex,
|
421
|
-
menuRef,
|
422
|
-
requestAnimationFrameId,
|
423
|
-
isNested,
|
424
|
-
styles
|
425
|
-
},
|
426
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
427
|
-
import_popover.Popover,
|
428
|
-
{
|
429
|
-
...{
|
430
|
-
trigger: isNested ? "hover" : "click",
|
431
|
-
...rest,
|
432
|
-
isOpen,
|
433
|
-
onOpen,
|
434
|
-
onClose,
|
435
|
-
placement,
|
436
|
-
offset,
|
437
|
-
duration,
|
438
|
-
initialFocusRef,
|
439
|
-
relatedRef,
|
440
|
-
closeOnButton: false,
|
441
|
-
closeOnBlur
|
442
|
-
}
|
443
|
-
}
|
444
|
-
)
|
445
|
-
}
|
446
|
-
)
|
447
|
-
}
|
448
|
-
) });
|
449
|
-
};
|
450
|
-
|
451
449
|
// src/menu-button.tsx
|
452
|
-
var
|
453
|
-
var
|
454
|
-
var import_popover2 = require("@yamada-ui/popover");
|
455
|
-
var import_utils4 = require("@yamada-ui/utils");
|
456
|
-
var import_react3 = require("react");
|
457
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
458
|
-
var MenuButton = (0, import_core4.forwardRef)(
|
450
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
451
|
+
var MenuButton = (0, import_core3.forwardRef)(
|
459
452
|
({ className, children, as, ...rest }, ref) => {
|
460
453
|
var _a;
|
461
454
|
const { onKeyDownRef, onUpstreamRestoreFocus } = (_a = useUpstreamMenuItem()) != null ? _a : {};
|
@@ -488,8 +481,8 @@ var MenuButton = (0, import_core4.forwardRef)(
|
|
488
481
|
[isOpen, onOpen, onFocusFirstItem, onUpstreamRestoreFocus, onClose]
|
489
482
|
);
|
490
483
|
(0, import_utils4.assignRef)(onKeyDownRef, onItemKeyDown);
|
491
|
-
const Component = (0, import_react3.useMemo)(() => as ? (0,
|
492
|
-
return /* @__PURE__ */ (0,
|
484
|
+
const Component = (0, import_react3.useMemo)(() => as ? (0, import_core3.ui)(as) : Button, [as]);
|
485
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
493
486
|
Component,
|
494
487
|
{
|
495
488
|
ref,
|
@@ -504,7 +497,7 @@ var MenuButton = (0, import_core4.forwardRef)(
|
|
504
497
|
) });
|
505
498
|
}
|
506
499
|
);
|
507
|
-
var Button = (0,
|
500
|
+
var Button = (0, import_core3.forwardRef)((rest, ref) => {
|
508
501
|
const { styles } = useMenu();
|
509
502
|
const css = {
|
510
503
|
display: "inline-flex",
|
@@ -513,11 +506,11 @@ var Button = (0, import_core4.forwardRef)((rest, ref) => {
|
|
513
506
|
outline: 0,
|
514
507
|
...styles.button
|
515
508
|
};
|
516
|
-
return /* @__PURE__ */ (0,
|
509
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.button, { ref, __css: css, ...rest });
|
517
510
|
});
|
518
|
-
var MenuItemButton = (0,
|
511
|
+
var MenuItemButton = (0, import_core3.forwardRef)(
|
519
512
|
({ className, children, innerProps, icon, iconProps, ...rest }, ref) => {
|
520
|
-
return /* @__PURE__ */ (0,
|
513
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
521
514
|
MenuButton,
|
522
515
|
{
|
523
516
|
ref,
|
@@ -525,8 +518,8 @@ var MenuItemButton = (0, import_core4.forwardRef)(
|
|
525
518
|
flex: "1",
|
526
519
|
...rest,
|
527
520
|
children: [
|
528
|
-
/* @__PURE__ */ (0,
|
529
|
-
/* @__PURE__ */ (0,
|
521
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.span, { as: "span", flex: "1", ...innerProps, children }),
|
522
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MenuIcon, { ...iconProps, children: icon != null ? icon : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icon.ChevronIcon, { fontSize: "1.5em", transform: "rotate(-90deg)" }) })
|
530
523
|
]
|
531
524
|
}
|
532
525
|
);
|
@@ -534,12 +527,12 @@ var MenuItemButton = (0, import_core4.forwardRef)(
|
|
534
527
|
);
|
535
528
|
|
536
529
|
// src/menu-list.tsx
|
537
|
-
var
|
530
|
+
var import_core4 = require("@yamada-ui/core");
|
538
531
|
var import_popover3 = require("@yamada-ui/popover");
|
539
532
|
var import_utils5 = require("@yamada-ui/utils");
|
540
533
|
var import_react4 = require("react");
|
541
|
-
var
|
542
|
-
var MenuList = (0,
|
534
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
535
|
+
var MenuList = (0, import_core4.forwardRef)(
|
543
536
|
({ className, contentProps, children, ...rest }, ref) => {
|
544
537
|
const { menuRef, focusedIndex, setFocusedIndex, onClose, styles } = useMenu();
|
545
538
|
const descendants = useMenuDescendantsContext();
|
@@ -576,7 +569,7 @@ var MenuList = (0, import_core5.forwardRef)(
|
|
576
569
|
},
|
577
570
|
[focusedIndex, onClose, onFirst, onLast, onNext, onPrev]
|
578
571
|
);
|
579
|
-
return /* @__PURE__ */ (0,
|
572
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
580
573
|
import_popover3.PopoverContent,
|
581
574
|
{
|
582
575
|
as: "div",
|
@@ -584,8 +577,8 @@ var MenuList = (0, import_core5.forwardRef)(
|
|
584
577
|
__css: { ...styles.content },
|
585
578
|
...contentProps,
|
586
579
|
onKeyDown: (0, import_utils5.handlerAll)(contentProps == null ? void 0 : contentProps.onKeyDown, onKeyDown),
|
587
|
-
children: /* @__PURE__ */ (0,
|
588
|
-
|
580
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
581
|
+
import_core4.ui.ul,
|
589
582
|
{
|
590
583
|
ref: (0, import_utils5.mergeRefs)(menuRef, ref),
|
591
584
|
role: "menu",
|
@@ -602,15 +595,15 @@ var MenuList = (0, import_core5.forwardRef)(
|
|
602
595
|
);
|
603
596
|
|
604
597
|
// src/menu-group.tsx
|
605
|
-
var
|
598
|
+
var import_core5 = require("@yamada-ui/core");
|
606
599
|
var import_utils6 = require("@yamada-ui/utils");
|
607
|
-
var
|
608
|
-
var MenuGroup = (0,
|
600
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
601
|
+
var MenuGroup = (0, import_core5.forwardRef)(
|
609
602
|
({ className, label, children, labelProps, ...rest }, ref) => {
|
610
603
|
const { styles } = useMenu();
|
611
604
|
const css = { ...styles.group };
|
612
|
-
return /* @__PURE__ */ (0,
|
613
|
-
|
605
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
606
|
+
import_core5.ui.li,
|
614
607
|
{
|
615
608
|
ref,
|
616
609
|
className: (0, import_utils6.cx)("ui-menu__item", "ui-menu__item--group", className),
|
@@ -618,8 +611,8 @@ var MenuGroup = (0, import_core6.forwardRef)(
|
|
618
611
|
__css: css,
|
619
612
|
...rest,
|
620
613
|
children: [
|
621
|
-
label ? /* @__PURE__ */ (0,
|
622
|
-
|
614
|
+
label ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
615
|
+
import_core5.ui.span,
|
623
616
|
{
|
624
617
|
className: (0, import_utils6.cx)("ui-menu__item--group-label"),
|
625
618
|
__css: styles.groupLabel,
|
@@ -627,7 +620,7 @@ var MenuGroup = (0, import_core6.forwardRef)(
|
|
627
620
|
children: label
|
628
621
|
}
|
629
622
|
) : null,
|
630
|
-
/* @__PURE__ */ (0,
|
623
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.ul, { className: "ui-menu__item__group", children })
|
631
624
|
]
|
632
625
|
}
|
633
626
|
);
|
@@ -638,7 +631,7 @@ var MenuGroup = (0, import_core6.forwardRef)(
|
|
638
631
|
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
639
632
|
var import_utils7 = require("@yamada-ui/utils");
|
640
633
|
var import_react5 = require("react");
|
641
|
-
var
|
634
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
642
635
|
var MenuOptionGroup = (0, import_react5.forwardRef)(
|
643
636
|
({
|
644
637
|
className,
|
@@ -677,7 +670,7 @@ var MenuOptionGroup = (0, import_react5.forwardRef)(
|
|
677
670
|
const isChecked = !isRadio && (0, import_utils7.isArray)(value) ? value.includes(child.props.value) : child.props.value === value;
|
678
671
|
return (0, import_react5.cloneElement)(child, { type, onClick, isChecked });
|
679
672
|
});
|
680
|
-
return /* @__PURE__ */ (0,
|
673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
681
674
|
MenuGroup,
|
682
675
|
{
|
683
676
|
ref,
|
@@ -691,22 +684,33 @@ var MenuOptionGroup = (0, import_react5.forwardRef)(
|
|
691
684
|
MenuOptionGroup.displayName = "MenuOptionGroup";
|
692
685
|
|
693
686
|
// src/menu-divider.tsx
|
694
|
-
var
|
687
|
+
var import_core6 = require("@yamada-ui/core");
|
695
688
|
var import_utils8 = require("@yamada-ui/utils");
|
689
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
690
|
+
var MenuDivider = (0, import_core6.forwardRef)(
|
691
|
+
({ className, ...rest }, ref) => {
|
692
|
+
const { styles } = useMenu();
|
693
|
+
const css = { ...styles.divider };
|
694
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
695
|
+
import_core6.ui.hr,
|
696
|
+
{
|
697
|
+
ref,
|
698
|
+
className: (0, import_utils8.cx)("ui-menu__divider", className),
|
699
|
+
__css: css,
|
700
|
+
...rest
|
701
|
+
}
|
702
|
+
);
|
703
|
+
}
|
704
|
+
);
|
705
|
+
|
706
|
+
// src/context-menu.tsx
|
707
|
+
var import_core7 = require("@yamada-ui/core");
|
696
708
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
697
|
-
var
|
698
|
-
const
|
699
|
-
const
|
700
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
701
|
-
|
702
|
-
{
|
703
|
-
ref,
|
704
|
-
className: (0, import_utils8.cx)("ui-menu__divider", className),
|
705
|
-
__css: css,
|
706
|
-
...rest
|
707
|
-
}
|
708
|
-
);
|
709
|
-
});
|
709
|
+
var ContextMenu = (props) => {
|
710
|
+
const [styles, mergedProps] = (0, import_core7.useComponentMultiStyle)("ContextMenu", props);
|
711
|
+
const { ...rest } = (0, import_core7.omitThemeProps)(mergedProps);
|
712
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ContextMenuProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Menu, { trigger: "contextmenu", ...rest }) });
|
713
|
+
};
|
710
714
|
|
711
715
|
// src/context-menu-trigger.tsx
|
712
716
|
var import_core8 = require("@yamada-ui/core");
|