mtrl 0.6.2 → 0.7.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.
Files changed (48) hide show
  1. package/README.md +39 -0
  2. package/dist/README.md +39 -0
  3. package/dist/components/badge/index.d.ts +2 -2
  4. package/dist/components/button/index.d.ts +1 -0
  5. package/dist/components/card/index.d.ts +0 -1
  6. package/dist/components/chips/index.d.ts +3 -4
  7. package/dist/components/datepicker/index.d.ts +3 -3
  8. package/dist/components/dialog/index.d.ts +2 -2
  9. package/dist/components/drawer/api.d.ts +54 -0
  10. package/dist/components/drawer/config.d.ts +106 -0
  11. package/dist/components/drawer/constants.d.ts +97 -0
  12. package/dist/components/drawer/drawer.d.ts +59 -0
  13. package/dist/components/drawer/features/headline.d.ts +17 -0
  14. package/dist/components/drawer/features/index.d.ts +3 -0
  15. package/dist/components/drawer/features/items.d.ts +18 -0
  16. package/dist/components/drawer/features/state.d.ts +18 -0
  17. package/dist/components/drawer/index.d.ts +6 -0
  18. package/dist/components/drawer/types.d.ts +233 -0
  19. package/dist/components/fab/index.d.ts +2 -2
  20. package/dist/components/index.d.ts +38 -47
  21. package/dist/components/menu/constants.d.ts +2 -0
  22. package/dist/components/menu/features/opener.d.ts +1 -1
  23. package/dist/components/menu/types.d.ts +14 -0
  24. package/dist/components/progress/index.d.ts +2 -3
  25. package/dist/components/progress/types.d.ts +8 -0
  26. package/dist/components/search/index.d.ts +0 -1
  27. package/dist/components/segmented-button/index.d.ts +3 -4
  28. package/dist/components/slider/index.d.ts +2 -3
  29. package/dist/components/snackbar/index.d.ts +2 -3
  30. package/dist/components/textfield/index.d.ts +0 -1
  31. package/dist/index.cjs +10 -20
  32. package/dist/index.cjs.map +52 -70
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.js +10 -20
  35. package/dist/index.js.map +52 -70
  36. package/dist/package.json +1 -1
  37. package/dist/styles.css +2 -2
  38. package/package.json +23 -5
  39. package/src/styles/components/_button-group.scss +1 -1
  40. package/src/styles/components/_button.scss +1 -1
  41. package/src/styles/components/_drawer.scss +611 -0
  42. package/src/styles/components/_extended-fab.scss +1 -1
  43. package/src/styles/components/_fab.scss +1 -1
  44. package/src/styles/components/_icon-button.scss +1 -1
  45. package/src/styles/components/_menu.scss +25 -0
  46. package/src/styles/components/_segmented-button.scss +1 -1
  47. package/src/styles/main.scss +1 -0
  48. package/dist/constants.d.ts +0 -30
@@ -0,0 +1,233 @@
1
+ import { BaseComponentConfig } from "../../core/config/component";
2
+ /**
3
+ * Drawer variant type — controls layout behavior
4
+ * @category Components
5
+ * @remarks
6
+ * - standard: Inline drawer, can be permanently visible or toggled. Best for expanded+ window sizes.
7
+ * - modal: Overlay drawer with scrim. Best for compact/medium window sizes.
8
+ */
9
+ export type DrawerVariant = "standard" | "modal";
10
+ /**
11
+ * Drawer position — which edge the drawer anchors to
12
+ * @category Components
13
+ */
14
+ export type DrawerPosition = "start" | "end";
15
+ /**
16
+ * Configuration for a navigation destination item
17
+ * @category Components
18
+ */
19
+ export interface DrawerItemConfig {
20
+ /** Item type — defaults to 'item' if omitted */
21
+ type?: "item" | "divider" | "section";
22
+ /** Unique identifier for the item */
23
+ id?: string;
24
+ /** Destination label text */
25
+ label?: string;
26
+ /** Icon HTML content (placed before label) */
27
+ icon?: string;
28
+ /** Badge text (e.g. unread count) */
29
+ badge?: string;
30
+ /** Whether this item is initially active/selected */
31
+ active?: boolean;
32
+ /** Section label text (only when type is 'section') */
33
+ sectionLabel?: string;
34
+ /** Whether the item is disabled */
35
+ disabled?: boolean;
36
+ }
37
+ /**
38
+ * Event detail emitted when a drawer item is selected
39
+ * @category Components
40
+ */
41
+ export interface DrawerSelectEvent {
42
+ /** The selected item's id */
43
+ id: string;
44
+ /** The selected item's label */
45
+ label: string;
46
+ /** The selected item's index within navigation items (excludes dividers/sections) */
47
+ index: number;
48
+ /** The underlying DOM event */
49
+ originalEvent: Event;
50
+ }
51
+ /**
52
+ * Configuration interface for the Drawer component
53
+ * @category Components
54
+ */
55
+ export interface DrawerConfig extends BaseComponentConfig {
56
+ /**
57
+ * Drawer variant that determines layout behavior
58
+ * @default 'standard'
59
+ */
60
+ variant?: DrawerVariant | string;
61
+ /**
62
+ * Drawer anchor position
63
+ * @default 'start'
64
+ */
65
+ position?: DrawerPosition | string;
66
+ /**
67
+ * Whether the drawer is initially open
68
+ * @default false
69
+ */
70
+ open?: boolean;
71
+ /**
72
+ * Whether the modal drawer can be dismissed by clicking the scrim
73
+ * @default true
74
+ */
75
+ dismissible?: boolean;
76
+ /**
77
+ * Optional headline text displayed at the top of the drawer
78
+ * @example 'Mail'
79
+ */
80
+ headline?: string;
81
+ /**
82
+ * Navigation items configuration array.
83
+ * Supports destination items, dividers, and section labels.
84
+ * @example
85
+ * [
86
+ * { id: 'inbox', label: 'Inbox', icon: '<svg>...</svg>', badge: '24', active: true },
87
+ * { type: 'divider' },
88
+ * { type: 'section', label: 'Labels' },
89
+ * { id: 'family', label: 'Family', icon: '<svg>...</svg>' },
90
+ * ]
91
+ */
92
+ items?: DrawerItemConfig[];
93
+ /**
94
+ * Drawer width as a CSS value
95
+ * @default '360px'
96
+ */
97
+ width?: string | number;
98
+ /**
99
+ * When true, renders a compact drawer with smaller items and tighter spacing.
100
+ * Useful in dense UIs like admin panels where the standard 56px item height
101
+ * is too large.
102
+ * @default false
103
+ */
104
+ dense?: boolean;
105
+ /**
106
+ * Additional CSS classes to add to the drawer
107
+ */
108
+ class?: string;
109
+ /**
110
+ * Component prefix for class names
111
+ * @default 'mtrl'
112
+ */
113
+ prefix?: string;
114
+ /**
115
+ * Component name used in class generation
116
+ */
117
+ componentName?: string;
118
+ /**
119
+ * Callback when a navigation item is selected
120
+ */
121
+ onSelect?: (event: DrawerSelectEvent) => void;
122
+ /**
123
+ * Callback when the drawer opens
124
+ */
125
+ onOpen?: () => void;
126
+ /**
127
+ * Callback when the drawer closes
128
+ */
129
+ onClose?: () => void;
130
+ }
131
+ /**
132
+ * Drawer component interface — public API
133
+ * @category Components
134
+ */
135
+ export interface DrawerComponent {
136
+ /** The drawer's root DOM element */
137
+ element: HTMLElement;
138
+ /**
139
+ * Gets a class name with the component's prefix
140
+ * @param name - Base class name
141
+ * @returns Prefixed class name
142
+ */
143
+ getClass: (name: string) => string;
144
+ /**
145
+ * Opens the drawer
146
+ * @returns The drawer component for chaining
147
+ */
148
+ open: () => DrawerComponent;
149
+ /**
150
+ * Closes the drawer
151
+ * @returns The drawer component for chaining
152
+ */
153
+ close: () => DrawerComponent;
154
+ /**
155
+ * Toggles the drawer open/closed state
156
+ * @returns The drawer component for chaining
157
+ */
158
+ toggle: () => DrawerComponent;
159
+ /**
160
+ * Checks if the drawer is currently open
161
+ * @returns True if the drawer is open
162
+ */
163
+ isOpen: () => boolean;
164
+ /**
165
+ * Sets the active navigation item by id
166
+ * @param id - Item id to activate
167
+ * @returns The drawer component for chaining
168
+ */
169
+ setActive: (id: string) => DrawerComponent;
170
+ /**
171
+ * Gets the currently active item id
172
+ * @returns Active item id or null
173
+ */
174
+ getActive: () => string | null;
175
+ /**
176
+ * Sets the headline text
177
+ * @param text - Headline text
178
+ * @returns The drawer component for chaining
179
+ */
180
+ setHeadline: (text: string) => DrawerComponent;
181
+ /**
182
+ * Gets the headline text
183
+ * @returns Headline text
184
+ */
185
+ getHeadline: () => string;
186
+ /**
187
+ * Sets the navigation items
188
+ * @param items - Array of item configurations
189
+ * @returns The drawer component for chaining
190
+ */
191
+ setItems: (items: DrawerItemConfig[]) => DrawerComponent;
192
+ /**
193
+ * Gets the current items configuration
194
+ * @returns Array of item configurations
195
+ */
196
+ getItems: () => DrawerItemConfig[];
197
+ /**
198
+ * Sets a badge on a specific item
199
+ * @param id - Item id
200
+ * @param badge - Badge text or empty string to remove
201
+ * @returns The drawer component for chaining
202
+ */
203
+ setBadge: (id: string, badge: string) => DrawerComponent;
204
+ /**
205
+ * Adds an event listener
206
+ * @param event - Event name ('select', 'open', 'close')
207
+ * @param handler - Event handler function
208
+ * @returns The drawer component for chaining
209
+ */
210
+ on: (event: string, handler: Function) => DrawerComponent;
211
+ /**
212
+ * Removes an event listener
213
+ * @param event - Event name
214
+ * @param handler - Event handler function
215
+ * @returns The drawer component for chaining
216
+ */
217
+ off: (event: string, handler: Function) => DrawerComponent;
218
+ /**
219
+ * Adds CSS classes to the drawer element
220
+ * @param classes - One or more class names to add
221
+ * @returns The drawer component for chaining
222
+ */
223
+ addClass: (...classes: string[]) => DrawerComponent;
224
+ /**
225
+ * Destroys the drawer component and cleans up resources
226
+ */
227
+ destroy: () => void;
228
+ /** API for managing component lifecycle */
229
+ lifecycle: {
230
+ /** Destroys the component and cleans up resources */
231
+ destroy: () => void;
232
+ };
233
+ }
@@ -31,5 +31,5 @@
31
31
  *
32
32
  * @category Components
33
33
  */
34
- export { default, default as createFab } from './fab';
35
- export { FabConfig, FabComponent, FabVariant, FabSize, FabPosition } from './types';
34
+ export { default, default as createFab } from "./fab";
35
+ export { FabConfig, FabComponent, FabVariant, FabSize, FabPosition, } from "./types";
@@ -1,54 +1,12 @@
1
1
  /**
2
2
  * Component library exports
3
3
  *
4
- * This file re-exports all components and their associated types, constants,
5
- * and utilities from the mtrl library. Both named exports and default exports
6
- * are handled to provide a consistent public API while maintaining tree-shaking
7
- * compatibility.
4
+ * This file exports all component creators and their types.
5
+ * Constants are NOT re-exported here to enable proper tree-shaking.
6
+ * Import constants directly from component paths if needed.
8
7
  *
9
8
  * @packageDocumentation
10
9
  */
11
- export { LIST_DEFAULTS, LIST_TYPES, LIST_SELECTION_MODES, LIST_EVENTS, LIST_SCROLL_POSITIONS, LIST_CLASSES, } from "./list/constants";
12
- export type { ListConfig, ListComponent, SelectEvent as ListSelectEvent, // Rename to avoid collision
13
- LoadEvent, } from "./list/types";
14
- export { BUTTON_GROUP_VARIANTS, BUTTON_GROUP_ORIENTATIONS, BUTTON_GROUP_DENSITY, BUTTON_GROUP_EVENTS, BUTTON_GROUP_DEFAULTS, BUTTON_GROUP_CLASSES, BUTTON_GROUP_HEIGHTS, BUTTON_GROUP_RADII, } from "./button-group/constants";
15
- export type { ButtonGroupConfig, ButtonGroupComponent, ButtonGroupItemConfig, ButtonGroupEvent, ButtonGroupEventType, ButtonGroupVariant, ButtonGroupOrientation, ButtonGroupDensity, } from "./button-group/types";
16
- export { SELECT_VARIANTS, SELECT_PLACEMENT, SELECT_INTERACTION, SELECT_EVENTS, SELECT_ICONS, SELECT_DEFAULTS, SELECT_CLASSES, } from "./select/constants";
17
- export type { SelectConfig, SelectComponent, SelectOption, SelectEvent, // Keep the original name since select is more commonly used
18
- SelectChangeEvent, } from "./select/types";
19
- export * from "./badge";
20
- export * from "./bottom-app-bar";
21
- export * from "./button";
22
- export * from "./button-group";
23
- export * from "./card";
24
- export * from "./carousel";
25
- export * from "./checkbox";
26
- export * from "./chips";
27
- export * from "./datepicker";
28
- export * from "./dialog";
29
- export * from "./fab";
30
- export * from "./extended-fab";
31
- export * from "./icon-button";
32
- export * from "./menu";
33
- export * from "./navigation";
34
- export { PROGRESS_VARIANTS, PROGRESS_SHAPES, PROGRESS_EVENTS, PROGRESS_DEFAULTS, PROGRESS_CLASSES, PROGRESS_MEASUREMENTS, PROGRESS_THICKNESS, } from "./progress/constants";
35
- export type { ProgressConfig, ProgressComponent, ProgressShape, } from "./progress/types";
36
- export * from "./radios";
37
- export * from "./search";
38
- export * from "./segmented-button";
39
- export * from "./sheet";
40
- export * from "./slider";
41
- export * from "./snackbar";
42
- export * from "./switch";
43
- export * from "./tabs";
44
- export * from "./textfield";
45
- export * from "./timepicker";
46
- export * from "./top-app-bar";
47
- export * from "./tooltip";
48
- export { createDivider } from "./divider";
49
- export type { DividerConfig } from "./divider/config";
50
- export type { DividerComponent } from "./divider/types";
51
- export { createCardContent, createCardHeader, createCardActions, createCardMedia, } from "./card/content";
52
10
  export { default as createBadge } from "./badge";
53
11
  export { default as createBottomAppBar } from "./bottom-app-bar";
54
12
  export { default as createButton } from "./button";
@@ -59,13 +17,13 @@ export { default as createCheckbox } from "./checkbox";
59
17
  export { createChip, createChips } from "./chips";
60
18
  export { default as createDatePicker } from "./datepicker";
61
19
  export { default as createDialog } from "./dialog";
20
+ export { createDivider } from "./divider";
21
+ export { default as createDrawer } from "./drawer";
62
22
  export { default as createFab } from "./fab";
63
23
  export { default as createExtendedFab } from "./extended-fab";
64
24
  export { default as createIconButton } from "./icon-button";
65
25
  export { default as createList } from "./list";
66
26
  export { default as createMenu } from "./menu";
67
- export { default as createNavigation } from "./navigation";
68
- export { default as createNavigationSystem } from "./navigation/system";
69
27
  export { default as createProgress } from "./progress";
70
28
  export { default as createRadios } from "./radios";
71
29
  export { default as createSearch } from "./search";
@@ -82,3 +40,36 @@ export { default as createTextfield } from "./textfield";
82
40
  export { default as createTimePicker } from "./timepicker";
83
41
  export { default as createTopAppBar } from "./top-app-bar";
84
42
  export { default as createTooltip } from "./tooltip";
43
+ export { createCardContent, createCardHeader, createCardActions, createCardMedia, } from "./card/content";
44
+ export type { BadgeConfig, BadgeComponent } from "./badge/types";
45
+ export type { BottomAppBarConfig, BottomAppBar } from "./bottom-app-bar/types";
46
+ export type { ButtonConfig, ButtonComponent, ButtonVariant, } from "./button/types";
47
+ export type { ButtonGroupConfig, ButtonGroupComponent, ButtonGroupItemConfig, ButtonGroupEvent, ButtonGroupEventType, ButtonGroupVariant, ButtonGroupOrientation, ButtonGroupDensity, } from "./button-group/types";
48
+ export type { CardSchema } from "./card/types";
49
+ export type { CarouselConfig, CarouselComponent } from "./carousel/types";
50
+ export type { CheckboxConfig, CheckboxComponent } from "./checkbox/types";
51
+ export type { ChipConfig, ChipComponent, ChipVariant, ChipsConfig, ChipsComponent, } from "./chips/types";
52
+ export type { DatePickerConfig, DatePickerComponent } from "./datepicker/types";
53
+ export type { DialogConfig, DialogComponent } from "./dialog/types";
54
+ export type { DrawerConfig, DrawerComponent, DrawerVariant, DrawerPosition, DrawerItemConfig, DrawerSelectEvent, } from "./drawer/types";
55
+ export type { DividerConfig } from "./divider/config";
56
+ export type { DividerComponent } from "./divider/types";
57
+ export type { FabConfig, FabComponent } from "./fab/types";
58
+ export type { ExtendedFabConfig, ExtendedFabComponent, } from "./extended-fab/types";
59
+ export type { IconButtonConfig, IconButtonComponent, } from "./icon-button/types";
60
+ export type { ListConfig, ListComponent, SelectEvent as ListSelectEvent, LoadEvent, } from "./list/types";
61
+ export type { MenuConfig, MenuComponent, MenuItem } from "./menu/types";
62
+ export type { ProgressConfig, ProgressComponent, ProgressShape, } from "./progress/types";
63
+ export type { RadiosConfig, RadiosComponent, RadioOptionConfig, } from "./radios/types";
64
+ export type { SearchConfig, SearchComponent } from "./search/types";
65
+ export type { SelectConfig, SelectComponent, SelectOption, SelectEvent, SelectChangeEvent, } from "./select/types";
66
+ export type { SegmentedButtonConfig, SegmentedButtonComponent, } from "./segmented-button/types";
67
+ export type { SheetConfig, SheetComponent } from "./sheet/types";
68
+ export type { SliderConfig, SliderComponent, SliderEvent, } from "./slider/types";
69
+ export type { SnackbarConfig, SnackbarComponent } from "./snackbar/types";
70
+ export type { SwitchConfig, SwitchComponent } from "./switch/types";
71
+ export type { TabsConfig, TabsComponent, TabConfig, TabComponent, } from "./tabs/types";
72
+ export type { TextfieldConfig, TextfieldComponent } from "./textfield/types";
73
+ export type { TimePickerConfig, TimePickerComponent } from "./timepicker/types";
74
+ export type { TopAppBarConfig, TopAppBar } from "./top-app-bar/types";
75
+ export type { TooltipConfig, TooltipComponent } from "./tooltip/types";
@@ -103,4 +103,6 @@ export declare const MENU_CLASSES: {
103
103
  readonly ITEM_SHORTCUT: "menu__item-shortcut";
104
104
  /** Submenu indicator */
105
105
  readonly SUBMENU_INDICATOR: "menu__submenu-indicator";
106
+ /** Dense/compact variant */
107
+ readonly DENSE: "menu--dense";
106
108
  };
@@ -1,4 +1,4 @@
1
- import { MenuConfig } from '../types';
1
+ import { MenuConfig } from "../types";
2
2
  /**
3
3
  * Adds opener functionality to menu component
4
4
  * Manages the relationship between menu and its opener element
@@ -181,6 +181,20 @@ export interface MenuConfig {
181
181
  * Use this when the menu needs to stay within a specific container (e.g., inside a dialog)
182
182
  */
183
183
  container?: HTMLElement | null;
184
+ /**
185
+ * When true, the opener is used only for positioning.
186
+ * No click, blur, or keyboard handlers are attached to the opener element.
187
+ * The consumer is responsible for calling open() / close() manually.
188
+ * @default false
189
+ */
190
+ manualOpen?: boolean;
191
+ /**
192
+ * When true, renders a compact menu with smaller items and tighter spacing.
193
+ * Useful in dense UIs like toolbars and action bars where the standard
194
+ * 48px item height is too large.
195
+ * @default false
196
+ */
197
+ dense?: boolean;
184
198
  /**
185
199
  * Additional CSS classes to add to the menu
186
200
  */
@@ -1,3 +1,2 @@
1
- export { default } from './progress';
2
- export { ProgressConfig, ProgressComponent, ProgressShape } from './types';
3
- export { PROGRESS_VARIANTS, PROGRESS_SHAPES, PROGRESS_EVENTS, PROGRESS_DEFAULTS, PROGRESS_CLASSES, PROGRESS_MEASUREMENTS, PROGRESS_THICKNESS } from './constants';
1
+ export { default } from "./progress";
2
+ export { ProgressConfig, ProgressComponent, ProgressShape } from "./types";
@@ -239,6 +239,14 @@ export interface ProgressComponent {
239
239
  * @returns Current size in pixels, or undefined for linear variant
240
240
  */
241
241
  getSize: () => number | undefined;
242
+ /**
243
+ * Returns a Promise that resolves after the current canvas state
244
+ * has been painted to screen. Useful when you need to ensure a
245
+ * value change (e.g. 100%) is visually rendered before proceeding.
246
+ *
247
+ * @returns Promise that resolves after the next paint
248
+ */
249
+ painted: () => Promise<void>;
242
250
  /**
243
251
  * Adds an event listener to the progress
244
252
  * @param event - Event name ('change', 'complete')
@@ -1,3 +1,2 @@
1
1
  export { default } from "./search";
2
2
  export type { SearchConfig, SearchComponent, SearchEvent, SearchState, SearchViewMode, SearchEventType, SearchSuggestion, SearchTrailingItem, } from "./types";
3
- export { SEARCH_STATES, SEARCH_VIEW_MODES, SEARCH_EVENTS, SEARCH_ICONS, SEARCH_DEFAULTS, SEARCH_CLASSES, SEARCH_MEASUREMENTS, SEARCH_KEYS, } from "./constants";
@@ -1,4 +1,3 @@
1
- export { default, default as createSegmentedButton } from './segmented-button';
2
- export { SelectionMode, Density } from './types';
3
- export type { SegmentedButtonConfig, SegmentedButtonComponent, SegmentConfig, Segment } from './types';
4
- export { SEGMENTED_BUTTON_MODES, SEGMENTED_BUTTON_DENSITY, SEGMENTED_BUTTON_EVENTS, SEGMENTED_BUTTON_DEFAULTS, SEGMENTED_BUTTON_ICONS, SEGMENTED_BUTTON_CLASSES } from './constants';
1
+ export { default, default as createSegmentedButton } from "./segmented-button";
2
+ export { SelectionMode, Density } from "./types";
3
+ export type { SegmentedButtonConfig, SegmentedButtonComponent, SegmentConfig, Segment, } from "./types";
@@ -1,3 +1,2 @@
1
- export { default } from './slider';
2
- export { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS, SLIDER_POSITIONS, SLIDER_DEFAULTS, SLIDER_CLASSES } from './constants';
3
- export { type SliderConfig, type SliderComponent, type SliderEvent } from './types';
1
+ export { default } from "./slider";
2
+ export { type SliderConfig, type SliderComponent, type SliderEvent, } from "./types";
@@ -1,3 +1,2 @@
1
- export { default } from './snackbar';
2
- export { SNACKBAR_VARIANTS, SNACKBAR_POSITIONS, SNACKBAR_STATES, SNACKBAR_EVENTS, SNACKBAR_DEFAULTS, SNACKBAR_CLASSES } from './constants';
3
- export { SnackbarConfig, SnackbarComponent } from './types';
1
+ export { default } from "./snackbar";
2
+ export { SnackbarConfig, SnackbarComponent } from "./types";
@@ -1,3 +1,2 @@
1
1
  export { default } from "./textfield";
2
- export { TEXTFIELD_VARIANTS, TEXTFIELD_STATES, TEXTFIELD_TYPES, TEXTFIELD_EVENTS, TEXTFIELD_DEFAULTS, TEXTFIELD_CLASSES, TEXTFIELD_DENSITY, } from "./constants";
3
2
  export { TextfieldConfig, TextfieldComponent, TextfieldDensity } from "./types";