mtrl 0.3.5 → 0.3.7

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 (65) hide show
  1. package/package.json +1 -1
  2. package/src/components/button/api.ts +16 -0
  3. package/src/components/button/types.ts +9 -0
  4. package/src/components/menu/api.ts +144 -267
  5. package/src/components/menu/config.ts +84 -40
  6. package/src/components/menu/features/anchor.ts +243 -0
  7. package/src/components/menu/features/controller.ts +1167 -0
  8. package/src/components/menu/features/index.ts +5 -0
  9. package/src/components/menu/features/position.ts +353 -0
  10. package/src/components/menu/index.ts +31 -63
  11. package/src/components/menu/menu.ts +72 -104
  12. package/src/components/menu/types.ts +264 -447
  13. package/src/components/select/api.ts +78 -0
  14. package/src/components/select/config.ts +76 -0
  15. package/src/components/select/features.ts +317 -0
  16. package/src/components/select/index.ts +38 -0
  17. package/src/components/select/select.ts +73 -0
  18. package/src/components/select/types.ts +355 -0
  19. package/src/components/textfield/api.ts +78 -6
  20. package/src/components/textfield/features/index.ts +17 -0
  21. package/src/components/textfield/features/leading-icon.ts +127 -0
  22. package/src/components/textfield/features/placement.ts +149 -0
  23. package/src/components/textfield/features/prefix-text.ts +107 -0
  24. package/src/components/textfield/features/suffix-text.ts +100 -0
  25. package/src/components/textfield/features/supporting-text.ts +113 -0
  26. package/src/components/textfield/features/trailing-icon.ts +108 -0
  27. package/src/components/textfield/textfield.ts +51 -15
  28. package/src/components/textfield/types.ts +70 -0
  29. package/src/core/collection/adapters/base.ts +62 -0
  30. package/src/core/collection/collection.ts +300 -0
  31. package/src/core/collection/index.ts +57 -0
  32. package/src/core/collection/list-manager.ts +333 -0
  33. package/src/core/dom/classes.ts +81 -9
  34. package/src/core/dom/create.ts +30 -19
  35. package/src/core/layout/README.md +531 -166
  36. package/src/core/layout/array.ts +3 -4
  37. package/src/core/layout/config.ts +193 -0
  38. package/src/core/layout/create.ts +1 -2
  39. package/src/core/layout/index.ts +12 -2
  40. package/src/core/layout/object.ts +2 -3
  41. package/src/core/layout/processor.ts +60 -12
  42. package/src/core/layout/result.ts +1 -2
  43. package/src/core/layout/types.ts +105 -50
  44. package/src/core/layout/utils.ts +69 -61
  45. package/src/index.ts +6 -2
  46. package/src/styles/abstract/_variables.scss +18 -0
  47. package/src/styles/components/_button.scss +21 -5
  48. package/src/styles/components/{_chip.scss → _chips.scss} +118 -4
  49. package/src/styles/components/_menu.scss +109 -18
  50. package/src/styles/components/_select.scss +265 -0
  51. package/src/styles/components/_textfield.scss +233 -42
  52. package/src/styles/main.scss +24 -23
  53. package/src/styles/utilities/_layout.scss +665 -0
  54. package/src/components/menu/features/items-manager.ts +0 -457
  55. package/src/components/menu/features/keyboard-navigation.ts +0 -133
  56. package/src/components/menu/features/positioning.ts +0 -127
  57. package/src/components/menu/features/visibility.ts +0 -230
  58. package/src/components/menu/menu-item.ts +0 -86
  59. package/src/components/menu/utils.ts +0 -67
  60. package/src/components/textfield/features.ts +0 -322
  61. package/src/core/collection/adapters/base.js +0 -26
  62. package/src/core/collection/collection.js +0 -259
  63. package/src/core/collection/list-manager.js +0 -157
  64. /package/src/core/collection/adapters/{route.js → route.ts} +0 -0
  65. /package/src/{core/build → styles/utilities}/_ripple.scss +0 -0
@@ -1,15 +1,15 @@
1
1
  // src/core/layout/utils.ts
2
2
  /**
3
3
  * @module core/layout
4
- * @description Optimized utility functions for layout creation
4
+ * @description Utility functions for layout creation
5
5
  */
6
6
 
7
7
  import { PREFIX } from '../config';
8
8
  import { ComponentLike } from './types';
9
+ import { normalizeClasses as normalizeClassesUtil } from '../utils';
9
10
 
10
11
  /**
11
12
  * Checks if a value is a component object (has an element property)
12
- * Optimized fast path check by only validating that element property exists
13
13
  *
14
14
  * @param value - Value to check
15
15
  * @returns True if the value is a component-like object
@@ -29,9 +29,18 @@ export function createFragment(): DocumentFragment {
29
29
  return document.createDocumentFragment();
30
30
  }
31
31
 
32
+ /**
33
+ * Normalizes class values into an array of strings
34
+ */
35
+ export function normalizeClasses(...classes: (string | string[])[]): string[] {
36
+ return normalizeClassesUtil(...classes);
37
+ }
38
+
39
+ // Constant for prefix with dash
40
+ const PREFIX_WITH_DASH = `${PREFIX}-`;
41
+
32
42
  /**
33
43
  * Processes className options to add prefix if needed
34
- * Supports BEM naming conventions when enabled
35
44
  *
36
45
  * @param options - Element options
37
46
  * @param skipPrefix - Whether to skip adding prefixes
@@ -43,76 +52,73 @@ export function processClassNames(
43
52
  skipPrefix: boolean = false,
44
53
  useBEM: boolean = false
45
54
  ): Record<string, any> {
46
- // Fast path - if no options or skipping prefix, return as is
55
+ // Fast path - if no options or skipping prefix, return a new object
47
56
  if (!options || skipPrefix) return { ...options };
48
57
 
49
- // Clone options to avoid mutating the original
58
+ // Avoid unnecessary clone if no class properties exist
59
+ const hasClassProps = options.class || options.className || options.rawClass;
60
+ if (!hasClassProps) return { ...options };
61
+
62
+ // Create clone only once
50
63
  const processed = { ...options };
51
64
 
52
- /**
53
- * Processes a single class name with optional BEM handling
54
- *
55
- * @param cls - Class name to process
56
- * @returns Processed class name with prefix
57
- */
58
- const processClass = (cls: string): string => {
59
- // Already prefixed - leave it as is
60
- if (cls.startsWith(`${PREFIX}-`)) {
61
- return cls;
65
+ // Unify class and className as aliases
66
+ if (processed.className) {
67
+ if (!processed.class) {
68
+ // Simple transfer if only className exists
69
+ processed.class = processed.className;
70
+ } else {
71
+ // Merge if both exist
72
+ const classNames = normalizeClasses([processed.class, processed.className]);
73
+ processed.class = classNames.join(' ');
62
74
  }
63
-
64
- if (useBEM) {
65
- // For BEM classes (with __ or --), only prefix the block part
66
- if (cls.includes('__')) {
67
- // This is a BEM element, prefix only the block part
68
- const [block, element] = cls.split('__');
69
- return `${PREFIX}-${block}__${element}`;
70
- } else if (cls.includes('--')) {
71
- // This is a BEM modifier, prefix only the block part
72
- const [block, modifier] = cls.split('--');
73
- return `${PREFIX}-${block}--${modifier}`;
74
- }
75
- }
76
-
77
- // Standard case - prefix the entire class name
78
- return `${PREFIX}-${cls}`;
79
- };
75
+ // Always remove className after processing
76
+ delete processed.className;
77
+ }
80
78
 
81
- /**
82
- * Process a class property (either 'class' or 'className')
83
- *
84
- * @param prop - Property name to process
85
- */
86
- const processProperty = (prop: string): void => {
87
- if (!processed[prop]) return;
88
-
89
- // Handle string class names
90
- if (typeof processed[prop] === 'string') {
91
- processed[prop] = processed[prop]
92
- .split(' ')
93
- .map(cls => cls ? processClass(cls) : '')
94
- .filter(Boolean)
95
- .join(' ');
96
- }
97
- // Handle array class names
98
- else if (Array.isArray(processed[prop])) {
99
- processed[prop] = processed[prop]
100
- .map(cls => typeof cls === 'string' ? processClass(cls) : cls)
79
+ // Process prefixed classes
80
+ if (processed.class && !skipPrefix) {
81
+ // Handle string format
82
+ if (typeof processed.class === 'string') {
83
+ const classes = processed.class.split(/\s+/).filter(Boolean);
84
+
85
+ if (useBEM) {
86
+ // Handle BEM notation with special prefixing rules
87
+ processed.class = classes.map(cls => {
88
+ if (!cls || cls.startsWith(PREFIX_WITH_DASH)) return cls;
89
+
90
+ if (cls.includes('__')) {
91
+ const [block, element] = cls.split('__');
92
+ return `${PREFIX_WITH_DASH}${block}__${element}`;
93
+ } else if (cls.includes('--')) {
94
+ const [block, modifier] = cls.split('--');
95
+ return `${PREFIX_WITH_DASH}${block}--${modifier}`;
96
+ }
97
+
98
+ return `${PREFIX_WITH_DASH}${cls}`;
99
+ }).join(' ');
100
+ } else {
101
+ // Standard prefix handling
102
+ processed.class = classes.map(cls =>
103
+ cls && !cls.startsWith(PREFIX_WITH_DASH) ? `${PREFIX_WITH_DASH}${cls}` : cls
104
+ ).filter(Boolean).join(' ');
105
+ }
106
+ }
107
+ // Handle array format
108
+ else if (Array.isArray(processed.class)) {
109
+ processed.class = processed.class
101
110
  .filter(Boolean)
111
+ .map(cls => typeof cls === 'string' && !cls.startsWith(PREFIX_WITH_DASH) ?
112
+ `${PREFIX_WITH_DASH}${cls}` : cls)
102
113
  .join(' ');
103
114
  }
104
- };
105
-
106
- // Process both possible class properties for compatibility
107
- processProperty('class');
108
- processProperty('className');
115
+ }
109
116
 
110
117
  return processed;
111
118
  }
112
119
 
113
120
  /**
114
121
  * Flattens a nested layout into a simple object with element and component references
115
- * Optimized by using a direct property access loop and early exits
116
122
  *
117
123
  * @param layout - Layout object
118
124
  * @returns Flattened layout with all elements and components
@@ -120,17 +126,19 @@ export function processClassNames(
120
126
  export function flattenLayout(layout: Record<string, any>): Record<string, any> {
121
127
  const flattened: Record<string, any> = {};
122
128
 
129
+ // Fast path - return empty object for empty layout
130
+ if (!layout || typeof layout !== 'object') return flattened;
131
+
123
132
  for (const key in layout) {
124
133
  const value = layout[key];
125
134
 
126
135
  // Only include components, elements, and non-functions
127
- // Fast path with fewer type checks
128
136
  if (value &&
129
137
  typeof value !== 'function' &&
130
- (value instanceof HTMLElement || 'element' in value)) {
138
+ (value instanceof HTMLElement || isComponent(value))) {
131
139
  flattened[key] = value;
132
140
  }
133
141
  }
134
142
 
135
143
  return flattened;
136
- }
144
+ }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  // Direct component imports
9
- import { createElement } from './core/dom/create';
9
+ import { createElement, addClass, removeClass, hasClass, toggleClass } from './core/dom';
10
10
  import createLayout from './core/layout';
11
11
  import createBadge from './components/badge';
12
12
  import createBottomAppBar from './components/bottom-app-bar';
@@ -36,6 +36,7 @@ import createSegmentedButton, { createSegment } from './components/segmented-but
36
36
  import createSheet from './components/sheet';
37
37
  import createSlider from './components/slider';
38
38
  import createSnackbar from './components/snackbar';
39
+ import createSelect from './components/select';
39
40
  import createSwitch from './components/switch';
40
41
  import createTabs, { createTab } from './components/tabs';
41
42
  import createTextfield from './components/textfield';
@@ -45,6 +46,7 @@ import createTooltip from './components/tooltip';
45
46
 
46
47
  // Export all "create*" functions
47
48
  export {
49
+ addClass, removeClass, hasClass, toggleClass,
48
50
  createElement,
49
51
  createLayout,
50
52
  createBadge,
@@ -58,7 +60,7 @@ export {
58
60
  createCarousel,
59
61
  createCheckbox,
60
62
  createChip,
61
- createChipSet,
63
+ createChips,
62
64
  createDatePicker,
63
65
  createDialog,
64
66
  createDivider,
@@ -72,6 +74,7 @@ export {
72
74
  createProgress,
73
75
  createRadios,
74
76
  createSearch,
77
+ createSelect,
75
78
  createSegmentedButton,
76
79
  createSegment,
77
80
  createSheet,
@@ -115,6 +118,7 @@ export {
115
118
  createProgress as fProgress,
116
119
  createRadios as fRadios,
117
120
  createSearch as fSearch,
121
+ createSelect as fSelect,
118
122
  createSegmentedButton as fSegmentedButton,
119
123
  createSegment as fSegment,
120
124
  createSheet as fSheet,
@@ -284,4 +284,22 @@ $spacing-scale: (
284
284
  @return map.get($chip-config, $key);
285
285
  }
286
286
  @return $fallback;
287
+ }
288
+
289
+ // Textfield configuration
290
+ $textfield: (
291
+ 'height': 56px,
292
+ 'height-small': 48px,
293
+ 'height-large': 64px,
294
+ 'padding-horizontal': 16px,
295
+ 'padding-vertical': 16px,
296
+ 'border-radius': map.get($shape, 'extra-small'),
297
+ 'border-width': 1px,
298
+ 'label-offset': 16px,
299
+ 'icon-size': 24px
300
+ ) !default;
301
+
302
+ // Add textfield function
303
+ @function textfield($key) {
304
+ @return map.get($textfield, $key);
287
305
  }
@@ -106,6 +106,17 @@ $component: '#{base.$prefix}-button';
106
106
  opacity: 0.38
107
107
  }
108
108
 
109
+ // Active state - applied when the button has a menu open
110
+ &--active {
111
+ // Common active state styling for all variants
112
+ box-shadow: none;
113
+
114
+ // ARIA attribute to indicate active state for accessibility
115
+ &[aria-expanded="true"] {
116
+ // For compatibility with ARIA
117
+ }
118
+ }
119
+
109
120
  // Variants
110
121
  &--filled {
111
122
  background-color: t.color('primary');
@@ -116,7 +127,8 @@ $component: '#{base.$prefix}-button';
116
127
  @include m.elevation(1);
117
128
  }
118
129
 
119
- &:active {
130
+ &:active,
131
+ &.#{$component}--active {
120
132
  @include m.state-layer(t.color('on-primary'), 'pressed');
121
133
  @include m.elevation(0);
122
134
  }
@@ -133,7 +145,8 @@ $component: '#{base.$prefix}-button';
133
145
  @include m.elevation(2);
134
146
  }
135
147
 
136
- &:active {
148
+ &:active,
149
+ &.#{$component}--active {
137
150
  @include m.state-layer(t.color('primary'), 'pressed');
138
151
  @include m.elevation(1);
139
152
  }
@@ -160,7 +173,8 @@ $component: '#{base.$prefix}-button';
160
173
  @include m.elevation(1);
161
174
  }
162
175
 
163
- &:active {
176
+ &:active,
177
+ &.#{$component}--active {
164
178
  @include m.state-layer(t.color('on-secondary-container'), 'pressed');
165
179
  @include m.elevation(0);
166
180
  }
@@ -175,7 +189,8 @@ $component: '#{base.$prefix}-button';
175
189
  background-color: t.alpha('primary', 0.08);
176
190
  }
177
191
 
178
- &:active {
192
+ &:active,
193
+ &.#{$component}--active {
179
194
  @include m.state-layer(t.color('primary'), 'pressed');
180
195
  }
181
196
  }
@@ -189,7 +204,8 @@ $component: '#{base.$prefix}-button';
189
204
  background-color: t.alpha('primary', 0.08);
190
205
  }
191
206
 
192
- &:active {
207
+ &:active,
208
+ &.#{$component}--active {
193
209
  background-color: t.alpha('primary', 0.12);
194
210
  }
195
211
 
@@ -44,6 +44,17 @@ $container: '#{base.$prefix}-chips';
44
44
  outline-offset: 2px;
45
45
  }
46
46
 
47
+ // Active state - applied when the chip has a menu open
48
+ &--active {
49
+ // Base active state styling
50
+ // Will use variant-specific implementations below
51
+
52
+ // ARIA attribute to indicate active state for accessibility
53
+ &[aria-expanded="true"] {
54
+ // For compatibility with ARIA
55
+ }
56
+ }
57
+
47
58
  // Disabled state
48
59
  &--disabled {
49
60
  opacity: 0.38;
@@ -127,7 +138,8 @@ $container: '#{base.$prefix}-chips';
127
138
  border-radius: v.chip('border-radius');
128
139
  }
129
140
 
130
- &:active::after {
141
+ &:active::after,
142
+ &.#{$component}--active::after {
131
143
  content: '';
132
144
  position: absolute;
133
145
  inset: 0;
@@ -151,7 +163,8 @@ $container: '#{base.$prefix}-chips';
151
163
  border-radius: inherit;
152
164
  }
153
165
 
154
- &:active::after {
166
+ &:active::after,
167
+ &.#{$component}--active::after {
155
168
  content: '';
156
169
  position: absolute;
157
170
  inset: 0;
@@ -182,7 +195,8 @@ $container: '#{base.$prefix}-chips';
182
195
  border-color: t.alpha('outline', v.chip('outlined-border-focus-opacity'));
183
196
  }
184
197
 
185
- &:active::after {
198
+ &:active::after,
199
+ &.#{$component}--active::after {
186
200
  content: '';
187
201
  position: absolute;
188
202
  inset: 0;
@@ -206,6 +220,17 @@ $container: '#{base.$prefix}-chips';
206
220
  pointer-events: none;
207
221
  border-radius: inherit;
208
222
  }
223
+
224
+ &:active::after,
225
+ &.#{$component}--active::after {
226
+ content: '';
227
+ position: absolute;
228
+ inset: 0;
229
+ background-color: t.color('on-secondary-container');
230
+ opacity: 0.12;
231
+ pointer-events: none;
232
+ border-radius: inherit;
233
+ }
209
234
  }
210
235
  }
211
236
 
@@ -225,7 +250,8 @@ $container: '#{base.$prefix}-chips';
225
250
  border-radius: inherit;
226
251
  }
227
252
 
228
- &:active::after {
253
+ &:active::after,
254
+ &.#{$component}--active::after {
229
255
  content: '';
230
256
  position: absolute;
231
257
  inset: 0;
@@ -248,6 +274,17 @@ $container: '#{base.$prefix}-chips';
248
274
  pointer-events: none;
249
275
  border-radius: inherit;
250
276
  }
277
+
278
+ &:active::after,
279
+ &.#{$component}--active::after {
280
+ content: '';
281
+ position: absolute;
282
+ inset: 0;
283
+ background-color: t.color('on-secondary-container');
284
+ opacity: 0.12;
285
+ pointer-events: none;
286
+ border-radius: inherit;
287
+ }
251
288
  }
252
289
  }
253
290
 
@@ -268,6 +305,17 @@ $container: '#{base.$prefix}-chips';
268
305
  border-radius: calc(v.chip('border-radius') - 1px);
269
306
  }
270
307
 
308
+ &:active::after,
309
+ &.#{$component}--active::after {
310
+ content: '';
311
+ position: absolute;
312
+ inset: 0;
313
+ background-color: t.color('on-surface');
314
+ opacity: 0.12;
315
+ pointer-events: none;
316
+ border-radius: calc(v.chip('border-radius') - 1px);
317
+ }
318
+
271
319
  &.#{$component}--selected {
272
320
 
273
321
  padding-left: 8px;
@@ -310,6 +358,17 @@ $container: '#{base.$prefix}-chips';
310
358
  pointer-events: none;
311
359
  border-radius: calc(v.chip('border-radius') - 1px);
312
360
  }
361
+
362
+ &:active::after,
363
+ &.#{$component}--active::after {
364
+ content: '';
365
+ position: absolute;
366
+ inset: 0;
367
+ background-color: t.color('on-secondary-container');
368
+ opacity: 0.12;
369
+ pointer-events: none;
370
+ border-radius: calc(v.chip('border-radius') - 1px);
371
+ }
313
372
  }
314
373
  }
315
374
 
@@ -332,6 +391,17 @@ $container: '#{base.$prefix}-chips';
332
391
  border-radius: v.chip('border-radius');
333
392
  }
334
393
 
394
+ &:active::after,
395
+ &.#{$component}--active::after {
396
+ content: '';
397
+ position: absolute;
398
+ inset: 0;
399
+ background-color: t.color('on-surface');
400
+ opacity: 0.12;
401
+ pointer-events: none;
402
+ border-radius: v.chip('border-radius');
403
+ }
404
+
335
405
  &.#{$component}--selected {
336
406
  background-color: t.color('secondary-container');
337
407
  color: t.color('on-secondary-container');
@@ -349,6 +419,17 @@ $container: '#{base.$prefix}-chips';
349
419
  pointer-events: none;
350
420
  border-radius: inherit;
351
421
  }
422
+
423
+ &:active::after,
424
+ &.#{$component}--active::after {
425
+ content: '';
426
+ position: absolute;
427
+ inset: 0;
428
+ background-color: t.color('on-secondary-container');
429
+ opacity: 0.12;
430
+ pointer-events: none;
431
+ border-radius: inherit;
432
+ }
352
433
  }
353
434
  }
354
435
 
@@ -375,6 +456,17 @@ $container: '#{base.$prefix}-chips';
375
456
  pointer-events: none;
376
457
  border-radius: inherit;
377
458
  }
459
+
460
+ &:active::after,
461
+ &.#{$component}--active::after {
462
+ content: '';
463
+ position: absolute;
464
+ inset: 0;
465
+ background-color: t.color('on-surface');
466
+ opacity: 0.12;
467
+ pointer-events: none;
468
+ border-radius: inherit;
469
+ }
378
470
  }
379
471
 
380
472
  // Suggestion chip
@@ -403,6 +495,17 @@ $container: '#{base.$prefix}-chips';
403
495
  border-radius: inherit;
404
496
  }
405
497
 
498
+ &:active::after,
499
+ &.#{$component}--active::after {
500
+ content: '';
501
+ position: absolute;
502
+ inset: 0;
503
+ background-color: t.color('on-surface');
504
+ opacity: 0.12;
505
+ pointer-events: none;
506
+ border-radius: inherit;
507
+ }
508
+
406
509
  &.#{$component}--selected {
407
510
  background-color: t.color('secondary-container');
408
511
  color: t.color('on-secondary-container');
@@ -416,6 +519,17 @@ $container: '#{base.$prefix}-chips';
416
519
  pointer-events: none;
417
520
  border-radius: inherit;
418
521
  }
522
+
523
+ &:active::after,
524
+ &.#{$component}--active::after {
525
+ content: '';
526
+ position: absolute;
527
+ inset: 0;
528
+ background-color: t.color('on-secondary-container');
529
+ opacity: 0.12;
530
+ pointer-events: none;
531
+ border-radius: inherit;
532
+ }
419
533
  }
420
534
  }
421
535
  }