@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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/chunk-6ALPY7K4.mjs +111 -0
- package/dist/chunk-OFZGIB33.mjs +374 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +504 -0
- package/dist/index.mjs +28 -0
- package/dist/menu-button.d.ts +7 -0
- package/dist/menu-button.js +100 -0
- package/dist/menu-button.mjs +7 -0
- package/dist/menu-divider.d.ts +7 -0
- package/dist/menu-divider.js +58 -0
- package/dist/menu-divider.mjs +7 -0
- package/dist/menu-group.d.ts +7 -0
- package/dist/menu-group.js +73 -0
- package/dist/menu-group.mjs +7 -0
- package/dist/menu-item.d.ts +23 -0
- package/dist/menu-item.js +202 -0
- package/dist/menu-item.mjs +9 -0
- package/dist/menu-list.d.ts +7 -0
- package/dist/menu-list.js +110 -0
- package/dist/menu-list.mjs +7 -0
- package/dist/menu-option-group.d.ts +15 -0
- package/dist/menu-option-group.js +276 -0
- package/dist/menu-option-group.mjs +7 -0
- package/dist/menu.d.ts +2134 -0
- package/dist/menu.js +138 -0
- package/dist/menu.mjs +12 -0
- package/package.json +81 -0
|
@@ -0,0 +1,58 @@
|
|
|
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-divider.tsx
|
|
21
|
+
var menu_divider_exports = {};
|
|
22
|
+
__export(menu_divider_exports, {
|
|
23
|
+
MenuDivider: () => MenuDivider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(menu_divider_exports);
|
|
26
|
+
var import_core2 = require("@yamada-ui/core");
|
|
27
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
28
|
+
|
|
29
|
+
// src/menu.tsx
|
|
30
|
+
var import_core = require("@yamada-ui/core");
|
|
31
|
+
var import_popover = require("@yamada-ui/popover");
|
|
32
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
33
|
+
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
|
34
|
+
var import_utils = require("@yamada-ui/utils");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
var {
|
|
38
|
+
DescendantsContextProvider,
|
|
39
|
+
useDescendantsContext: useMenuDescendantsContext,
|
|
40
|
+
useDescendants,
|
|
41
|
+
useDescendant: useMenuDescendant
|
|
42
|
+
} = (0, import_use_descendant.createDescendant)();
|
|
43
|
+
var [MenuProvider, useMenu] = (0, import_utils.createContext)({
|
|
44
|
+
name: "MenuContext",
|
|
45
|
+
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/menu-divider.tsx
|
|
49
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
50
|
+
var MenuDivider = (0, import_core2.forwardRef)(({ className, ...rest }, ref) => {
|
|
51
|
+
const { styles } = useMenu();
|
|
52
|
+
const css = { ...styles.divider };
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.hr, { ref, className: (0, import_utils2.cx)("ui-menu-divider", className), __css: css, ...rest });
|
|
54
|
+
});
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
MenuDivider
|
|
58
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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-group.tsx
|
|
21
|
+
var menu_group_exports = {};
|
|
22
|
+
__export(menu_group_exports, {
|
|
23
|
+
MenuGroup: () => MenuGroup
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(menu_group_exports);
|
|
26
|
+
var import_core2 = require("@yamada-ui/core");
|
|
27
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
28
|
+
|
|
29
|
+
// src/menu.tsx
|
|
30
|
+
var import_core = require("@yamada-ui/core");
|
|
31
|
+
var import_popover = require("@yamada-ui/popover");
|
|
32
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
33
|
+
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
|
34
|
+
var import_utils = require("@yamada-ui/utils");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
var {
|
|
38
|
+
DescendantsContextProvider,
|
|
39
|
+
useDescendantsContext: useMenuDescendantsContext,
|
|
40
|
+
useDescendants,
|
|
41
|
+
useDescendant: useMenuDescendant
|
|
42
|
+
} = (0, import_use_descendant.createDescendant)();
|
|
43
|
+
var [MenuProvider, useMenu] = (0, import_utils.createContext)({
|
|
44
|
+
name: "MenuContext",
|
|
45
|
+
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/menu-group.tsx
|
|
49
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
50
|
+
var MenuGroup = (0, import_core2.forwardRef)(
|
|
51
|
+
({ className, title, children, ...rest }, ref) => {
|
|
52
|
+
const { styles } = useMenu();
|
|
53
|
+
const css = { ...styles.group };
|
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
55
|
+
import_core2.ui.div,
|
|
56
|
+
{
|
|
57
|
+
ref,
|
|
58
|
+
className: (0, import_utils2.cx)("ui-menu-group", className),
|
|
59
|
+
role: "group",
|
|
60
|
+
__css: css,
|
|
61
|
+
...rest,
|
|
62
|
+
children: [
|
|
63
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { className: (0, import_utils2.cx)("ui-menu-group-title"), __css: styles.groupTitle, children: title }) : null,
|
|
64
|
+
children
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
MenuGroup
|
|
73
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
type MenuItemOptions = {
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
isFocusable?: boolean;
|
|
8
|
+
closeOnSelect?: boolean;
|
|
9
|
+
icon?: ReactElement;
|
|
10
|
+
command?: string;
|
|
11
|
+
};
|
|
12
|
+
type MenuItemProps = HTMLUIProps<'button'> & MenuItemOptions;
|
|
13
|
+
declare const MenuItem: _yamada_ui_core.Component<"button", MenuItemProps>;
|
|
14
|
+
type MenuOptionItemOptions = {
|
|
15
|
+
icon?: ReactElement | null;
|
|
16
|
+
value?: string;
|
|
17
|
+
isChecked?: boolean;
|
|
18
|
+
type?: 'radio' | 'checkbox';
|
|
19
|
+
};
|
|
20
|
+
type MenuOptionItemProps = Omit<MenuItemProps, 'icon' | 'command'> & MenuOptionItemOptions;
|
|
21
|
+
declare const MenuOptionItem: _yamada_ui_core.Component<"button", MenuOptionItemProps>;
|
|
22
|
+
|
|
23
|
+
export { MenuItem, MenuItemProps, MenuOptionItem, MenuOptionItemProps };
|
|
@@ -0,0 +1,202 @@
|
|
|
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-item.tsx
|
|
21
|
+
var menu_item_exports = {};
|
|
22
|
+
__export(menu_item_exports, {
|
|
23
|
+
MenuItem: () => MenuItem,
|
|
24
|
+
MenuOptionItem: () => MenuOptionItem
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(menu_item_exports);
|
|
27
|
+
var import_core2 = require("@yamada-ui/core");
|
|
28
|
+
var import_use_clickable = require("@yamada-ui/use-clickable");
|
|
29
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
30
|
+
var import_react2 = require("react");
|
|
31
|
+
|
|
32
|
+
// src/menu.tsx
|
|
33
|
+
var import_core = require("@yamada-ui/core");
|
|
34
|
+
var import_popover = require("@yamada-ui/popover");
|
|
35
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
36
|
+
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
|
37
|
+
var import_utils = require("@yamada-ui/utils");
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var {
|
|
41
|
+
DescendantsContextProvider,
|
|
42
|
+
useDescendantsContext: useMenuDescendantsContext,
|
|
43
|
+
useDescendants,
|
|
44
|
+
useDescendant: useMenuDescendant
|
|
45
|
+
} = (0, import_use_descendant.createDescendant)();
|
|
46
|
+
var [MenuProvider, useMenu] = (0, import_utils.createContext)({
|
|
47
|
+
name: "MenuContext",
|
|
48
|
+
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// src/menu-item.tsx
|
|
52
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
53
|
+
var isTargetMenuItem = (target) => {
|
|
54
|
+
var _a;
|
|
55
|
+
return (0, import_utils2.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("menu-item"));
|
|
56
|
+
};
|
|
57
|
+
var MenuItem = (0, import_core2.forwardRef)(
|
|
58
|
+
({
|
|
59
|
+
as,
|
|
60
|
+
className,
|
|
61
|
+
type,
|
|
62
|
+
isDisabled,
|
|
63
|
+
isFocusable,
|
|
64
|
+
closeOnSelect: customCloseOnSelect,
|
|
65
|
+
icon,
|
|
66
|
+
command,
|
|
67
|
+
children,
|
|
68
|
+
...props
|
|
69
|
+
}, ref) => {
|
|
70
|
+
const {
|
|
71
|
+
focusedIndex,
|
|
72
|
+
setFocusedIndex,
|
|
73
|
+
isOpen,
|
|
74
|
+
onClose,
|
|
75
|
+
closeOnSelect: generalCloseOnSelect,
|
|
76
|
+
menuRef,
|
|
77
|
+
styles
|
|
78
|
+
} = useMenu();
|
|
79
|
+
const trulyDisabled = isDisabled && !isFocusable;
|
|
80
|
+
const buttonRef = (0, import_react2.useRef)(null);
|
|
81
|
+
const { index, register } = useMenuDescendant({ disabled: trulyDisabled });
|
|
82
|
+
const isFocused = index === focusedIndex;
|
|
83
|
+
const onClick = (0, import_react2.useCallback)(
|
|
84
|
+
(ev) => {
|
|
85
|
+
var _a;
|
|
86
|
+
(_a = props.onClick) == null ? void 0 : _a.call(props, ev);
|
|
87
|
+
if (!isTargetMenuItem(ev.currentTarget))
|
|
88
|
+
return;
|
|
89
|
+
if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect)
|
|
90
|
+
onClose();
|
|
91
|
+
},
|
|
92
|
+
[props, customCloseOnSelect, generalCloseOnSelect, onClose]
|
|
93
|
+
);
|
|
94
|
+
const onFocus = (0, import_react2.useCallback)(
|
|
95
|
+
(ev) => {
|
|
96
|
+
var _a;
|
|
97
|
+
(_a = props.onFocus) == null ? void 0 : _a.call(props, ev);
|
|
98
|
+
setFocusedIndex(index);
|
|
99
|
+
},
|
|
100
|
+
[props, setFocusedIndex, index]
|
|
101
|
+
);
|
|
102
|
+
const rest = (0, import_use_clickable.useClickable)({
|
|
103
|
+
onClick,
|
|
104
|
+
onFocus,
|
|
105
|
+
ref: (0, import_utils2.mergeRefs)(register, buttonRef, ref),
|
|
106
|
+
isDisabled,
|
|
107
|
+
isFocusable
|
|
108
|
+
});
|
|
109
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
|
110
|
+
if (!isOpen)
|
|
111
|
+
return;
|
|
112
|
+
if (isFocused && !trulyDisabled && buttonRef.current) {
|
|
113
|
+
requestAnimationFrame(() => {
|
|
114
|
+
var _a;
|
|
115
|
+
return (_a = buttonRef.current) == null ? void 0 : _a.focus();
|
|
116
|
+
});
|
|
117
|
+
} else if (menuRef.current && !(0, import_utils2.isActiveElement)(menuRef.current)) {
|
|
118
|
+
menuRef.current.focus();
|
|
119
|
+
}
|
|
120
|
+
}, [isFocused, trulyDisabled, menuRef, isOpen]);
|
|
121
|
+
type = as || type ? type != null ? type : void 0 : "button";
|
|
122
|
+
children = icon || command ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { style: { pointerEvents: "none", flex: 1 }, children }) : children;
|
|
123
|
+
const css = {
|
|
124
|
+
textDecoration: "none",
|
|
125
|
+
color: "inherit",
|
|
126
|
+
userSelect: "none",
|
|
127
|
+
display: "flex",
|
|
128
|
+
width: "100%",
|
|
129
|
+
alignItems: "center",
|
|
130
|
+
textAlign: "start",
|
|
131
|
+
flex: "0 0 auto",
|
|
132
|
+
outline: 0,
|
|
133
|
+
gap: "0.75rem",
|
|
134
|
+
...styles.item
|
|
135
|
+
};
|
|
136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
137
|
+
import_core2.ui.button,
|
|
138
|
+
{
|
|
139
|
+
...props,
|
|
140
|
+
...rest,
|
|
141
|
+
as,
|
|
142
|
+
type,
|
|
143
|
+
role: "menu-item",
|
|
144
|
+
tabInde: isFocused ? 0 : -1,
|
|
145
|
+
className: (0, import_utils2.cx)("ui-menu-item", className),
|
|
146
|
+
__css: css,
|
|
147
|
+
children: [
|
|
148
|
+
icon ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MenuIcon, { children: icon }) : null,
|
|
149
|
+
children,
|
|
150
|
+
command ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MenuCommand, { children: command }) : null
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
var MenuOptionItem = (0, import_core2.forwardRef)(
|
|
157
|
+
({ className, icon, isChecked, closeOnSelect = false, children, ...rest }, ref) => {
|
|
158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
159
|
+
MenuItem,
|
|
160
|
+
{
|
|
161
|
+
ref,
|
|
162
|
+
className: (0, import_utils2.cx)("ui-menu-option-item", className),
|
|
163
|
+
"aria-checked": (0, import_utils2.ariaAttr)(isChecked),
|
|
164
|
+
closeOnSelect,
|
|
165
|
+
...rest,
|
|
166
|
+
children: [
|
|
167
|
+
icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MenuIcon, { opacity: isChecked ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckIcon, {}) }) : null,
|
|
168
|
+
children
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
var MenuIcon = (0, import_core2.forwardRef)(({ className, ...rest }, ref) => {
|
|
175
|
+
const { styles } = useMenu();
|
|
176
|
+
const css = {
|
|
177
|
+
flexShrink: 0,
|
|
178
|
+
display: "inline-flex",
|
|
179
|
+
justifyContent: "center",
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
fontSize: "0.85em",
|
|
182
|
+
...styles.icon
|
|
183
|
+
};
|
|
184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { ref, className: (0, import_utils2.cx)("ui-menu-icon", className), __css: css, ...rest });
|
|
185
|
+
});
|
|
186
|
+
var MenuCommand = (0, import_core2.forwardRef)(({ className, ...rest }, ref) => {
|
|
187
|
+
const { styles } = useMenu();
|
|
188
|
+
const css = { ...styles.command };
|
|
189
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { ref, className: (0, import_utils2.cx)("ui-menu-command", className), __css: css, ...rest });
|
|
190
|
+
});
|
|
191
|
+
var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
192
|
+
"polygon",
|
|
193
|
+
{
|
|
194
|
+
fill: "currentColor",
|
|
195
|
+
points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
|
|
196
|
+
}
|
|
197
|
+
) });
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
MenuItem,
|
|
201
|
+
MenuOptionItem
|
|
202
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
|
|
4
|
+
type MenuListProps = HTMLUIProps<'section'>;
|
|
5
|
+
declare const MenuList: _yamada_ui_core.Component<"section", MenuListProps>;
|
|
6
|
+
|
|
7
|
+
export { MenuList, MenuListProps };
|
|
@@ -0,0 +1,110 @@
|
|
|
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-list.tsx
|
|
21
|
+
var menu_list_exports = {};
|
|
22
|
+
__export(menu_list_exports, {
|
|
23
|
+
MenuList: () => MenuList
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(menu_list_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-list.tsx
|
|
51
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
52
|
+
var MenuList = (0, import_core2.forwardRef)(({ className, ...rest }, ref) => {
|
|
53
|
+
const { menuRef, focusedIndex, setFocusedIndex, onClose, styles } = useMenu();
|
|
54
|
+
const descendants = useMenuDescendantsContext();
|
|
55
|
+
const onNext = (0, import_react2.useCallback)(() => {
|
|
56
|
+
const next = descendants.enabledNextValue(focusedIndex);
|
|
57
|
+
if (next)
|
|
58
|
+
setFocusedIndex(next.index);
|
|
59
|
+
}, [descendants, focusedIndex, setFocusedIndex]);
|
|
60
|
+
const onPrev = (0, import_react2.useCallback)(() => {
|
|
61
|
+
const prev = descendants.enabledPrevValue(focusedIndex);
|
|
62
|
+
if (prev)
|
|
63
|
+
setFocusedIndex(prev.index);
|
|
64
|
+
}, [descendants, focusedIndex, setFocusedIndex]);
|
|
65
|
+
const onFirst = (0, import_react2.useCallback)(() => {
|
|
66
|
+
const first = descendants.enabledfirstValue();
|
|
67
|
+
if (first)
|
|
68
|
+
setFocusedIndex(first.index);
|
|
69
|
+
}, [descendants, setFocusedIndex]);
|
|
70
|
+
const onLast = (0, import_react2.useCallback)(() => {
|
|
71
|
+
const last = descendants.enabledlastValue();
|
|
72
|
+
if (last)
|
|
73
|
+
setFocusedIndex(last.index);
|
|
74
|
+
}, [descendants, setFocusedIndex]);
|
|
75
|
+
const onKeyDown = (0, import_react2.useCallback)(
|
|
76
|
+
(ev) => {
|
|
77
|
+
const actions = {
|
|
78
|
+
Tab: (ev2) => ev2.preventDefault(),
|
|
79
|
+
Escape: onClose,
|
|
80
|
+
ArrowDown: focusedIndex === -1 ? onFirst : onNext,
|
|
81
|
+
ArrowUp: focusedIndex === -1 ? onLast : onPrev,
|
|
82
|
+
Home: onFirst,
|
|
83
|
+
End: onLast
|
|
84
|
+
};
|
|
85
|
+
const action = actions[ev.key];
|
|
86
|
+
if (!action)
|
|
87
|
+
return;
|
|
88
|
+
ev.preventDefault();
|
|
89
|
+
action(ev);
|
|
90
|
+
},
|
|
91
|
+
[focusedIndex, onClose, onFirst, onLast, onNext, onPrev]
|
|
92
|
+
);
|
|
93
|
+
const css = { ...styles.list };
|
|
94
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
95
|
+
import_popover2.PopoverContent,
|
|
96
|
+
{
|
|
97
|
+
ref: (0, import_utils2.mergeRefs)(menuRef, ref),
|
|
98
|
+
className: (0, import_utils2.cx)("ui-menu-list", className),
|
|
99
|
+
role: "menu",
|
|
100
|
+
tabIndex: -1,
|
|
101
|
+
__css: css,
|
|
102
|
+
...rest,
|
|
103
|
+
onKeyDown: (0, import_utils2.handlerAll)(rest.onKeyDown, onKeyDown)
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
MenuList
|
|
110
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HTMLUIProps, ComponentArgs } from '@yamada-ui/core';
|
|
2
|
+
import { Ref } from 'react';
|
|
3
|
+
|
|
4
|
+
type MenuOptionGroupOptions<Y extends string | string[] = string> = {
|
|
5
|
+
value?: Y;
|
|
6
|
+
defaultValue?: Y;
|
|
7
|
+
type?: 'radio' | 'checkbox';
|
|
8
|
+
onChange?: (value: Y) => void;
|
|
9
|
+
};
|
|
10
|
+
type MenuOptionGroupProps<Y extends string | string[] = string> = Omit<HTMLUIProps<'div'>, keyof MenuOptionGroupOptions> & MenuOptionGroupOptions<Y>;
|
|
11
|
+
declare const MenuOptionGroup: (<Y extends string | string[] = string>(props: Omit<HTMLUIProps<"div">, keyof MenuOptionGroupOptions<string>> & MenuOptionGroupOptions<Y> & {
|
|
12
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
13
|
+
}) => JSX.Element) & ComponentArgs;
|
|
14
|
+
|
|
15
|
+
export { MenuOptionGroup, MenuOptionGroupProps };
|