mtrl 0.3.0 → 0.3.2
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/.env +15 -0
- package/CONTRIBUTING.md +8 -8
- package/DOCS.md +3 -3
- package/README.md +43 -20
- package/TESTING.md +128 -18
- package/dist/index.js +14865 -0
- package/git-user-stats.js +545 -0
- package/index.ts +9 -69
- package/package.json +10 -3
- package/src/components/badge/api.ts +15 -1
- package/src/components/badge/badge.ts +43 -4
- package/src/components/badge/config.ts +40 -8
- package/src/components/badge/index.ts +64 -3
- package/src/components/badge/types.ts +175 -33
- package/src/components/button/api.ts +63 -1
- package/src/components/button/button.ts +39 -3
- package/src/components/button/config.ts +21 -4
- package/src/components/button/index.ts +26 -1
- package/src/components/button/types.ts +7 -1
- package/src/components/card/api.ts +78 -9
- package/src/components/card/card.ts +58 -3
- package/src/components/card/config.ts +41 -11
- package/src/components/card/features.ts +39 -12
- package/src/components/card/index.ts +84 -19
- package/src/components/card/types.ts +218 -29
- package/src/components/carousel/carousel.ts +92 -28
- package/src/components/carousel/constants.ts +107 -21
- package/src/components/carousel/index.ts +31 -13
- package/src/components/checkbox/checkbox.ts +83 -16
- package/src/components/checkbox/index.ts +43 -1
- package/src/components/checkbox/types.ts +219 -32
- package/src/components/chips/api.ts +194 -0
- package/src/components/{chip → chips/chip}/api.ts +42 -2
- package/src/components/chips/chip/chip.ts +131 -0
- package/src/components/{chip → chips/chip}/config.ts +3 -3
- package/src/components/chips/chip/index.ts +3 -0
- package/src/components/chips/chips.md +481 -0
- package/src/components/chips/chips.ts +75 -0
- package/src/components/chips/config.ts +109 -0
- package/src/components/chips/constants.ts +61 -0
- package/src/components/chips/features/chip-items.ts +33 -0
- package/src/components/chips/features/container.ts +77 -0
- package/src/components/chips/features/controller.ts +448 -0
- package/src/components/chips/features/index.ts +5 -0
- package/src/components/chips/features/label.ts +108 -0
- package/src/components/chips/index.ts +11 -0
- package/src/components/chips/schema.ts +61 -0
- package/src/components/{chip → chips}/types.ts +203 -92
- package/src/components/dialog/dialog.ts +99 -16
- package/src/components/dialog/index.ts +97 -1
- package/src/components/dialog/types.ts +375 -69
- package/src/components/divider/config.ts +90 -6
- package/src/components/divider/divider.ts +32 -2
- package/src/components/divider/features.ts +26 -0
- package/src/components/divider/index.ts +30 -0
- package/src/components/divider/types.ts +86 -9
- package/src/components/extended-fab/api.ts +53 -1
- package/src/components/extended-fab/config.ts +29 -1
- package/src/components/extended-fab/extended-fab.ts +28 -0
- package/src/components/extended-fab/index.ts +36 -0
- package/src/components/extended-fab/types.ts +458 -13
- package/src/components/fab/api.ts +42 -2
- package/src/components/fab/config.ts +29 -1
- package/src/components/fab/fab.ts +16 -2
- package/src/components/fab/index.ts +35 -0
- package/src/components/fab/types.ts +374 -10
- package/src/components/list/api.ts +12 -2
- package/src/components/list/config.ts +21 -0
- package/src/components/list/features.ts +6 -0
- package/src/components/list/index.ts +56 -1
- package/src/components/list/list-item.ts +46 -2
- package/src/components/list/list.ts +73 -2
- package/src/components/list/types.ts +172 -0
- package/src/components/list/utils.ts +26 -2
- package/src/components/menu/api.ts +217 -20
- package/src/components/menu/config.ts +27 -0
- package/src/components/menu/features/visibility.ts +55 -6
- package/src/components/menu/index.ts +64 -0
- package/src/components/menu/menu-item.ts +46 -3
- package/src/components/menu/menu.ts +77 -1
- package/src/components/menu/types.ts +404 -39
- package/src/components/navigation/index.ts +4 -1
- package/src/components/navigation/types.ts +33 -0
- package/src/components/sheet/config.ts +1 -2
- package/src/components/sheet/features/gestures.ts +1 -1
- package/src/components/sheet/features/position.ts +1 -2
- package/src/components/sheet/features/state.ts +1 -1
- package/src/components/sheet/index.ts +10 -2
- package/src/components/sheet/sheet.ts +1 -2
- package/src/components/sheet/types.ts +29 -1
- package/src/components/slider/api.ts +1 -1
- package/src/components/slider/config.ts +1 -1
- package/src/components/slider/features/controller.ts +1 -1
- package/src/components/slider/features/handlers.ts +1 -1
- package/src/components/slider/features/states.ts +1 -1
- package/src/components/slider/index.ts +12 -5
- package/src/components/slider/schema.ts +1 -1
- package/src/components/slider/types.ts +31 -0
- package/src/components/snackbar/index.ts +7 -1
- package/src/components/snackbar/types.ts +25 -0
- package/src/components/switch/index.ts +5 -1
- package/src/components/switch/types.ts +13 -0
- package/src/components/tabs/tab-api.ts +1 -1
- package/src/components/tabs/types.ts +1 -1
- package/src/components/textfield/index.ts +7 -1
- package/src/components/textfield/types.ts +36 -0
- package/src/components/tooltip/api.ts +6 -2
- package/src/components/tooltip/config.ts +9 -28
- package/src/components/tooltip/index.ts +10 -1
- package/src/components/tooltip/types.ts +38 -3
- package/src/index.ts +129 -31
- package/src/styles/abstract/_mixins.scss +23 -9
- package/src/styles/abstract/_variables.scss +14 -4
- package/src/styles/components/_card.scss +1 -1
- package/src/styles/components/_chip.scss +323 -113
- package/src/styles/components/_tabs.scss +1 -1
- package/src/components/checkbox/constants.ts +0 -37
- package/src/components/chip/chip-set.ts +0 -225
- package/src/components/chip/chip.ts +0 -118
- package/src/components/chip/constants.ts +0 -28
- package/src/components/chip/index.ts +0 -12
- package/src/components/list/constants.ts +0 -116
- package/src/components/sheet/constants.ts +0 -20
- package/src/components/slider/constants.ts +0 -32
- package/src/components/snackbar/constants.ts +0 -26
- package/src/components/tooltip/constants.ts +0 -27
- package/test/components/button.test.js +0 -170
- package/test/components/checkbox.test.js +0 -238
- package/test/components/list.test.js +0 -105
- package/test/components/menu.test.js +0 -385
- package/test/components/navigation.test.js +0 -227
- package/test/components/snackbar.test.js +0 -234
- package/test/components/switch.test.js +0 -186
- package/test/components/textfield.test.js +0 -314
- package/test/core/emitter.test.js +0 -141
- package/test/core/ripple.test.js +0 -66
- package/test/setup.js +0 -371
- package/tsconfig.json +0 -22
- package/typedoc.json +0 -28
- package/typedoc.simple.json +0 -14
|
@@ -1,196 +1,561 @@
|
|
|
1
1
|
// src/components/menu/types.ts
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Menu alignment options
|
|
4
|
+
* Menu horizontal alignment options
|
|
5
|
+
*
|
|
6
|
+
* Determines how the menu is horizontally aligned relative to its anchor element.
|
|
7
|
+
*
|
|
5
8
|
* @category Components
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Position menu with right alignment
|
|
12
|
+
* menu.position(buttonElement, { align: 'right' });
|
|
13
|
+
* ```
|
|
6
14
|
*/
|
|
7
15
|
export type MenuAlign = 'left' | 'right' | 'center';
|
|
8
16
|
|
|
9
17
|
/**
|
|
10
18
|
* Menu vertical alignment options
|
|
19
|
+
*
|
|
20
|
+
* Determines how the menu is vertically positioned relative to its anchor element.
|
|
21
|
+
*
|
|
11
22
|
* @category Components
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Position menu above the anchor element
|
|
26
|
+
* menu.position(buttonElement, { vAlign: 'top' });
|
|
27
|
+
* ```
|
|
12
28
|
*/
|
|
13
29
|
export type MenuVerticalAlign = 'top' | 'bottom' | 'middle';
|
|
14
30
|
|
|
15
31
|
/**
|
|
16
32
|
* Menu item types
|
|
33
|
+
*
|
|
34
|
+
* Defines the different types of items that can be added to a menu.
|
|
35
|
+
* - 'item': Standard selectable menu item (default)
|
|
36
|
+
* - 'divider': Horizontal line separating groups of menu items
|
|
37
|
+
*
|
|
17
38
|
* @category Components
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Adding a divider between menu items
|
|
42
|
+
* menu.addItem({ type: 'divider' });
|
|
43
|
+
* ```
|
|
18
44
|
*/
|
|
19
45
|
export type MenuItemType = 'item' | 'divider';
|
|
20
46
|
|
|
21
47
|
/**
|
|
22
48
|
* Menu events
|
|
49
|
+
*
|
|
50
|
+
* Events that can be subscribed to for the Menu component.
|
|
51
|
+
* - 'select': Fired when a menu item is selected
|
|
52
|
+
* - 'open': Fired when the menu is shown
|
|
53
|
+
* - 'close': Fired when the menu is hidden
|
|
54
|
+
* - 'submenuOpen': Fired when a submenu is opened
|
|
55
|
+
* - 'submenuClose': Fired when a submenu is closed
|
|
56
|
+
*
|
|
23
57
|
* @category Components
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Listen for menu open events
|
|
61
|
+
* menu.on('open', () => {
|
|
62
|
+
* console.log('Menu opened');
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Listen for item selection
|
|
66
|
+
* menu.on('select', (event) => {
|
|
67
|
+
* console.log(`Selected item: ${event.name}`);
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
24
70
|
*/
|
|
25
71
|
export type MenuEvent = 'select' | 'open' | 'close' | 'submenuOpen' | 'submenuClose';
|
|
26
72
|
|
|
27
73
|
/**
|
|
28
74
|
* Menu item configuration
|
|
75
|
+
*
|
|
76
|
+
* Configuration object for individual menu items.
|
|
77
|
+
*
|
|
78
|
+
* @category Components
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Basic menu item
|
|
82
|
+
* const basicItem: MenuItemConfig = {
|
|
83
|
+
* name: 'edit',
|
|
84
|
+
* text: 'Edit Document'
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* // Disabled menu item
|
|
88
|
+
* const disabledItem: MenuItemConfig = {
|
|
89
|
+
* name: 'print',
|
|
90
|
+
* text: 'Print',
|
|
91
|
+
* disabled: true
|
|
92
|
+
* };
|
|
93
|
+
*
|
|
94
|
+
* // Menu item with a submenu
|
|
95
|
+
* const itemWithSubmenu: MenuItemConfig = {
|
|
96
|
+
* name: 'share',
|
|
97
|
+
* text: 'Share',
|
|
98
|
+
* items: [
|
|
99
|
+
* { name: 'email', text: 'Email' },
|
|
100
|
+
* { name: 'link', text: 'Copy Link' }
|
|
101
|
+
* ]
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* // Divider item
|
|
105
|
+
* const divider: MenuItemConfig = { type: 'divider' };
|
|
106
|
+
* ```
|
|
29
107
|
*/
|
|
30
108
|
export interface MenuItemConfig {
|
|
31
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Unique identifier for the item
|
|
111
|
+
* Used for identifying the item when handling selection events
|
|
112
|
+
*/
|
|
32
113
|
name: string;
|
|
33
114
|
|
|
34
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Text content displayed for the item
|
|
117
|
+
* This is the visible label shown in the menu
|
|
118
|
+
*/
|
|
35
119
|
text: string;
|
|
36
120
|
|
|
37
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Type of menu item
|
|
123
|
+
* Defaults to 'item' if not specified
|
|
124
|
+
*/
|
|
38
125
|
type?: MenuItemType | string;
|
|
39
126
|
|
|
40
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Whether the item is disabled
|
|
129
|
+
* Disabled items can't be selected and appear visually muted
|
|
130
|
+
*/
|
|
41
131
|
disabled?: boolean;
|
|
42
132
|
|
|
43
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Additional CSS classes to apply to the item
|
|
135
|
+
* Useful for custom styling or visual indicators
|
|
136
|
+
*/
|
|
44
137
|
class?: string;
|
|
45
138
|
|
|
46
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* Submenu items
|
|
141
|
+
* Creates a nested menu that appears when this item is hovered
|
|
142
|
+
*/
|
|
47
143
|
items?: MenuItemConfig[];
|
|
48
144
|
}
|
|
49
145
|
|
|
50
146
|
/**
|
|
51
|
-
*
|
|
147
|
+
* Menu position configuration
|
|
148
|
+
*
|
|
149
|
+
* Configures how a menu is positioned relative to an anchor element.
|
|
150
|
+
* This allows for precise control over menu placement in the UI.
|
|
151
|
+
*
|
|
152
|
+
* @category Components
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Position menu at the bottom-right of the anchor with additional offset
|
|
156
|
+
* menu.position(buttonElement, {
|
|
157
|
+
* align: 'right',
|
|
158
|
+
* vAlign: 'bottom',
|
|
159
|
+
* offsetX: 5,
|
|
160
|
+
* offsetY: 10
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Center align menu below the anchor
|
|
164
|
+
* menu.position(buttonElement, {
|
|
165
|
+
* align: 'center',
|
|
166
|
+
* vAlign: 'bottom'
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
52
169
|
*/
|
|
53
170
|
export interface MenuPositionConfig {
|
|
54
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Horizontal alignment
|
|
173
|
+
* Controls how the menu aligns horizontally with the anchor element
|
|
174
|
+
* @default 'left'
|
|
175
|
+
*/
|
|
55
176
|
align?: MenuAlign | string;
|
|
56
177
|
|
|
57
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Vertical alignment
|
|
180
|
+
* Controls how the menu aligns vertically with the anchor element
|
|
181
|
+
* @default 'bottom'
|
|
182
|
+
*/
|
|
58
183
|
vAlign?: MenuVerticalAlign | string;
|
|
59
184
|
|
|
60
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Horizontal offset in pixels
|
|
187
|
+
* Additional horizontal offset from the aligned position
|
|
188
|
+
* Positive values move the menu to the right
|
|
189
|
+
* @default 0
|
|
190
|
+
*/
|
|
61
191
|
offsetX?: number;
|
|
62
192
|
|
|
63
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Vertical offset in pixels
|
|
195
|
+
* Additional vertical offset from the aligned position
|
|
196
|
+
* Positive values move the menu downward
|
|
197
|
+
* @default 0
|
|
198
|
+
*/
|
|
64
199
|
offsetY?: number;
|
|
65
200
|
}
|
|
66
201
|
|
|
67
202
|
/**
|
|
68
|
-
*
|
|
203
|
+
* Menu position result
|
|
204
|
+
*
|
|
205
|
+
* Contains the calculated position values for a menu.
|
|
206
|
+
* Used internally by the positioning system.
|
|
207
|
+
*
|
|
208
|
+
* @category Components
|
|
209
|
+
* @internal
|
|
69
210
|
*/
|
|
70
211
|
export interface MenuPosition {
|
|
71
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* Left position in pixels
|
|
214
|
+
* Absolute position from the left edge of the viewport
|
|
215
|
+
*/
|
|
72
216
|
left: number;
|
|
73
217
|
|
|
74
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* Top position in pixels
|
|
220
|
+
* Absolute position from the top edge of the viewport
|
|
221
|
+
*/
|
|
75
222
|
top: number;
|
|
76
223
|
}
|
|
77
224
|
|
|
78
225
|
/**
|
|
79
|
-
*
|
|
226
|
+
* Menu item internal data structure
|
|
227
|
+
*
|
|
228
|
+
* Used internally to track menu item DOM elements and their configurations.
|
|
229
|
+
* This helps with item management and event handling.
|
|
230
|
+
*
|
|
231
|
+
* @category Components
|
|
232
|
+
* @internal
|
|
80
233
|
*/
|
|
81
234
|
export interface MenuItemData {
|
|
82
|
-
/**
|
|
235
|
+
/**
|
|
236
|
+
* DOM element for the item
|
|
237
|
+
* Reference to the rendered menu item element
|
|
238
|
+
*/
|
|
83
239
|
element: HTMLElement;
|
|
84
240
|
|
|
85
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* Item configuration
|
|
243
|
+
* The configuration that was used to create this item
|
|
244
|
+
*/
|
|
86
245
|
config: MenuItemConfig;
|
|
87
246
|
}
|
|
88
247
|
|
|
89
248
|
/**
|
|
90
249
|
* Menu selection event data
|
|
250
|
+
*
|
|
251
|
+
* Contains information about a selected menu item.
|
|
252
|
+
* This is passed to event handlers when an item is selected.
|
|
253
|
+
*
|
|
254
|
+
* @category Components
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* menu.on('select', (event: MenuSelectEvent) => {
|
|
258
|
+
* console.log(`Selected: ${event.name}`);
|
|
259
|
+
* console.log(`Text: ${event.text}`);
|
|
260
|
+
*
|
|
261
|
+
* // For submenu items, path contains the hierarchy
|
|
262
|
+
* if (event.path) {
|
|
263
|
+
* console.log(`From submenu path: ${event.path.join(' > ')}`);
|
|
264
|
+
* }
|
|
265
|
+
* });
|
|
266
|
+
* ```
|
|
91
267
|
*/
|
|
92
268
|
export interface MenuSelectEvent {
|
|
93
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Name of the selected item
|
|
271
|
+
* Matches the name property from MenuItemConfig
|
|
272
|
+
*/
|
|
94
273
|
name: string;
|
|
95
274
|
|
|
96
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* Text content of the selected item
|
|
277
|
+
* The visible text that was displayed in the menu
|
|
278
|
+
*/
|
|
97
279
|
text: string;
|
|
98
280
|
|
|
99
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* Path of parent item names (for submenus)
|
|
283
|
+
* For nested menu selections, contains the names of all parent items
|
|
284
|
+
* from top level to the selected item
|
|
285
|
+
*/
|
|
100
286
|
path?: string[];
|
|
101
287
|
}
|
|
102
288
|
|
|
103
289
|
/**
|
|
104
290
|
* Configuration interface for the Menu component
|
|
291
|
+
*
|
|
292
|
+
* Provides options for creating and configuring a Menu component.
|
|
293
|
+
*
|
|
294
|
+
* @category Components
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* // Create a basic menu with initial items
|
|
298
|
+
* const menu = createMenu({
|
|
299
|
+
* items: [
|
|
300
|
+
* { name: 'copy', text: 'Copy' },
|
|
301
|
+
* { name: 'paste', text: 'Paste' },
|
|
302
|
+
* { type: 'divider' },
|
|
303
|
+
* { name: 'delete', text: 'Delete' }
|
|
304
|
+
* ],
|
|
305
|
+
* stayOpenOnSelect: false,
|
|
306
|
+
* class: 'custom-menu'
|
|
307
|
+
* });
|
|
308
|
+
*
|
|
309
|
+
* // Create a submenu
|
|
310
|
+
* const submenu = createMenu({
|
|
311
|
+
* items: [
|
|
312
|
+
* { name: 'option1', text: 'Option 1' },
|
|
313
|
+
* { name: 'option2', text: 'Option 2' }
|
|
314
|
+
* ],
|
|
315
|
+
* parentItem: parentElement
|
|
316
|
+
* });
|
|
317
|
+
* ```
|
|
105
318
|
*/
|
|
106
319
|
export interface MenuConfig {
|
|
107
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* Initial menu items
|
|
322
|
+
* Array of item configurations to populate the menu with
|
|
323
|
+
*/
|
|
108
324
|
items?: MenuItemConfig[];
|
|
109
325
|
|
|
110
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* Additional CSS classes
|
|
328
|
+
* Custom classes to apply to the menu container element
|
|
329
|
+
*/
|
|
111
330
|
class?: string;
|
|
112
331
|
|
|
113
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Whether to keep menu open after selection
|
|
334
|
+
* When true, selecting an item will not automatically close the menu
|
|
335
|
+
* @default false
|
|
336
|
+
*/
|
|
114
337
|
stayOpenOnSelect?: boolean;
|
|
115
338
|
|
|
116
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* Origin element that opens the menu
|
|
341
|
+
* Element used to trigger the menu appearance (like a button)
|
|
342
|
+
*/
|
|
117
343
|
origin?: HTMLElement | { element: HTMLElement };
|
|
118
344
|
|
|
119
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Parent item element (for submenus)
|
|
347
|
+
* For submenus, references the parent menu item this menu belongs to
|
|
348
|
+
*/
|
|
120
349
|
parentItem?: HTMLElement;
|
|
121
350
|
|
|
122
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* Prefix for class names
|
|
353
|
+
* Custom prefix for all CSS class names generated by the component
|
|
354
|
+
* @default 'mtrl'
|
|
355
|
+
*/
|
|
123
356
|
prefix?: string;
|
|
124
357
|
|
|
125
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* Component name
|
|
360
|
+
* Name identifier used in CSS classes and debugging
|
|
361
|
+
* @default 'menu'
|
|
362
|
+
*/
|
|
126
363
|
componentName?: string;
|
|
127
364
|
}
|
|
128
365
|
|
|
129
366
|
/**
|
|
130
367
|
* Menu component interface
|
|
368
|
+
*
|
|
369
|
+
* Represents a Material Design 3 menu component that provides a temporary
|
|
370
|
+
* surface containing choices that users can interact with.
|
|
371
|
+
*
|
|
372
|
+
* The menu supports positioning, item management, keyboard navigation,
|
|
373
|
+
* and event handling for user interactions.
|
|
374
|
+
*
|
|
375
|
+
* This interface is implemented by the object returned from the {@link ../menu!default | createMenu} function.
|
|
376
|
+
*
|
|
377
|
+
* @category Components
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* // Create a menu with items
|
|
381
|
+
* const menu = createMenu({
|
|
382
|
+
* items: [
|
|
383
|
+
* { name: 'edit', text: 'Edit' },
|
|
384
|
+
* { name: 'duplicate', text: 'Duplicate' },
|
|
385
|
+
* { type: 'divider' },
|
|
386
|
+
* { name: 'delete', text: 'Delete' }
|
|
387
|
+
* ]
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* // Position and show the menu
|
|
391
|
+
* const button = document.getElementById('menuButton');
|
|
392
|
+
* button.addEventListener('click', () => {
|
|
393
|
+
* menu.position(button).show();
|
|
394
|
+
* });
|
|
395
|
+
*
|
|
396
|
+
* // Handle selection
|
|
397
|
+
* menu.on('select', (event) => {
|
|
398
|
+
* console.log(`Selected: ${event.name}`);
|
|
399
|
+
* if (event.name === 'delete') {
|
|
400
|
+
* // Handle delete action
|
|
401
|
+
* }
|
|
402
|
+
* });
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @see {@link ../menu!default | createMenu} for creating menu instances
|
|
131
406
|
*/
|
|
132
407
|
export interface MenuComponent {
|
|
133
|
-
/**
|
|
408
|
+
/**
|
|
409
|
+
* The root element of the menu
|
|
410
|
+
* Access to the underlying DOM element for direct manipulation if needed
|
|
411
|
+
*/
|
|
134
412
|
element: HTMLElement;
|
|
135
413
|
|
|
136
|
-
/**
|
|
414
|
+
/**
|
|
415
|
+
* Shows the menu
|
|
416
|
+
* Makes the menu visible in the DOM
|
|
417
|
+
* @returns The menu component for method chaining
|
|
418
|
+
*/
|
|
137
419
|
show: () => MenuComponent;
|
|
138
420
|
|
|
139
|
-
/**
|
|
421
|
+
/**
|
|
422
|
+
* Hides the menu
|
|
423
|
+
* Makes the menu invisible in the DOM
|
|
424
|
+
* @returns The menu component for method chaining
|
|
425
|
+
*/
|
|
140
426
|
hide: () => MenuComponent;
|
|
141
427
|
|
|
142
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* Checks if the menu is visible
|
|
430
|
+
* @returns True if the menu is currently visible
|
|
431
|
+
*/
|
|
143
432
|
isVisible: () => boolean;
|
|
144
433
|
|
|
145
|
-
/**
|
|
434
|
+
/**
|
|
435
|
+
* Positions the menu relative to a target
|
|
436
|
+
* Places the menu in relation to a target element with customizable alignment
|
|
437
|
+
* @param target - The element to position the menu against
|
|
438
|
+
* @param options - Configuration for how to align the menu
|
|
439
|
+
* @returns The menu component for method chaining
|
|
440
|
+
*/
|
|
146
441
|
position: (target: HTMLElement, options?: MenuPositionConfig) => MenuComponent;
|
|
147
442
|
|
|
148
|
-
/**
|
|
443
|
+
/**
|
|
444
|
+
* Adds a menu item
|
|
445
|
+
* Dynamically adds a new item to the menu
|
|
446
|
+
* @param config - Configuration for the new menu item
|
|
447
|
+
* @returns The menu component for method chaining
|
|
448
|
+
*/
|
|
149
449
|
addItem: (config: MenuItemConfig) => MenuComponent;
|
|
150
450
|
|
|
151
|
-
/**
|
|
451
|
+
/**
|
|
452
|
+
* Removes a menu item by name
|
|
453
|
+
* Dynamically removes an item from the menu
|
|
454
|
+
* @param name - Name identifier of the item to remove
|
|
455
|
+
* @returns The menu component for method chaining
|
|
456
|
+
*/
|
|
152
457
|
removeItem: (name: string) => MenuComponent;
|
|
153
458
|
|
|
154
|
-
/**
|
|
459
|
+
/**
|
|
460
|
+
* Gets all menu items
|
|
461
|
+
* @returns A Map of all items in the menu, indexed by item name
|
|
462
|
+
*/
|
|
155
463
|
getItems: () => Map<string, MenuItemData>;
|
|
156
464
|
|
|
157
|
-
/**
|
|
465
|
+
/**
|
|
466
|
+
* Adds event listener
|
|
467
|
+
* Subscribes to menu events like 'select', 'open', etc.
|
|
468
|
+
* @param event - The event name to listen for
|
|
469
|
+
* @param handler - Callback function to execute when the event occurs
|
|
470
|
+
* @returns The menu component for method chaining
|
|
471
|
+
*/
|
|
158
472
|
on: (event: string, handler: Function) => MenuComponent;
|
|
159
473
|
|
|
160
|
-
/**
|
|
474
|
+
/**
|
|
475
|
+
* Removes event listener
|
|
476
|
+
* Unsubscribes from menu events
|
|
477
|
+
* @param event - The event name to stop listening for
|
|
478
|
+
* @param handler - The handler function to remove
|
|
479
|
+
* @returns The menu component for method chaining
|
|
480
|
+
*/
|
|
161
481
|
off: (event: string, handler: Function) => MenuComponent;
|
|
162
482
|
|
|
163
|
-
/**
|
|
483
|
+
/**
|
|
484
|
+
* Destroys the menu component and cleans up resources
|
|
485
|
+
* Removes event listeners and DOM elements to prevent memory leaks
|
|
486
|
+
* @returns The menu component for method chaining
|
|
487
|
+
*/
|
|
164
488
|
destroy: () => MenuComponent;
|
|
165
489
|
}
|
|
166
490
|
|
|
167
491
|
/**
|
|
168
492
|
* Base component interface
|
|
493
|
+
*
|
|
494
|
+
* Internal interface representing the base structure for menu components
|
|
495
|
+
* before the public API is applied.
|
|
496
|
+
*
|
|
497
|
+
* @internal
|
|
498
|
+
* @category Components
|
|
169
499
|
*/
|
|
170
500
|
export interface BaseComponent {
|
|
501
|
+
/** The root DOM element */
|
|
171
502
|
element: HTMLElement;
|
|
503
|
+
|
|
504
|
+
/** Method to emit events */
|
|
172
505
|
emit?: (event: string, data: any) => void;
|
|
506
|
+
|
|
507
|
+
/** Method to subscribe to events */
|
|
173
508
|
on?: (event: string, handler: Function) => any;
|
|
509
|
+
|
|
510
|
+
/** Method to unsubscribe from events */
|
|
174
511
|
off?: (event: string, handler: Function) => any;
|
|
512
|
+
|
|
513
|
+
/** Method to show the component */
|
|
175
514
|
show?: () => any;
|
|
515
|
+
|
|
516
|
+
/** Method to hide the component */
|
|
176
517
|
hide?: () => any;
|
|
518
|
+
|
|
519
|
+
/** Method to check visibility */
|
|
177
520
|
isVisible?: () => boolean;
|
|
521
|
+
|
|
522
|
+
/** Method to position relative to target */
|
|
178
523
|
position?: (target: HTMLElement, options?: MenuPositionConfig) => any;
|
|
524
|
+
|
|
525
|
+
/** Method to add an item */
|
|
179
526
|
addItem?: (config: MenuItemConfig) => any;
|
|
527
|
+
|
|
528
|
+
/** Method to remove an item */
|
|
180
529
|
removeItem?: (name: string) => any;
|
|
530
|
+
|
|
531
|
+
/** Method to get all items */
|
|
181
532
|
getItems?: () => Map<string, MenuItemData>;
|
|
533
|
+
|
|
534
|
+
/** Method to close submenus */
|
|
182
535
|
closeSubmenus?: () => any;
|
|
536
|
+
|
|
537
|
+
/** Method to refresh hover handlers */
|
|
183
538
|
refreshHoverHandlers?: () => any;
|
|
539
|
+
|
|
540
|
+
/** Lifecycle methods container */
|
|
184
541
|
lifecycle?: {
|
|
185
542
|
destroy: () => void;
|
|
186
543
|
};
|
|
544
|
+
|
|
545
|
+
/** Allow for additional properties */
|
|
187
546
|
[key: string]: any;
|
|
188
547
|
}
|
|
189
548
|
|
|
190
549
|
/**
|
|
191
550
|
* API options interface
|
|
551
|
+
*
|
|
552
|
+
* Internal interface used when applying the API to a component.
|
|
553
|
+
*
|
|
554
|
+
* @internal
|
|
555
|
+
* @category Components
|
|
192
556
|
*/
|
|
193
557
|
export interface ApiOptions {
|
|
558
|
+
/** Lifecycle methods to include */
|
|
194
559
|
lifecycle: {
|
|
195
560
|
destroy: () => void;
|
|
196
561
|
};
|
|
@@ -6,18 +6,51 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type NavVariant = 'rail' | 'drawer' | 'bar' | 'modal' | 'standard';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Navigation variants enum
|
|
11
|
+
* @category Components
|
|
12
|
+
*/
|
|
13
|
+
export const NAV_VARIANTS: Record<string, NavVariant> = {
|
|
14
|
+
RAIL: 'rail',
|
|
15
|
+
DRAWER: 'drawer',
|
|
16
|
+
BAR: 'bar',
|
|
17
|
+
MODAL: 'modal',
|
|
18
|
+
STANDARD: 'standard'
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
22
|
* Navigation positions
|
|
11
23
|
* @category Components
|
|
12
24
|
*/
|
|
13
25
|
export type NavPosition = 'left' | 'right' | 'top' | 'bottom';
|
|
14
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Navigation positions enum
|
|
29
|
+
* @category Components
|
|
30
|
+
*/
|
|
31
|
+
export const NAV_POSITIONS: Record<string, NavPosition> = {
|
|
32
|
+
LEFT: 'left',
|
|
33
|
+
RIGHT: 'right',
|
|
34
|
+
TOP: 'top',
|
|
35
|
+
BOTTOM: 'bottom'
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
15
38
|
/**
|
|
16
39
|
* Navigation behaviors
|
|
17
40
|
* @category Components
|
|
18
41
|
*/
|
|
19
42
|
export type NavBehavior = 'fixed' | 'dismissible' | 'modal';
|
|
20
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Navigation behaviors enum
|
|
46
|
+
* @category Components
|
|
47
|
+
*/
|
|
48
|
+
export const NAV_BEHAVIORS: Record<string, NavBehavior> = {
|
|
49
|
+
FIXED: 'fixed',
|
|
50
|
+
DISMISSIBLE: 'dismissible',
|
|
51
|
+
MODAL: 'modal'
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
21
54
|
/**
|
|
22
55
|
* Navigation item state
|
|
23
56
|
* @category Components
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
createElementConfig,
|
|
5
5
|
BaseComponentConfig
|
|
6
6
|
} from '../../core/config/component-config';
|
|
7
|
-
import { SheetConfig } from './types';
|
|
8
|
-
import { SHEET_VARIANTS, SHEET_POSITIONS } from './constants';
|
|
7
|
+
import { SheetConfig, SHEET_VARIANTS, SHEET_POSITIONS } from './types';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Default configuration for the Sheet component
|