@y14e/menu 1.4.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yusuke Kamiyamane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Menu
2
+
3
+ WAI-ARIA compliant menu ([menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/)) pattern implementation in TypeScript. Supports checkbox item, radio item, and infinitely nested menus.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @y14e/menu
9
+ ```
10
+
11
+ ```ts
12
+ // npm
13
+ import Tabs from '@y14e/menu@1.4.0';
14
+
15
+ // CDNs
16
+ import Tabs from 'https://esm.sh/@y14e/menu@1.4.0';
17
+ // or
18
+ import Tabs from 'https://cdn.jsdelivr.net/npm/@y14e/menu@1.4.0/+esm';
19
+ // or
20
+ import Tabs from 'https://esm.unpkg.com/@y14e/menu@1.4.0';
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ new Menu(root, options);
27
+ // => Menu
28
+ //
29
+ // root: HTMLElement
30
+ // options (optional): MenuOptions
31
+
32
+ ```
33
+
34
+ ## 🪄 Options
35
+
36
+ ```ts
37
+ interface MenuOptions {
38
+ animation?: {
39
+ duration?: number; // ms (default: 300)
40
+ };
41
+ delay?: number; // ms (default: 200)
42
+ popover?: {
43
+ menu?: MenuPopoverOptions;
44
+ submenu?: MenuPopoverOptions;
45
+ transformOrigin?: boolean; // default: true
46
+ };
47
+ selector?: {
48
+ checkboxItem?: string; // default: '[role="menuitemcheckbox"]'
49
+ group?: string; // default: '[role="group"]'
50
+ item?: string; // default: '[role^="menuitem"]'
51
+ list?: string; // default: '[role="menu"]'
52
+ radioItem?: string; // default: '[role="menuitemradio"]'
53
+ trigger?: string; // default: '[data-menu-trigger]'
54
+ };
55
+ }
56
+
57
+ interface MenuPopoverOptions {
58
+ arrow?: boolean; // default: true
59
+ middleware?: Middleware[]; // default: [flip(), offset(), shift()]
60
+ placement?: Placement; // default: 'bottom-start' (menu) / 'right-start' (submenu)
61
+ }
62
+ ```
63
+
64
+ > [!NOTE]
65
+ > `Middleware` and `Placement` are provided by [Floating UI](https://floating-ui.com/). See the Floating UI docs for details.
66
+
67
+ ### ⚙️ Customize defaults
68
+
69
+ Override the global default settings applied to all menu instances.
70
+
71
+ ```ts
72
+ import Menu from './menu';
73
+
74
+ Menu.defaults = {
75
+ delay: 500,
76
+ selector: {
77
+ trigger: '.trigger',
78
+ },
79
+ };
80
+
81
+ new Menu(root);
82
+ ```
83
+
84
+ ## 📦 APIs
85
+
86
+ ### `open`
87
+
88
+ ```ts
89
+ menu.open();
90
+ // => void
91
+ ```
92
+
93
+ ### `close`
94
+
95
+ ```ts
96
+ menu.close();
97
+ // => void
98
+ ```
99
+
100
+ ### `destroy`
101
+
102
+ Destroys the instance and cleans up all event listeners and submenus.
103
+
104
+ ```ts
105
+ menu.destroy(force);
106
+ // => Promise<void>
107
+ //
108
+ // force (optional): If true, skips waiting for animations to finish.
109
+ ```
110
+
111
+ ## Demo
112
+
113
+ https://y14e.github.io/menu/
114
+
115
+ ## Credits
116
+
117
+ * [Floating UI](https://floating-ui.com/)