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.
Files changed (140) hide show
  1. package/.env +15 -0
  2. package/CONTRIBUTING.md +8 -8
  3. package/DOCS.md +3 -3
  4. package/README.md +43 -20
  5. package/TESTING.md +128 -18
  6. package/dist/index.js +14865 -0
  7. package/git-user-stats.js +545 -0
  8. package/index.ts +9 -69
  9. package/package.json +10 -3
  10. package/src/components/badge/api.ts +15 -1
  11. package/src/components/badge/badge.ts +43 -4
  12. package/src/components/badge/config.ts +40 -8
  13. package/src/components/badge/index.ts +64 -3
  14. package/src/components/badge/types.ts +175 -33
  15. package/src/components/button/api.ts +63 -1
  16. package/src/components/button/button.ts +39 -3
  17. package/src/components/button/config.ts +21 -4
  18. package/src/components/button/index.ts +26 -1
  19. package/src/components/button/types.ts +7 -1
  20. package/src/components/card/api.ts +78 -9
  21. package/src/components/card/card.ts +58 -3
  22. package/src/components/card/config.ts +41 -11
  23. package/src/components/card/features.ts +39 -12
  24. package/src/components/card/index.ts +84 -19
  25. package/src/components/card/types.ts +218 -29
  26. package/src/components/carousel/carousel.ts +92 -28
  27. package/src/components/carousel/constants.ts +107 -21
  28. package/src/components/carousel/index.ts +31 -13
  29. package/src/components/checkbox/checkbox.ts +83 -16
  30. package/src/components/checkbox/index.ts +43 -1
  31. package/src/components/checkbox/types.ts +219 -32
  32. package/src/components/chips/api.ts +194 -0
  33. package/src/components/{chip → chips/chip}/api.ts +42 -2
  34. package/src/components/chips/chip/chip.ts +131 -0
  35. package/src/components/{chip → chips/chip}/config.ts +3 -3
  36. package/src/components/chips/chip/index.ts +3 -0
  37. package/src/components/chips/chips.md +481 -0
  38. package/src/components/chips/chips.ts +75 -0
  39. package/src/components/chips/config.ts +109 -0
  40. package/src/components/chips/constants.ts +61 -0
  41. package/src/components/chips/features/chip-items.ts +33 -0
  42. package/src/components/chips/features/container.ts +77 -0
  43. package/src/components/chips/features/controller.ts +448 -0
  44. package/src/components/chips/features/index.ts +5 -0
  45. package/src/components/chips/features/label.ts +108 -0
  46. package/src/components/chips/index.ts +11 -0
  47. package/src/components/chips/schema.ts +61 -0
  48. package/src/components/{chip → chips}/types.ts +203 -92
  49. package/src/components/dialog/dialog.ts +99 -16
  50. package/src/components/dialog/index.ts +97 -1
  51. package/src/components/dialog/types.ts +375 -69
  52. package/src/components/divider/config.ts +90 -6
  53. package/src/components/divider/divider.ts +32 -2
  54. package/src/components/divider/features.ts +26 -0
  55. package/src/components/divider/index.ts +30 -0
  56. package/src/components/divider/types.ts +86 -9
  57. package/src/components/extended-fab/api.ts +53 -1
  58. package/src/components/extended-fab/config.ts +29 -1
  59. package/src/components/extended-fab/extended-fab.ts +28 -0
  60. package/src/components/extended-fab/index.ts +36 -0
  61. package/src/components/extended-fab/types.ts +458 -13
  62. package/src/components/fab/api.ts +42 -2
  63. package/src/components/fab/config.ts +29 -1
  64. package/src/components/fab/fab.ts +16 -2
  65. package/src/components/fab/index.ts +35 -0
  66. package/src/components/fab/types.ts +374 -10
  67. package/src/components/list/api.ts +12 -2
  68. package/src/components/list/config.ts +21 -0
  69. package/src/components/list/features.ts +6 -0
  70. package/src/components/list/index.ts +56 -1
  71. package/src/components/list/list-item.ts +46 -2
  72. package/src/components/list/list.ts +73 -2
  73. package/src/components/list/types.ts +172 -0
  74. package/src/components/list/utils.ts +26 -2
  75. package/src/components/menu/api.ts +217 -20
  76. package/src/components/menu/config.ts +27 -0
  77. package/src/components/menu/features/visibility.ts +55 -6
  78. package/src/components/menu/index.ts +64 -0
  79. package/src/components/menu/menu-item.ts +46 -3
  80. package/src/components/menu/menu.ts +77 -1
  81. package/src/components/menu/types.ts +404 -39
  82. package/src/components/navigation/index.ts +4 -1
  83. package/src/components/navigation/types.ts +33 -0
  84. package/src/components/sheet/config.ts +1 -2
  85. package/src/components/sheet/features/gestures.ts +1 -1
  86. package/src/components/sheet/features/position.ts +1 -2
  87. package/src/components/sheet/features/state.ts +1 -1
  88. package/src/components/sheet/index.ts +10 -2
  89. package/src/components/sheet/sheet.ts +1 -2
  90. package/src/components/sheet/types.ts +29 -1
  91. package/src/components/slider/api.ts +1 -1
  92. package/src/components/slider/config.ts +1 -1
  93. package/src/components/slider/features/controller.ts +1 -1
  94. package/src/components/slider/features/handlers.ts +1 -1
  95. package/src/components/slider/features/states.ts +1 -1
  96. package/src/components/slider/index.ts +12 -5
  97. package/src/components/slider/schema.ts +1 -1
  98. package/src/components/slider/types.ts +31 -0
  99. package/src/components/snackbar/index.ts +7 -1
  100. package/src/components/snackbar/types.ts +25 -0
  101. package/src/components/switch/index.ts +5 -1
  102. package/src/components/switch/types.ts +13 -0
  103. package/src/components/tabs/tab-api.ts +1 -1
  104. package/src/components/tabs/types.ts +1 -1
  105. package/src/components/textfield/index.ts +7 -1
  106. package/src/components/textfield/types.ts +36 -0
  107. package/src/components/tooltip/api.ts +6 -2
  108. package/src/components/tooltip/config.ts +9 -28
  109. package/src/components/tooltip/index.ts +10 -1
  110. package/src/components/tooltip/types.ts +38 -3
  111. package/src/index.ts +129 -31
  112. package/src/styles/abstract/_mixins.scss +23 -9
  113. package/src/styles/abstract/_variables.scss +14 -4
  114. package/src/styles/components/_card.scss +1 -1
  115. package/src/styles/components/_chip.scss +323 -113
  116. package/src/styles/components/_tabs.scss +1 -1
  117. package/src/components/checkbox/constants.ts +0 -37
  118. package/src/components/chip/chip-set.ts +0 -225
  119. package/src/components/chip/chip.ts +0 -118
  120. package/src/components/chip/constants.ts +0 -28
  121. package/src/components/chip/index.ts +0 -12
  122. package/src/components/list/constants.ts +0 -116
  123. package/src/components/sheet/constants.ts +0 -20
  124. package/src/components/slider/constants.ts +0 -32
  125. package/src/components/snackbar/constants.ts +0 -26
  126. package/src/components/tooltip/constants.ts +0 -27
  127. package/test/components/button.test.js +0 -170
  128. package/test/components/checkbox.test.js +0 -238
  129. package/test/components/list.test.js +0 -105
  130. package/test/components/menu.test.js +0 -385
  131. package/test/components/navigation.test.js +0 -227
  132. package/test/components/snackbar.test.js +0 -234
  133. package/test/components/switch.test.js +0 -186
  134. package/test/components/textfield.test.js +0 -314
  135. package/test/core/emitter.test.js +0 -141
  136. package/test/core/ripple.test.js +0 -66
  137. package/test/setup.js +0 -371
  138. package/tsconfig.json +0 -22
  139. package/typedoc.json +0 -28
  140. package/typedoc.simple.json +0 -14
@@ -0,0 +1,109 @@
1
+ // src/components/chips/config.ts
2
+ import {
3
+ createComponentConfig,
4
+ createElementConfig
5
+ } from '../../core/config/component-config';
6
+ import { ChipsConfig } from './types';
7
+ import { createChipsSchema } from './schema';
8
+
9
+ /**
10
+ * Default configuration for the Chips component
11
+ */
12
+ export const defaultConfig: ChipsConfig = {
13
+ chips: [],
14
+ scrollable: false,
15
+ vertical: false,
16
+ multiSelect: false,
17
+ onChange: null,
18
+ selector: null,
19
+ labelPosition: 'start'
20
+ };
21
+
22
+ /**
23
+ * Creates the base configuration for Chips component
24
+ * @param {ChipsConfig} config - User provided configuration
25
+ * @returns {ChipsConfig} Complete configuration with defaults applied
26
+ */
27
+ export const createBaseConfig = (config: ChipsConfig = {}): ChipsConfig => {
28
+ // Create the base config with defaults applied
29
+ const baseConfig = createComponentConfig(defaultConfig, config, 'chips') as ChipsConfig;
30
+
31
+ // Create a basic component object for structure generation
32
+ const baseComponent = {
33
+ componentName: 'chips',
34
+ config: baseConfig,
35
+ getClass: (className) => {
36
+ const prefix = baseConfig.prefix || 'mtrl';
37
+ return className ? `${prefix}-${className}` : prefix;
38
+ }
39
+ };
40
+
41
+ // Add the structure definition to the config
42
+ baseConfig.schema = createChipsSchema(baseComponent, baseConfig);
43
+
44
+ return baseConfig;
45
+ };
46
+
47
+ /**
48
+ * Generates element configuration for the Chips component
49
+ * @param {ChipsConfig} config - Chips configuration
50
+ * @returns {Object} Element configuration object for withElement
51
+ */
52
+ export const getElementConfig = (config: ChipsConfig) =>
53
+ createElementConfig(config, {
54
+ tag: 'div',
55
+ attrs: {
56
+ tabindex: '0',
57
+ role: 'group',
58
+ 'aria-multiselectable': config.multiSelect === true ? 'true' : 'false'
59
+ },
60
+ className: [
61
+ config.class
62
+ ].filter(Boolean)
63
+ });
64
+
65
+ /**
66
+ * Creates API configuration for the Chips component
67
+ * @param {Object} comp - Component with chips features
68
+ * @returns {Object} API configuration object
69
+ */
70
+ export const getApiConfig = (comp) => ({
71
+ chips: {
72
+ addChip: function(chipConfig) {
73
+ if (comp.chips && typeof comp.chips.addChip === 'function') {
74
+ return comp.chips.addChip(chipConfig);
75
+ }
76
+ return null;
77
+ },
78
+ removeChip: (chipOrIndex) => comp.chips?.removeChip?.(chipOrIndex),
79
+ getChips: () => comp.chips?.getChips?.() ?? [],
80
+ getSelectedChips: () => comp.chips?.getSelectedChips?.() ?? [],
81
+ getSelectedValues: () => comp.chips?.getSelectedValues?.() ?? [],
82
+ selectByValue: (values) => comp.chips?.selectByValue?.(values),
83
+ clearSelection: () => comp.chips?.clearSelection?.(),
84
+ scrollToChip: (chipOrIndex) => comp.chips?.scrollToChip?.(chipOrIndex)
85
+ },
86
+ layout: {
87
+ setScrollable: (isScrollable) => comp.layout?.setScrollable?.(isScrollable),
88
+ isScrollable: () => comp.layout?.isScrollable?.() ?? false,
89
+ setVertical: (isVertical) => comp.layout?.setVertical?.(isVertical),
90
+ isVertical: () => comp.layout?.isVertical?.() ?? false
91
+ },
92
+ label: {
93
+ setText: (t) => comp.label?.setText?.(t),
94
+ getText: () => comp.label?.getText?.() ?? '',
95
+ setPosition: (p) => comp.label?.setPosition?.(p),
96
+ getPosition: () => comp.label?.getPosition?.() ?? 'start'
97
+ },
98
+ keyboard: {
99
+ enableKeyboardNavigation: () => comp.keyboard?.enable?.(),
100
+ disableKeyboardNavigation: () => comp.keyboard?.disable?.()
101
+ },
102
+ events: {
103
+ on: (e, h) => comp.on?.(e, h),
104
+ off: (e, h) => comp.off?.(e, h)
105
+ },
106
+ lifecycle: {
107
+ destroy: () => comp.lifecycle?.destroy?.()
108
+ }
109
+ });
@@ -0,0 +1,61 @@
1
+ // src/components/chips/constants.ts
2
+
3
+ /**
4
+ * Available variants for the Chip component
5
+ * @enum {string}
6
+ */
7
+ export const CHIP_VARIANTS = {
8
+ /** Standard filled chip with solid background */
9
+ FILLED: 'filled',
10
+
11
+ /** Outlined chip with transparent background and border */
12
+ OUTLINED: 'outlined',
13
+
14
+ /** Elevated chip with shadow */
15
+ ELEVATED: 'elevated',
16
+
17
+ /** Assist chip for suggesting actions */
18
+ ASSIST: 'assist',
19
+
20
+ /** Filter chip for filtering content */
21
+ FILTER: 'filter',
22
+
23
+ /** Input chip for representing user input */
24
+ INPUT: 'input',
25
+
26
+ /** Suggestion chip for presenting options */
27
+ SUGGESTION: 'suggestion'
28
+ };
29
+
30
+ /**
31
+ * Available event types for Chip component
32
+ * @enum {string}
33
+ */
34
+ export const CHIP_EVENTS = {
35
+ /** Fired when chip selection state changes */
36
+ CHANGE: 'change',
37
+
38
+ /** Fired when chip is selected */
39
+ SELECT: 'select',
40
+
41
+ /** Fired when chip is deselected */
42
+ DESELECT: 'deselect',
43
+
44
+ /** Fired when chip is about to be removed */
45
+ REMOVE: 'remove'
46
+ };
47
+
48
+ /**
49
+ * Available event types for Chips container component
50
+ * @enum {string}
51
+ */
52
+ export const CHIPS_EVENTS = {
53
+ /** Fired when any chip selection changes */
54
+ CHANGE: 'change',
55
+
56
+ /** Fired when a chip is added to the container */
57
+ ADD: 'add',
58
+
59
+ /** Fired when a chip is removed from the container */
60
+ REMOVE: 'remove'
61
+ };
@@ -0,0 +1,33 @@
1
+ // src/components/chips/features/chip-items.ts
2
+ import { ChipsConfig } from '../types';
3
+ import createChip from '../chip/chip';
4
+
5
+ /**
6
+ * Adds chip item management to chips component
7
+ *
8
+ * @param config Chips configuration
9
+ * @returns Component enhancer that adds chip items functionality
10
+ */
11
+ export const withChipItems = (config: ChipsConfig) => component => {
12
+ // Chip instances stored in component state
13
+ const chipInstances = [];
14
+
15
+ return {
16
+ ...component,
17
+ chipInstances,
18
+
19
+ // When DOM is created, add initial chips
20
+ onCreated() {
21
+ if (typeof component.onCreated === 'function') {
22
+ component.onCreated();
23
+ }
24
+
25
+ // Initialize with provided chips
26
+ if (Array.isArray(config.chips) && config.chips.length > 0) {
27
+ config.chips.forEach(chipConfig => {
28
+ this.chips?.addChip?.(chipConfig);
29
+ });
30
+ }
31
+ }
32
+ };
33
+ };
@@ -0,0 +1,77 @@
1
+ // src/components/chips/features/container.ts
2
+ import { ChipsConfig } from '../types';
3
+
4
+ /**
5
+ * Adds container layout features to chips component
6
+ *
7
+ * @param config Chips configuration
8
+ * @returns Component enhancer that adds container layout functionality
9
+ */
10
+ export const withContainer = (config: ChipsConfig) => component => {
11
+ // Track current layout state
12
+ const state = {
13
+ scrollable: config.scrollable === true,
14
+ vertical: config.vertical === true
15
+ };
16
+
17
+ return {
18
+ ...component,
19
+
20
+ // Layout management API
21
+ layout: {
22
+ /**
23
+ * Sets the scrollable state of the chips container
24
+ * @param {boolean} isScrollable - Whether the chips container should be scrollable
25
+ * @returns Layout controller for chaining
26
+ */
27
+ setScrollable(isScrollable: boolean) {
28
+ state.scrollable = isScrollable;
29
+
30
+ if (component.element) {
31
+ if (isScrollable) {
32
+ component.element.classList.add(`${component.getClass('chips')}--scrollable`);
33
+ } else {
34
+ component.element.classList.remove(`${component.getClass('chips')}--scrollable`);
35
+ }
36
+ }
37
+
38
+ return this;
39
+ },
40
+
41
+ /**
42
+ * Gets the scrollable state
43
+ * @returns {boolean} Whether the container is scrollable
44
+ */
45
+ isScrollable() {
46
+ return state.scrollable;
47
+ },
48
+
49
+ /**
50
+ * Sets the vertical layout state
51
+ * @param {boolean} isVertical - Whether the chips container should be vertically stacked
52
+ * @returns Layout controller for chaining
53
+ */
54
+ setVertical(isVertical: boolean) {
55
+ state.vertical = isVertical;
56
+
57
+ if (component.element) {
58
+ if (isVertical) {
59
+ component.element.classList.add(`${component.getClass('chips')}--vertical`);
60
+ } else {
61
+ component.element.classList.remove(`${component.getClass('chips')}--vertical`);
62
+ }
63
+ }
64
+
65
+ return this;
66
+ },
67
+
68
+ /**
69
+ * Gets the vertical state
70
+ * @returns {boolean} Whether the container has vertical layout
71
+ */
72
+ isVertical() {
73
+ return state.vertical;
74
+ }
75
+ }
76
+ };
77
+ };