@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
package/dist/menu.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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.tsx
|
|
21
|
+
var menu_exports = {};
|
|
22
|
+
__export(menu_exports, {
|
|
23
|
+
Menu: () => Menu,
|
|
24
|
+
useMenu: () => useMenu,
|
|
25
|
+
useMenuDescendant: () => useMenuDescendant,
|
|
26
|
+
useMenuDescendantsContext: () => useMenuDescendantsContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(menu_exports);
|
|
29
|
+
var import_core = require("@yamada-ui/core");
|
|
30
|
+
var import_popover = require("@yamada-ui/popover");
|
|
31
|
+
var import_use_descendant = require("@yamada-ui/use-descendant");
|
|
32
|
+
var import_use_disclosure = require("@yamada-ui/use-disclosure");
|
|
33
|
+
var import_utils = require("@yamada-ui/utils");
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var {
|
|
37
|
+
DescendantsContextProvider,
|
|
38
|
+
useDescendantsContext: useMenuDescendantsContext,
|
|
39
|
+
useDescendants,
|
|
40
|
+
useDescendant: useMenuDescendant
|
|
41
|
+
} = (0, import_use_descendant.createDescendant)();
|
|
42
|
+
var [MenuProvider, useMenu] = (0, import_utils.createContext)({
|
|
43
|
+
name: "MenuContext",
|
|
44
|
+
errorMessage: `useMenu returned is 'undefined'. Seems you forgot to wrap the components in "<Menu />"`
|
|
45
|
+
});
|
|
46
|
+
var Menu = (props) => {
|
|
47
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Menu", props);
|
|
48
|
+
const {
|
|
49
|
+
initialFocusRef,
|
|
50
|
+
closeOnSelect = true,
|
|
51
|
+
placement = "bottom-start",
|
|
52
|
+
duration = 0.2,
|
|
53
|
+
...rest
|
|
54
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
55
|
+
const descendants = useDescendants();
|
|
56
|
+
const [focusedIndex, setFocusedIndex] = (0, import_react.useState)(-1);
|
|
57
|
+
const menuRef = (0, import_react.useRef)(null);
|
|
58
|
+
const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
|
|
59
|
+
const onFocusMenu = (0, import_react.useCallback)(() => {
|
|
60
|
+
requestAnimationFrame(() => {
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = menuRef.current) == null ? void 0 : _a.focus({ preventScroll: false });
|
|
63
|
+
});
|
|
64
|
+
}, []);
|
|
65
|
+
const onFocusFirstItem = (0, import_react.useCallback)(() => {
|
|
66
|
+
const id = setTimeout(() => {
|
|
67
|
+
if (initialFocusRef)
|
|
68
|
+
return;
|
|
69
|
+
const first = descendants.enabledfirstValue();
|
|
70
|
+
if (first)
|
|
71
|
+
setFocusedIndex(first.index);
|
|
72
|
+
});
|
|
73
|
+
timeoutIds.current.add(id);
|
|
74
|
+
}, [descendants, initialFocusRef]);
|
|
75
|
+
const onFocusLastItem = (0, import_react.useCallback)(() => {
|
|
76
|
+
const id = setTimeout(() => {
|
|
77
|
+
if (initialFocusRef)
|
|
78
|
+
return;
|
|
79
|
+
const last = descendants.enabledlastValue();
|
|
80
|
+
if (last)
|
|
81
|
+
setFocusedIndex(last.index);
|
|
82
|
+
});
|
|
83
|
+
timeoutIds.current.add(id);
|
|
84
|
+
}, [descendants, initialFocusRef]);
|
|
85
|
+
const onOpenInternal = (0, import_react.useCallback)(() => {
|
|
86
|
+
var _a;
|
|
87
|
+
(_a = rest.onOpen) == null ? void 0 : _a.call(rest);
|
|
88
|
+
onFocusMenu();
|
|
89
|
+
}, [onFocusMenu, rest]);
|
|
90
|
+
const [isOpen, onOpen, onClose] = (0, import_use_disclosure.useDisclosure)({ ...props, onOpen: onOpenInternal });
|
|
91
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
92
|
+
if (!isOpen)
|
|
93
|
+
setFocusedIndex(-1);
|
|
94
|
+
}, [isOpen]);
|
|
95
|
+
(0, import_utils.useUnmountEffect)(() => {
|
|
96
|
+
timeoutIds.current.forEach((id) => clearTimeout(id));
|
|
97
|
+
timeoutIds.current.clear();
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
MenuProvider,
|
|
101
|
+
{
|
|
102
|
+
value: {
|
|
103
|
+
isOpen,
|
|
104
|
+
onOpen,
|
|
105
|
+
onClose,
|
|
106
|
+
onFocusFirstItem,
|
|
107
|
+
onFocusLastItem,
|
|
108
|
+
closeOnSelect,
|
|
109
|
+
focusedIndex,
|
|
110
|
+
setFocusedIndex,
|
|
111
|
+
menuRef,
|
|
112
|
+
styles
|
|
113
|
+
},
|
|
114
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
|
+
import_popover.Popover,
|
|
116
|
+
{
|
|
117
|
+
...{
|
|
118
|
+
...rest,
|
|
119
|
+
isOpen,
|
|
120
|
+
onOpen,
|
|
121
|
+
onClose,
|
|
122
|
+
placement,
|
|
123
|
+
duration,
|
|
124
|
+
initialFocusRef,
|
|
125
|
+
closeOnButton: false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
) });
|
|
131
|
+
};
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
Menu,
|
|
135
|
+
useMenu,
|
|
136
|
+
useMenuDescendant,
|
|
137
|
+
useMenuDescendantsContext
|
|
138
|
+
});
|
package/dist/menu.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yamada-ui/menu",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Yamada UI menu component",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yamada",
|
|
7
|
+
"yamada ui",
|
|
8
|
+
"react",
|
|
9
|
+
"emotion",
|
|
10
|
+
"component",
|
|
11
|
+
"menu",
|
|
12
|
+
"ui",
|
|
13
|
+
"uikit",
|
|
14
|
+
"styled",
|
|
15
|
+
"style-props",
|
|
16
|
+
"styled-component",
|
|
17
|
+
"css-in-js"
|
|
18
|
+
],
|
|
19
|
+
"author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/hirotomoyamada/yamada-ui",
|
|
32
|
+
"directory": "packages/components/menu"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@yamada-ui/core": "0.1.0",
|
|
39
|
+
"@yamada-ui/utils": "0.1.0",
|
|
40
|
+
"@yamada-ui/popover": "0.1.0",
|
|
41
|
+
"@yamada-ui/transitions": "0.1.0",
|
|
42
|
+
"@yamada-ui/use-disclosure": "0.1.0",
|
|
43
|
+
"@yamada-ui/use-descendant": "0.1.0",
|
|
44
|
+
"@yamada-ui/use-controllable-state": "0.1.0",
|
|
45
|
+
"@yamada-ui/use-clickable": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"react": "^18.0.0",
|
|
49
|
+
"clean-package": "2.2.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"clean-package": "../../../clean-package.config.json",
|
|
55
|
+
"tsup": {
|
|
56
|
+
"clean": true,
|
|
57
|
+
"target": "es2019",
|
|
58
|
+
"format": [
|
|
59
|
+
"cjs",
|
|
60
|
+
"esm"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"module": "dist/index.mjs",
|
|
64
|
+
"types": "dist/index.d.ts",
|
|
65
|
+
"exports": {
|
|
66
|
+
".": {
|
|
67
|
+
"types": "./dist/index.d.ts",
|
|
68
|
+
"import": "./dist/index.mjs",
|
|
69
|
+
"require": "./dist/index.js"
|
|
70
|
+
},
|
|
71
|
+
"./package.json": "./package.json"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"dev": "pnpm build:fast -- --watch",
|
|
75
|
+
"build": "tsup src --dts",
|
|
76
|
+
"build:fast": "tsup src",
|
|
77
|
+
"clean": "rimraf dist .turbo",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"gen:docs": "tsx ../../../scripts/generate-docs"
|
|
80
|
+
}
|
|
81
|
+
}
|