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,4 +1,4 @@
|
|
|
1
|
-
// src/components/
|
|
1
|
+
// src/components/chips/types.ts
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Chip variant types
|
|
@@ -6,6 +6,25 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type ChipVariant = 'filled' | 'outlined' | 'elevated' | 'assist' | 'filter' | 'input' | 'suggestion';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Available chip event types
|
|
11
|
+
*/
|
|
12
|
+
export const CHIP_EVENTS = {
|
|
13
|
+
CHANGE: 'change',
|
|
14
|
+
SELECT: 'select',
|
|
15
|
+
DESELECT: 'deselect',
|
|
16
|
+
REMOVE: 'remove'
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Available chips event types
|
|
21
|
+
*/
|
|
22
|
+
export const CHIPS_EVENTS = {
|
|
23
|
+
CHANGE: 'change',
|
|
24
|
+
ADD: 'add',
|
|
25
|
+
REMOVE: 'remove'
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
9
28
|
/**
|
|
10
29
|
* Configuration interface for the Chip component
|
|
11
30
|
* @category Components
|
|
@@ -111,58 +130,85 @@ export interface ChipConfig {
|
|
|
111
130
|
|
|
112
131
|
/**
|
|
113
132
|
* Function called when the chip selection changes
|
|
133
|
+
* @param {boolean} selected - Whether the chip is selected
|
|
134
|
+
* @param {ChipComponent} chip - The chip component
|
|
114
135
|
*/
|
|
115
|
-
onChange?: (chip: ChipComponent) => void;
|
|
136
|
+
onChange?: (selected: boolean, chip: ChipComponent) => void;
|
|
116
137
|
}
|
|
117
138
|
|
|
118
139
|
/**
|
|
119
|
-
*
|
|
140
|
+
* Configuration interface for the Chips component
|
|
120
141
|
* @category Components
|
|
121
142
|
*/
|
|
122
|
-
export interface
|
|
123
|
-
/**
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
126
|
-
* @returns The icon API for chaining
|
|
143
|
+
export interface ChipsConfig {
|
|
144
|
+
/**
|
|
145
|
+
* Array of chip configurations to initialize
|
|
146
|
+
* @default []
|
|
127
147
|
*/
|
|
128
|
-
|
|
148
|
+
chips?: ChipConfig[];
|
|
129
149
|
|
|
130
|
-
/**
|
|
131
|
-
*
|
|
132
|
-
* @
|
|
150
|
+
/**
|
|
151
|
+
* Whether the chip set is horizontally scrollable
|
|
152
|
+
* @default false
|
|
133
153
|
*/
|
|
134
|
-
|
|
154
|
+
scrollable?: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Whether the chip set is vertically stacked
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
vertical?: boolean;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Additional CSS classes
|
|
164
|
+
*/
|
|
165
|
+
class?: string;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* CSS selector for filtering behavior
|
|
169
|
+
*/
|
|
170
|
+
selector?: string | null;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Whether multiple chips can be selected simultaneously
|
|
174
|
+
* @default false
|
|
175
|
+
*/
|
|
176
|
+
multiSelect?: boolean;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Callback function when chip selection changes
|
|
180
|
+
*/
|
|
181
|
+
onChange?: (selectedValues: (string | null)[], changedValue: string | null) => void;
|
|
135
182
|
|
|
136
183
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @
|
|
184
|
+
* Component prefix for class names
|
|
185
|
+
* @default 'mtrl'
|
|
139
186
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Text API interface for managing chip text
|
|
145
|
-
* @category Components
|
|
146
|
-
*/
|
|
147
|
-
export interface TextAPI {
|
|
187
|
+
prefix?: string;
|
|
188
|
+
|
|
148
189
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param content - Text content
|
|
151
|
-
* @returns The text API for chaining
|
|
190
|
+
* Label text for the chips container
|
|
152
191
|
*/
|
|
153
|
-
|
|
192
|
+
label?: string;
|
|
154
193
|
|
|
155
194
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
195
|
+
* Position of the label (start or end)
|
|
196
|
+
* @default 'start'
|
|
158
197
|
*/
|
|
159
|
-
|
|
198
|
+
labelPosition?: 'start' | 'end';
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Schema definition for the component structure
|
|
202
|
+
* @internal
|
|
203
|
+
*/
|
|
204
|
+
schema?: any;
|
|
160
205
|
|
|
161
206
|
/**
|
|
162
|
-
*
|
|
163
|
-
* @returns The text element or null if not present
|
|
207
|
+
* Event handlers for component events
|
|
164
208
|
*/
|
|
165
|
-
|
|
209
|
+
on?: {
|
|
210
|
+
[key: string]: Function;
|
|
211
|
+
};
|
|
166
212
|
}
|
|
167
213
|
|
|
168
214
|
/**
|
|
@@ -173,35 +219,6 @@ export interface ChipComponent {
|
|
|
173
219
|
/** The chip's DOM element */
|
|
174
220
|
element: HTMLElement;
|
|
175
221
|
|
|
176
|
-
/** API for managing chip text */
|
|
177
|
-
text: TextAPI;
|
|
178
|
-
|
|
179
|
-
/** API for managing chip icons */
|
|
180
|
-
icon: IconAPI;
|
|
181
|
-
|
|
182
|
-
/** API for managing disabled state */
|
|
183
|
-
disabled: {
|
|
184
|
-
/** Enables the chip */
|
|
185
|
-
enable: () => void;
|
|
186
|
-
/** Disables the chip */
|
|
187
|
-
disable: () => void;
|
|
188
|
-
/** Checks if the chip is disabled */
|
|
189
|
-
isDisabled: () => boolean;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/** API for managing component lifecycle */
|
|
193
|
-
lifecycle: {
|
|
194
|
-
/** Destroys the component and cleans up resources */
|
|
195
|
-
destroy: () => void;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Gets a class name with the component's prefix
|
|
200
|
-
* @param name - Base class name
|
|
201
|
-
* @returns Prefixed class name
|
|
202
|
-
*/
|
|
203
|
-
getClass: (name: string) => string;
|
|
204
|
-
|
|
205
222
|
/**
|
|
206
223
|
* Gets the chip's value attribute
|
|
207
224
|
* @returns Chip value
|
|
@@ -323,36 +340,130 @@ export interface ChipComponent {
|
|
|
323
340
|
}
|
|
324
341
|
|
|
325
342
|
/**
|
|
326
|
-
*
|
|
327
|
-
* @
|
|
328
|
-
*/
|
|
329
|
-
export interface ApiOptions {
|
|
330
|
-
disabled: {
|
|
331
|
-
enable: () => void;
|
|
332
|
-
disable: () => void;
|
|
333
|
-
};
|
|
334
|
-
lifecycle: {
|
|
335
|
-
destroy: () => void;
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Base component interface
|
|
341
|
-
* @internal
|
|
343
|
+
* Chips component interface
|
|
344
|
+
* @category Components
|
|
342
345
|
*/
|
|
343
|
-
export interface
|
|
346
|
+
export interface ChipsComponent {
|
|
347
|
+
/** The chips container's DOM element */
|
|
344
348
|
element: HTMLElement;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Adds a new chip to the chips container
|
|
352
|
+
* @param chipConfig - Configuration for the chip
|
|
353
|
+
* @returns The chips instance for chaining
|
|
354
|
+
*/
|
|
355
|
+
addChip: (chipConfig: ChipConfig) => ChipsComponent;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Removes a chip from the chips container
|
|
359
|
+
* @param chipOrIndex - Chip instance or index to remove
|
|
360
|
+
* @returns The chips instance for chaining
|
|
361
|
+
*/
|
|
362
|
+
removeChip: (chipOrIndex: ChipComponent | number) => ChipsComponent;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Gets all chip instances in the set
|
|
366
|
+
* @returns Array of chip instances
|
|
367
|
+
*/
|
|
368
|
+
getChips: () => ChipComponent[];
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Gets currently selected chips
|
|
372
|
+
* @returns Array of selected chip instances
|
|
373
|
+
*/
|
|
374
|
+
getSelectedChips: () => ChipComponent[];
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Gets the values of selected chips
|
|
378
|
+
* @returns Array of selected chip values
|
|
379
|
+
*/
|
|
380
|
+
getSelectedValues: () => (string | null)[];
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Selects chips by their values
|
|
384
|
+
* @param values - Value or array of values to select
|
|
385
|
+
* @param triggerEvent - Whether to trigger change event (default: true)
|
|
386
|
+
* @returns The chips instance for chaining
|
|
387
|
+
*/
|
|
388
|
+
selectByValue: (values: string | string[], triggerEvent?: boolean) => ChipsComponent;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Clears all selections
|
|
392
|
+
* @returns The chips instance for chaining
|
|
393
|
+
*/
|
|
394
|
+
clearSelection: () => ChipsComponent;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Sets the scrollable state of the chips container
|
|
398
|
+
* @param isScrollable - Whether the chips container should be scrollable
|
|
399
|
+
* @returns The chips instance for chaining
|
|
400
|
+
*/
|
|
401
|
+
setScrollable: (isScrollable: boolean) => ChipsComponent;
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Sets the vertical layout state
|
|
405
|
+
* @param isVertical - Whether the chips container should be vertically stacked
|
|
406
|
+
* @returns The chips instance for chaining
|
|
407
|
+
*/
|
|
408
|
+
setVertical: (isVertical: boolean) => ChipsComponent;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Sets the label text
|
|
412
|
+
* @param text - Label text
|
|
413
|
+
* @returns The chips instance for chaining
|
|
414
|
+
*/
|
|
415
|
+
setLabel: (text: string) => ChipsComponent;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Gets the label text
|
|
419
|
+
* @returns Label text
|
|
420
|
+
*/
|
|
421
|
+
getLabel: () => string;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Sets the label position
|
|
425
|
+
* @param position - Label position ('start' or 'end')
|
|
426
|
+
* @returns The chips instance for chaining
|
|
427
|
+
*/
|
|
428
|
+
setLabelPosition: (position: 'start' | 'end') => ChipsComponent;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Gets the label position
|
|
432
|
+
* @returns Label position
|
|
433
|
+
*/
|
|
434
|
+
getLabelPosition: () => string;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Scrolls to a specific chip
|
|
438
|
+
* @param chipOrIndex - Chip instance or index to scroll to
|
|
439
|
+
* @returns The chips instance for chaining
|
|
440
|
+
*/
|
|
441
|
+
scrollToChip: (chipOrIndex: ChipComponent | number) => ChipsComponent;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Enables keyboard navigation between chips in the set
|
|
445
|
+
* @returns The chips instance for chaining
|
|
446
|
+
*/
|
|
447
|
+
enableKeyboardNavigation: () => ChipsComponent;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Destroys the chips container and all contained chips
|
|
451
|
+
*/
|
|
452
|
+
destroy: () => void;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Adds an event listener to the chips container
|
|
456
|
+
* @param event - Event name ('change', etc.)
|
|
457
|
+
* @param handler - Event handler function
|
|
458
|
+
* @returns The chips instance for chaining
|
|
459
|
+
*/
|
|
460
|
+
on: (event: string, handler: Function) => ChipsComponent;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Removes an event listener from the chips container
|
|
464
|
+
* @param event - Event name
|
|
465
|
+
* @param handler - Event handler function
|
|
466
|
+
* @returns The chips instance for chaining
|
|
467
|
+
*/
|
|
468
|
+
off: (event: string, handler: Function) => ChipsComponent;
|
|
358
469
|
}
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
// src/components/dialog/dialog.ts
|
|
2
|
+
/**
|
|
3
|
+
* Dialog Component Implementation
|
|
4
|
+
*
|
|
5
|
+
* This module implements a Material Design 3 dialog component that can be
|
|
6
|
+
* used for alerts, confirmations, form submissions, and complex interactions.
|
|
7
|
+
*
|
|
8
|
+
* The implementation supports various features including:
|
|
9
|
+
* - Multiple size variants (small, medium, large, fullwidth, fullscreen)
|
|
10
|
+
* - Multiple animation styles
|
|
11
|
+
* - Custom buttons with configurable actions
|
|
12
|
+
* - Dividers for visual separation
|
|
13
|
+
* - Confirmation dialog patterns
|
|
14
|
+
* - Event handling for dialog lifecycle
|
|
15
|
+
*
|
|
16
|
+
* @module components/dialog
|
|
17
|
+
* @category Components
|
|
18
|
+
*/
|
|
19
|
+
|
|
2
20
|
import { pipe } from '../../core/compose';
|
|
3
21
|
import { createBase, withElement } from '../../core/compose/component';
|
|
4
22
|
import { withEvents, withLifecycle } from '../../core/compose/features';
|
|
@@ -16,28 +34,93 @@ import { DialogConfig, DialogComponent } from './types';
|
|
|
16
34
|
import { createBaseConfig, getElementConfig, getApiConfig } from './config';
|
|
17
35
|
|
|
18
36
|
/**
|
|
19
|
-
* Creates a new Dialog component
|
|
20
|
-
*
|
|
21
|
-
*
|
|
37
|
+
* Creates a new Dialog component with the specified configuration.
|
|
38
|
+
*
|
|
39
|
+
* Dialogs are modal windows that appear in front of app content to
|
|
40
|
+
* provide critical information or ask for decisions. They inform
|
|
41
|
+
* users about specific tasks and may contain critical information,
|
|
42
|
+
* require decisions, or involve multiple tasks.
|
|
43
|
+
*
|
|
44
|
+
* @param {DialogConfig} config - Configuration options for the dialog
|
|
45
|
+
* @returns {DialogComponent} A fully configured dialog component instance
|
|
46
|
+
* @throws {Error} Throws an error if dialog creation fails
|
|
47
|
+
*
|
|
48
|
+
* @category Components
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Create a basic dialog with title and content
|
|
52
|
+
* const infoDialog = createDialog({
|
|
53
|
+
* title: 'Information',
|
|
54
|
+
* content: 'Your changes have been saved.',
|
|
55
|
+
* size: 'small',
|
|
56
|
+
* buttons: [
|
|
57
|
+
* { text: 'OK', variant: 'text', closeDialog: true }
|
|
58
|
+
* ]
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* document.body.appendChild(infoDialog.element);
|
|
62
|
+
* infoDialog.open();
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Create a form dialog with multiple buttons
|
|
66
|
+
* const formDialog = createDialog({
|
|
67
|
+
* title: 'Edit Profile',
|
|
68
|
+
* content: '<form id="profile-form">...</form>',
|
|
69
|
+
* size: 'medium',
|
|
70
|
+
* closeOnEscape: true,
|
|
71
|
+
* closeOnOverlayClick: false,
|
|
72
|
+
* buttons: [
|
|
73
|
+
* {
|
|
74
|
+
* text: 'Save',
|
|
75
|
+
* variant: 'filled',
|
|
76
|
+
* onClick: (event, dialog) => {
|
|
77
|
+
* const form = document.getElementById('profile-form');
|
|
78
|
+
* if(form.checkValidity()) {
|
|
79
|
+
* saveProfile(form);
|
|
80
|
+
* dialog.close();
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* },
|
|
84
|
+
* { text: 'Cancel', variant: 'text', closeDialog: true }
|
|
85
|
+
* ]
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* // Create a confirmation dialog using the Promise-based API
|
|
90
|
+
* async function confirmAction() {
|
|
91
|
+
* const dialog = createDialog();
|
|
92
|
+
* const confirmed = await dialog.confirm({
|
|
93
|
+
* title: 'Confirm Action',
|
|
94
|
+
* message: 'Are you sure you want to proceed?',
|
|
95
|
+
* confirmText: 'Yes, proceed',
|
|
96
|
+
* cancelText: 'No, cancel'
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* if (confirmed) {
|
|
100
|
+
* // User clicked the confirm button
|
|
101
|
+
* performAction();
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
22
104
|
*/
|
|
23
105
|
const createDialog = (config: DialogConfig = {}): DialogComponent => {
|
|
24
106
|
const baseConfig = createBaseConfig(config);
|
|
25
107
|
|
|
26
108
|
try {
|
|
27
|
-
//
|
|
109
|
+
// Create the dialog through functional composition
|
|
110
|
+
// Each function in the pipe adds specific features to the component
|
|
28
111
|
const dialog = pipe(
|
|
29
|
-
createBase,
|
|
30
|
-
withEvents(),
|
|
31
|
-
withElement(getElementConfig(baseConfig)),
|
|
32
|
-
withStructure(baseConfig),
|
|
33
|
-
withVisibility(),
|
|
34
|
-
withContent(),
|
|
35
|
-
withButtons(),
|
|
36
|
-
withSize(),
|
|
37
|
-
withDivider(),
|
|
38
|
-
withConfirm(),
|
|
39
|
-
withLifecycle(),
|
|
40
|
-
comp => withAPI(getApiConfig(comp))(comp)
|
|
112
|
+
createBase, // Base component
|
|
113
|
+
withEvents(), // Event handling
|
|
114
|
+
withElement(getElementConfig(baseConfig)), // DOM element
|
|
115
|
+
withStructure(baseConfig), // Dialog structure (overlay, header, content, footer)
|
|
116
|
+
withVisibility(), // Open/close functionality
|
|
117
|
+
withContent(), // Content management
|
|
118
|
+
withButtons(), // Footer buttons
|
|
119
|
+
withSize(), // Size variants
|
|
120
|
+
withDivider(), // Header/content divider
|
|
121
|
+
withConfirm(), // Confirmation dialog helpers
|
|
122
|
+
withLifecycle(), // Lifecycle management
|
|
123
|
+
comp => withAPI(getApiConfig(comp))(comp) // Public API
|
|
41
124
|
)(baseConfig);
|
|
42
125
|
|
|
43
126
|
// Register event handlers from config
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
// src/components/dialog/index.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dialog Component Module
|
|
5
|
+
*
|
|
6
|
+
* A Material Design 3 dialog implementation with support for multiple sizes,
|
|
7
|
+
* animations, content types, and interactive features like confirmation.
|
|
8
|
+
*
|
|
9
|
+
* Dialogs inform users about critical information, require decisions,
|
|
10
|
+
* or involve multiple tasks.
|
|
11
|
+
*
|
|
12
|
+
* @module components/dialog
|
|
13
|
+
* @category Components
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Main factory function
|
|
2
17
|
export { default } from './dialog';
|
|
18
|
+
|
|
19
|
+
// TypeScript types and interfaces
|
|
3
20
|
export {
|
|
4
21
|
DialogConfig,
|
|
5
22
|
DialogComponent,
|
|
@@ -12,34 +29,113 @@ export {
|
|
|
12
29
|
DialogEventType
|
|
13
30
|
} from './types';
|
|
14
31
|
|
|
15
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Dialog size constants
|
|
34
|
+
*
|
|
35
|
+
* These constants define the available dialog size variants,
|
|
36
|
+
* controlling the width and height of the dialog.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import { createDialog, DIALOG_SIZES } from 'mtrl';
|
|
40
|
+
*
|
|
41
|
+
* const dialog = createDialog({
|
|
42
|
+
* title: 'Settings',
|
|
43
|
+
* size: DIALOG_SIZES.MEDIUM
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* @category Components
|
|
47
|
+
*/
|
|
16
48
|
export const DIALOG_SIZES = {
|
|
49
|
+
/** Small dialog (320px) for simple messages or choices */
|
|
17
50
|
SMALL: 'small',
|
|
51
|
+
/** Medium dialog (560px) for standard forms or content (default) */
|
|
18
52
|
MEDIUM: 'medium',
|
|
53
|
+
/** Large dialog (800px) for complex forms or rich content */
|
|
19
54
|
LARGE: 'large',
|
|
55
|
+
/** Dialog that spans the full width of the viewport with margins */
|
|
20
56
|
FULLWIDTH: 'fullwidth',
|
|
57
|
+
/** Dialog that takes up the entire viewport (similar to a new page) */
|
|
21
58
|
FULLSCREEN: 'fullscreen'
|
|
22
59
|
} as const;
|
|
23
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Dialog animation constants
|
|
63
|
+
*
|
|
64
|
+
* These constants define the available dialog opening and closing animations.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* import { createDialog, DIALOG_ANIMATIONS } from 'mtrl';
|
|
68
|
+
*
|
|
69
|
+
* const dialog = createDialog({
|
|
70
|
+
* animation: DIALOG_ANIMATIONS.SCALE
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* @category Components
|
|
74
|
+
*/
|
|
24
75
|
export const DIALOG_ANIMATIONS = {
|
|
76
|
+
/** Scale up/down animation from center (default) */
|
|
25
77
|
SCALE: 'scale',
|
|
78
|
+
/** Slide in from bottom, slide out to bottom */
|
|
26
79
|
SLIDE_UP: 'slide-up',
|
|
80
|
+
/** Slide in from top, slide out to top */
|
|
27
81
|
SLIDE_DOWN: 'slide-down',
|
|
82
|
+
/** Simple fade in/out animation */
|
|
28
83
|
FADE: 'fade'
|
|
29
84
|
} as const;
|
|
30
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Dialog footer alignment constants
|
|
88
|
+
*
|
|
89
|
+
* These constants control how buttons in the footer are aligned.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* import { createDialog, DIALOG_FOOTER_ALIGNMENTS } from 'mtrl';
|
|
93
|
+
*
|
|
94
|
+
* const dialog = createDialog({
|
|
95
|
+
* footerAlignment: DIALOG_FOOTER_ALIGNMENTS.RIGHT
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* @category Components
|
|
99
|
+
*/
|
|
31
100
|
export const DIALOG_FOOTER_ALIGNMENTS = {
|
|
101
|
+
/** Align buttons to the right (default, follows Material Design guidelines) */
|
|
32
102
|
RIGHT: 'right',
|
|
103
|
+
/** Align buttons to the left */
|
|
33
104
|
LEFT: 'left',
|
|
105
|
+
/** Center buttons in footer */
|
|
34
106
|
CENTER: 'center',
|
|
107
|
+
/** Space buttons evenly, with first button at left, last at right */
|
|
35
108
|
SPACE_BETWEEN: 'space-between'
|
|
36
109
|
} as const;
|
|
37
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Dialog event constants
|
|
113
|
+
*
|
|
114
|
+
* These events can be used with the dialog's on() method to respond
|
|
115
|
+
* to changes in the dialog's state.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* import { createDialog, DIALOG_EVENTS } from 'mtrl';
|
|
119
|
+
*
|
|
120
|
+
* const dialog = createDialog();
|
|
121
|
+
*
|
|
122
|
+
* dialog.on(DIALOG_EVENTS.AFTER_OPEN, () => {
|
|
123
|
+
* console.log('Dialog was opened');
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* @category Components
|
|
127
|
+
*/
|
|
38
128
|
export const DIALOG_EVENTS = {
|
|
129
|
+
/** Fired when the dialog begins opening */
|
|
39
130
|
OPEN: 'open',
|
|
131
|
+
/** Fired when the dialog begins closing */
|
|
40
132
|
CLOSE: 'close',
|
|
133
|
+
/** Fired before the dialog starts opening (can be prevented) */
|
|
41
134
|
BEFORE_OPEN: 'beforeopen',
|
|
135
|
+
/** Fired before the dialog starts closing (can be prevented) */
|
|
42
136
|
BEFORE_CLOSE: 'beforeclose',
|
|
137
|
+
/** Fired after the dialog has fully opened (animation complete) */
|
|
43
138
|
AFTER_OPEN: 'afteropen',
|
|
139
|
+
/** Fired after the dialog has fully closed (animation complete) */
|
|
44
140
|
AFTER_CLOSE: 'afterclose'
|
|
45
141
|
} as const;
|