mtrl 0.2.2 → 0.2.4

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 (97) hide show
  1. package/.typedocignore +11 -0
  2. package/DOCS.md +153 -0
  3. package/index.ts +18 -3
  4. package/package.json +7 -2
  5. package/src/components/badge/_styles.scss +174 -0
  6. package/src/components/badge/api.ts +292 -0
  7. package/src/components/badge/badge.ts +52 -0
  8. package/src/components/badge/config.ts +68 -0
  9. package/src/components/badge/constants.ts +30 -0
  10. package/src/components/badge/features.ts +185 -0
  11. package/src/components/badge/index.ts +4 -0
  12. package/src/components/badge/types.ts +105 -0
  13. package/src/components/button/types.ts +174 -29
  14. package/src/components/carousel/_styles.scss +645 -0
  15. package/src/components/carousel/api.ts +147 -0
  16. package/src/components/carousel/carousel.ts +178 -0
  17. package/src/components/carousel/config.ts +91 -0
  18. package/src/components/carousel/constants.ts +95 -0
  19. package/src/components/carousel/features/drag.ts +388 -0
  20. package/src/components/carousel/features/index.ts +8 -0
  21. package/src/components/carousel/features/slides.ts +682 -0
  22. package/src/components/carousel/index.ts +38 -0
  23. package/src/components/carousel/types.ts +327 -0
  24. package/src/components/dialog/_styles.scss +213 -0
  25. package/src/components/dialog/api.ts +283 -0
  26. package/src/components/dialog/config.ts +113 -0
  27. package/src/components/dialog/constants.ts +32 -0
  28. package/src/components/dialog/dialog.ts +56 -0
  29. package/src/components/dialog/features.ts +713 -0
  30. package/src/components/dialog/index.ts +15 -0
  31. package/src/components/dialog/types.ts +221 -0
  32. package/src/components/progress/_styles.scss +13 -1
  33. package/src/components/progress/api.ts +2 -2
  34. package/src/components/progress/progress.ts +2 -2
  35. package/src/components/progress/types.ts +3 -0
  36. package/src/components/radios/_styles.scss +232 -0
  37. package/src/components/radios/api.ts +100 -0
  38. package/src/components/radios/config.ts +60 -0
  39. package/src/components/radios/constants.ts +28 -0
  40. package/src/components/radios/index.ts +4 -0
  41. package/src/components/radios/radio.ts +269 -0
  42. package/src/components/radios/radios.ts +42 -0
  43. package/src/components/radios/types.ts +232 -0
  44. package/src/components/sheet/_styles.scss +236 -0
  45. package/src/components/sheet/api.ts +96 -0
  46. package/src/components/sheet/config.ts +66 -0
  47. package/src/components/sheet/constants.ts +20 -0
  48. package/src/components/sheet/features/content.ts +51 -0
  49. package/src/components/sheet/features/gestures.ts +177 -0
  50. package/src/components/sheet/features/index.ts +6 -0
  51. package/src/components/sheet/features/position.ts +42 -0
  52. package/src/components/sheet/features/state.ts +116 -0
  53. package/src/components/sheet/features/title.ts +86 -0
  54. package/src/components/sheet/index.ts +4 -0
  55. package/src/components/sheet/sheet.ts +57 -0
  56. package/src/components/sheet/types.ts +266 -0
  57. package/src/components/slider/_styles.scss +518 -0
  58. package/src/components/slider/api.ts +336 -0
  59. package/src/components/slider/config.ts +145 -0
  60. package/src/components/slider/constants.ts +28 -0
  61. package/src/components/slider/features/appearance.ts +140 -0
  62. package/src/components/slider/features/disabled.ts +43 -0
  63. package/src/components/slider/features/events.ts +164 -0
  64. package/src/components/slider/features/index.ts +5 -0
  65. package/src/components/slider/features/interactions.ts +256 -0
  66. package/src/components/slider/features/keyboard.ts +114 -0
  67. package/src/components/slider/features/slider.ts +336 -0
  68. package/src/components/slider/features/structure.ts +264 -0
  69. package/src/components/slider/features/ui.ts +518 -0
  70. package/src/components/slider/index.ts +9 -0
  71. package/src/components/slider/slider.ts +58 -0
  72. package/src/components/slider/types.ts +166 -0
  73. package/src/components/tabs/_styles.scss +224 -0
  74. package/src/components/tabs/api.ts +443 -0
  75. package/src/components/tabs/config.ts +80 -0
  76. package/src/components/tabs/constants.ts +12 -0
  77. package/src/components/tabs/index.ts +4 -0
  78. package/src/components/tabs/tabs.ts +52 -0
  79. package/src/components/tabs/types.ts +247 -0
  80. package/src/components/textfield/_styles.scss +97 -4
  81. package/src/components/tooltip/_styles.scss +241 -0
  82. package/src/components/tooltip/api.ts +411 -0
  83. package/src/components/tooltip/config.ts +78 -0
  84. package/src/components/tooltip/constants.ts +27 -0
  85. package/src/components/tooltip/index.ts +4 -0
  86. package/src/components/tooltip/tooltip.ts +60 -0
  87. package/src/components/tooltip/types.ts +178 -0
  88. package/src/core/build/_ripple.scss +79 -0
  89. package/src/core/build/constants.ts +48 -0
  90. package/src/core/build/icon.ts +137 -0
  91. package/src/core/build/ripple.ts +216 -0
  92. package/src/core/build/text.ts +91 -0
  93. package/src/index.ts +9 -1
  94. package/src/styles/abstract/_variables.scss +24 -12
  95. package/tsconfig.json +22 -0
  96. package/typedoc.json +28 -0
  97. package/typedoc.simple.json +14 -0
@@ -0,0 +1,116 @@
1
+ // src/components/sheet/features/state.ts
2
+ import { SHEET_EVENTS } from '../constants';
3
+
4
+ /**
5
+ * Adds state management functionality to a component
6
+ * @param {Object} config - Component configuration with initial state
7
+ * @returns {Function} Higher-order function that adds state to a component
8
+ */
9
+ export const withState = (config) => (component) => {
10
+ const { open: initialOpen = false, dismissible = true } = config;
11
+ let isOpen = initialOpen;
12
+
13
+ // Create scrim element
14
+ const scrimElement = document.createElement('div');
15
+ scrimElement.className = `${component.getClass('sheet')}-scrim`;
16
+
17
+ // Add scrim after component in DOM
18
+ component.element.parentNode?.insertBefore(scrimElement, component.element.nextSibling);
19
+
20
+ // Mark as dismissible if configured
21
+ if (dismissible) {
22
+ component.element.classList.add(`${component.getClass('sheet')}--dismissible`);
23
+
24
+ // Add click handler to scrim
25
+ scrimElement.addEventListener('click', () => {
26
+ if (dismissible) {
27
+ close();
28
+ }
29
+ });
30
+ }
31
+
32
+ // Initialize component state
33
+ if (initialOpen) {
34
+ component.element.classList.add(`${component.getClass('sheet')}--open`);
35
+ }
36
+
37
+ // Add elevation class based on config
38
+ if (config.elevation) {
39
+ component.element.classList.add(`${component.getClass('sheet')}--elevation-${config.elevation}`);
40
+ }
41
+
42
+ // Add keyboard support (ESC to close)
43
+ document.addEventListener('keydown', (event) => {
44
+ if (event.key === 'Escape' && isOpen && dismissible) {
45
+ close();
46
+ }
47
+ });
48
+
49
+ /**
50
+ * Opens the sheet
51
+ */
52
+ function open() {
53
+ if (!isOpen) {
54
+ isOpen = true;
55
+ component.element.classList.add(`${component.getClass('sheet')}--open`);
56
+ component.events.emit(SHEET_EVENTS.OPEN);
57
+
58
+ if (config.onOpen) {
59
+ config.onOpen();
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Closes the sheet
66
+ */
67
+ function close() {
68
+ if (isOpen) {
69
+ isOpen = false;
70
+ component.element.classList.remove(`${component.getClass('sheet')}--open`);
71
+ component.events.emit(SHEET_EVENTS.CLOSE);
72
+
73
+ if (config.onClose) {
74
+ config.onClose();
75
+ }
76
+ }
77
+ }
78
+
79
+ return {
80
+ ...component,
81
+ state: {
82
+ open,
83
+ close,
84
+
85
+ /**
86
+ * Checks if the sheet is open
87
+ * @returns {boolean} Whether the sheet is open
88
+ */
89
+ isOpen() {
90
+ return isOpen;
91
+ },
92
+
93
+ /**
94
+ * Sets whether the sheet can be dismissed
95
+ * @param {boolean} canDismiss - Whether the sheet can be dismissed
96
+ */
97
+ setDismissible(canDismiss: boolean) {
98
+ if (canDismiss) {
99
+ component.element.classList.add(`${component.getClass('sheet')}--dismissible`);
100
+ } else {
101
+ component.element.classList.remove(`${component.getClass('sheet')}--dismissible`);
102
+ }
103
+ }
104
+ },
105
+
106
+ /**
107
+ * Initializes the component (called after creation)
108
+ */
109
+ initialize() {
110
+ // Make sure scrim is in the correct DOM position
111
+ if (scrimElement.parentNode !== component.element.parentNode) {
112
+ component.element.parentNode?.insertBefore(scrimElement, component.element.nextSibling);
113
+ }
114
+ }
115
+ };
116
+ };
@@ -0,0 +1,86 @@
1
+ // src/core/compose/features/with-title.ts
2
+ /**
3
+ * Adds title functionality to a component
4
+ * @param {Object} config - Component configuration with optional title
5
+ * @returns {Function} Higher-order function that adds title to a component
6
+ */
7
+ export const withTitle = (config) => (component) => {
8
+ const { title = '' } = config;
9
+
10
+ // Only create title element if title is provided or dragHandle is enabled
11
+ let titleElement = null;
12
+
13
+ if (title || config.dragHandle) {
14
+ // Create title element
15
+ titleElement = document.createElement('div');
16
+ titleElement.className = `${component.getClass('sheet')}-title`;
17
+
18
+ if (title) {
19
+ titleElement.textContent = title;
20
+ }
21
+
22
+ // Insert before content
23
+ component.container.insertBefore(titleElement, component.container.firstChild);
24
+
25
+ // Add drag handle if enabled
26
+ if (config.dragHandle) {
27
+ const handleElement = document.createElement('div');
28
+ handleElement.className = `${component.getClass('sheet')}-handle`;
29
+ component.container.insertBefore(handleElement, component.container.firstChild);
30
+
31
+ // Store handle element reference
32
+ component.dragHandle = {
33
+ element: handleElement,
34
+
35
+ /**
36
+ * Sets the visibility of the drag handle
37
+ * @param {boolean} visible - Whether the handle should be visible
38
+ */
39
+ setVisible(visible: boolean) {
40
+ handleElement.style.display = visible ? 'block' : 'none';
41
+ }
42
+ };
43
+ }
44
+ }
45
+
46
+ return {
47
+ ...component,
48
+ title: {
49
+ /**
50
+ * Sets the title text
51
+ * @param {string} text - Title text
52
+ * @returns {Object} Title API for chaining
53
+ */
54
+ setTitle(text: string) {
55
+ if (!titleElement && text) {
56
+ // Create title element if it doesn't exist
57
+ titleElement = document.createElement('div');
58
+ titleElement.className = `${component.getClass('sheet')}-title`;
59
+ component.container.insertBefore(titleElement, component.content.getElement());
60
+ }
61
+
62
+ if (titleElement) {
63
+ titleElement.textContent = text;
64
+ }
65
+
66
+ return this;
67
+ },
68
+
69
+ /**
70
+ * Gets the current title text
71
+ * @returns {string} Title text or empty string
72
+ */
73
+ getTitle() {
74
+ return titleElement ? titleElement.textContent || '' : '';
75
+ },
76
+
77
+ /**
78
+ * Gets the title DOM element
79
+ * @returns {HTMLElement|null} Title element or null
80
+ */
81
+ getElement() {
82
+ return titleElement;
83
+ }
84
+ }
85
+ };
86
+ };
@@ -0,0 +1,4 @@
1
+ // src/components/sheet/index.ts
2
+ export { default } from './sheet';
3
+ export { SHEET_VARIANTS, SHEET_POSITIONS, SHEET_EVENTS } from './constants';
4
+ export { SheetConfig, SheetComponent } from './types';
@@ -0,0 +1,57 @@
1
+ // src/components/sheet/sheet.ts
2
+ import { PREFIX } from '../../core/config';
3
+ import { pipe } from '../../core/compose';
4
+ import { createBase, withElement } from '../../core/compose/component';
5
+ import {
6
+ withEvents,
7
+ withVariant,
8
+ withState,
9
+ withLifecycle,
10
+ withGestures
11
+ } from '../../core/compose/features';
12
+ import {
13
+ withContent,
14
+ withTitle,
15
+ withPosition,
16
+ withState,
17
+ withGestures
18
+ } from './features';
19
+ import { withAPI } from './api';
20
+ import { SheetConfig } from './types';
21
+ import { SHEET_VARIANTS, SHEET_POSITIONS } from './constants';
22
+ import { createBaseConfig, getElementConfig, getApiConfig } from './config';
23
+
24
+ /**
25
+ * Creates a new Sheet component
26
+ * @param {SheetConfig} config - Sheet configuration object
27
+ * @returns {SheetComponent} Sheet component instance
28
+ */
29
+ const createSheet = (config: SheetConfig = {}) => {
30
+ const baseConfig = createBaseConfig(config);
31
+
32
+ try {
33
+ const sheet = pipe(
34
+ createBase,
35
+ withEvents(),
36
+ withElement(getElementConfig(baseConfig)),
37
+ withVariant(baseConfig),
38
+ withPosition(baseConfig),
39
+ withContent(baseConfig),
40
+ withTitle(baseConfig),
41
+ withState(baseConfig),
42
+ withGestures(baseConfig),
43
+ withLifecycle(),
44
+ comp => withAPI(getApiConfig(comp))(comp)
45
+ )(baseConfig);
46
+
47
+ // Initialize the sheet (create DOM structure, add event listeners)
48
+ sheet.initialize();
49
+
50
+ return sheet;
51
+ } catch (error) {
52
+ console.error('Sheet creation error:', error);
53
+ throw new Error(`Failed to create sheet: ${(error as Error).message}`);
54
+ }
55
+ };
56
+
57
+ export default createSheet;
@@ -0,0 +1,266 @@
1
+ // src/components/sheet/types.ts
2
+ import { SHEET_VARIANTS, SHEET_POSITIONS } from './constants';
3
+
4
+ /**
5
+ * Configuration interface for the Sheet component
6
+ * @category Components
7
+ */
8
+ export interface SheetConfig {
9
+ /**
10
+ * Sheet variant that determines visual styling
11
+ * @default 'standard'
12
+ */
13
+ variant?: keyof typeof SHEET_VARIANTS | string;
14
+
15
+ /**
16
+ * Sheet position on the screen
17
+ * @default 'bottom'
18
+ */
19
+ position?: keyof typeof SHEET_POSITIONS | string;
20
+
21
+ /**
22
+ * Whether the sheet is initially open
23
+ * @default false
24
+ */
25
+ open?: boolean;
26
+
27
+ /**
28
+ * Whether the sheet can be dismissed by clicking the scrim
29
+ * @default true
30
+ */
31
+ dismissible?: boolean;
32
+
33
+ /**
34
+ * Whether to show a drag handle
35
+ * @default true
36
+ */
37
+ dragHandle?: boolean;
38
+
39
+ /**
40
+ * Content for the sheet
41
+ * @example '<div>Sheet content</div>'
42
+ */
43
+ content?: string;
44
+
45
+ /**
46
+ * Title for the sheet
47
+ * @example 'Sheet Title'
48
+ */
49
+ title?: string;
50
+
51
+ /**
52
+ * Additional CSS classes to add to the sheet
53
+ * @example 'custom-sheet settings-panel'
54
+ */
55
+ class?: string;
56
+
57
+ /**
58
+ * Component prefix for class names
59
+ * @default 'mtrl'
60
+ */
61
+ prefix?: string;
62
+
63
+ /**
64
+ * Component name used in class generation
65
+ */
66
+ componentName?: string;
67
+
68
+ /**
69
+ * Elevation level for the sheet (1-5)
70
+ * @default 3
71
+ */
72
+ elevation?: number;
73
+
74
+ /**
75
+ * Maximum height of the sheet (CSS value)
76
+ * @example '80%'
77
+ */
78
+ maxHeight?: string;
79
+
80
+ /**
81
+ * Whether to enable gesture-based interactions
82
+ * @default true
83
+ */
84
+ enableGestures?: boolean;
85
+
86
+ /**
87
+ * Callback when sheet is opened
88
+ */
89
+ onOpen?: () => void;
90
+
91
+ /**
92
+ * Callback when sheet is closed
93
+ */
94
+ onClose?: () => void;
95
+ }
96
+
97
+ /**
98
+ * Content API interface for managing sheet content
99
+ * @category Components
100
+ */
101
+ export interface ContentAPI {
102
+ /**
103
+ * Sets the content HTML
104
+ * @param html - HTML string for the content
105
+ * @returns The content API for chaining
106
+ */
107
+ setContent: (html: string) => ContentAPI;
108
+
109
+ /**
110
+ * Gets the current content HTML
111
+ * @returns HTML string for the content
112
+ */
113
+ getContent: () => string;
114
+
115
+ /**
116
+ * Gets the content DOM element
117
+ * @returns The content element or null if not present
118
+ */
119
+ getElement: () => HTMLElement | null;
120
+ }
121
+
122
+ /**
123
+ * Title API interface for managing sheet title
124
+ * @category Components
125
+ */
126
+ export interface TitleAPI {
127
+ /**
128
+ * Sets the title content
129
+ * @param text - Title text
130
+ * @returns The title API for chaining
131
+ */
132
+ setTitle: (text: string) => TitleAPI;
133
+
134
+ /**
135
+ * Gets the current title text
136
+ * @returns Sheet title text
137
+ */
138
+ getTitle: () => string;
139
+
140
+ /**
141
+ * Gets the title DOM element
142
+ * @returns The title element or null if not present
143
+ */
144
+ getElement: () => HTMLElement | null;
145
+ }
146
+
147
+ /**
148
+ * Sheet component interface
149
+ * @category Components
150
+ */
151
+ export interface SheetComponent {
152
+ /** The sheet's root DOM element */
153
+ element: HTMLElement;
154
+
155
+ /** The sheet's container DOM element */
156
+ container: HTMLElement;
157
+
158
+ /** API for managing sheet content */
159
+ content: ContentAPI;
160
+
161
+ /** API for managing sheet title */
162
+ title: TitleAPI;
163
+
164
+ /** API for managing sheet state */
165
+ state: {
166
+ /** Opens the sheet */
167
+ open: () => void;
168
+ /** Closes the sheet */
169
+ close: () => void;
170
+ /** Checks if the sheet is open */
171
+ isOpen: () => boolean;
172
+ };
173
+
174
+ /** API for managing component lifecycle */
175
+ lifecycle: {
176
+ /** Destroys the component and cleans up resources */
177
+ destroy: () => void;
178
+ };
179
+
180
+ /**
181
+ * Gets a class name with the component's prefix
182
+ * @param name - Base class name
183
+ * @returns Prefixed class name
184
+ */
185
+ getClass: (name: string) => string;
186
+
187
+ /**
188
+ * Opens the sheet
189
+ * @returns The sheet component for chaining
190
+ */
191
+ open: () => SheetComponent;
192
+
193
+ /**
194
+ * Closes the sheet
195
+ * @returns The sheet component for chaining
196
+ */
197
+ close: () => SheetComponent;
198
+
199
+ /**
200
+ * Sets the sheet content
201
+ * @param html - Content HTML
202
+ * @returns The sheet component for chaining
203
+ */
204
+ setContent: (html: string) => SheetComponent;
205
+
206
+ /**
207
+ * Gets the sheet content HTML
208
+ * @returns Content HTML
209
+ */
210
+ getContent: () => string;
211
+
212
+ /**
213
+ * Sets the sheet title
214
+ * @param text - Title text
215
+ * @returns The sheet component for chaining
216
+ */
217
+ setTitle: (text: string) => SheetComponent;
218
+
219
+ /**
220
+ * Gets the sheet title text
221
+ * @returns Title text
222
+ */
223
+ getTitle: () => string;
224
+
225
+ /**
226
+ * Enables or disables the drag handle
227
+ * @param enabled - Whether to show the drag handle
228
+ * @returns The sheet component for chaining
229
+ */
230
+ setDragHandle: (enabled: boolean) => SheetComponent;
231
+
232
+ /**
233
+ * Sets the maximum height of the sheet
234
+ * @param height - CSS value for max height
235
+ * @returns The sheet component for chaining
236
+ */
237
+ setMaxHeight: (height: string) => SheetComponent;
238
+
239
+ /**
240
+ * Destroys the sheet component and cleans up resources
241
+ */
242
+ destroy: () => void;
243
+
244
+ /**
245
+ * Adds an event listener to the sheet
246
+ * @param event - Event name ('open', 'close', etc.)
247
+ * @param handler - Event handler function
248
+ * @returns The sheet component for chaining
249
+ */
250
+ on: (event: string, handler: Function) => SheetComponent;
251
+
252
+ /**
253
+ * Removes an event listener from the sheet
254
+ * @param event - Event name
255
+ * @param handler - Event handler function
256
+ * @returns The sheet component for chaining
257
+ */
258
+ off: (event: string, handler: Function) => SheetComponent;
259
+
260
+ /**
261
+ * Adds CSS classes to the sheet element
262
+ * @param classes - One or more class names to add
263
+ * @returns The sheet component for chaining
264
+ */
265
+ addClass: (...classes: string[]) => SheetComponent;
266
+ }