mtrl 0.2.1 → 0.2.3
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/.typedocignore +11 -0
- package/DOCS.md +153 -0
- package/index.ts +18 -3
- package/package.json +7 -2
- package/src/components/badge/_styles.scss +174 -0
- package/src/components/badge/api.ts +292 -0
- package/src/components/badge/badge.ts +52 -0
- package/src/components/badge/config.ts +68 -0
- package/src/components/badge/constants.ts +30 -0
- package/src/components/badge/features.ts +185 -0
- package/src/components/badge/index.ts +4 -0
- package/src/components/badge/types.ts +105 -0
- package/src/components/button/types.ts +174 -29
- package/src/components/card/constants.ts +14 -0
- package/src/components/carousel/_styles.scss +645 -0
- package/src/components/carousel/api.ts +147 -0
- package/src/components/carousel/carousel.ts +178 -0
- package/src/components/carousel/config.ts +91 -0
- package/src/components/carousel/constants.ts +95 -0
- package/src/components/carousel/features/drag.ts +388 -0
- package/src/components/carousel/features/index.ts +8 -0
- package/src/components/carousel/features/slides.ts +682 -0
- package/src/components/carousel/index.ts +38 -0
- package/src/components/carousel/types.ts +327 -0
- package/src/components/chip/_styles.scss +83 -140
- package/src/components/chip/api.ts +231 -102
- package/src/components/chip/chip.ts +356 -44
- package/src/components/chip/constants.ts +3 -3
- package/src/components/chip/index.ts +3 -3
- package/src/components/dialog/_styles.scss +213 -0
- package/src/components/dialog/api.ts +283 -0
- package/src/components/dialog/config.ts +113 -0
- package/src/components/dialog/constants.ts +32 -0
- package/src/components/dialog/dialog.ts +56 -0
- package/src/components/dialog/features.ts +713 -0
- package/src/components/dialog/index.ts +15 -0
- package/src/components/dialog/types.ts +221 -0
- package/src/components/progress/_styles.scss +13 -1
- package/src/components/progress/api.ts +2 -2
- package/src/components/progress/progress.ts +2 -2
- package/src/components/progress/types.ts +3 -0
- package/src/components/radios/_styles.scss +232 -0
- package/src/components/radios/api.ts +100 -0
- package/src/components/radios/config.ts +60 -0
- package/src/components/radios/constants.ts +28 -0
- package/src/components/radios/index.ts +4 -0
- package/src/components/radios/radio.ts +269 -0
- package/src/components/radios/radios.ts +42 -0
- package/src/components/radios/types.ts +232 -0
- package/src/components/sheet/_styles.scss +236 -0
- package/src/components/sheet/api.ts +96 -0
- package/src/components/sheet/config.ts +66 -0
- package/src/components/sheet/constants.ts +20 -0
- package/src/components/sheet/features/content.ts +51 -0
- package/src/components/sheet/features/gestures.ts +177 -0
- package/src/components/sheet/features/index.ts +6 -0
- package/src/components/sheet/features/position.ts +42 -0
- package/src/components/sheet/features/state.ts +116 -0
- package/src/components/sheet/features/title.ts +86 -0
- package/src/components/sheet/index.ts +4 -0
- package/src/components/sheet/sheet.ts +57 -0
- package/src/components/sheet/types.ts +266 -0
- package/src/components/slider/_styles.scss +518 -0
- package/src/components/slider/api.ts +336 -0
- package/src/components/slider/config.ts +145 -0
- package/src/components/slider/constants.ts +28 -0
- package/src/components/slider/features/appearance.ts +140 -0
- package/src/components/slider/features/disabled.ts +43 -0
- package/src/components/slider/features/events.ts +164 -0
- package/src/components/slider/features/index.ts +5 -0
- package/src/components/slider/features/interactions.ts +256 -0
- package/src/components/slider/features/keyboard.ts +114 -0
- package/src/components/slider/features/slider.ts +336 -0
- package/src/components/slider/features/structure.ts +264 -0
- package/src/components/slider/features/ui.ts +518 -0
- package/src/components/slider/index.ts +9 -0
- package/src/components/slider/slider.ts +58 -0
- package/src/components/slider/types.ts +166 -0
- package/src/components/tabs/_styles.scss +224 -0
- package/src/components/tabs/api.ts +443 -0
- package/src/components/tabs/config.ts +80 -0
- package/src/components/tabs/constants.ts +12 -0
- package/src/components/tabs/index.ts +4 -0
- package/src/components/tabs/tabs.ts +52 -0
- package/src/components/tabs/types.ts +247 -0
- package/src/components/textfield/_styles.scss +97 -4
- package/src/components/tooltip/_styles.scss +241 -0
- package/src/components/tooltip/api.ts +411 -0
- package/src/components/tooltip/config.ts +78 -0
- package/src/components/tooltip/constants.ts +27 -0
- package/src/components/tooltip/index.ts +4 -0
- package/src/components/tooltip/tooltip.ts +60 -0
- package/src/components/tooltip/types.ts +178 -0
- package/src/index.ts +9 -1
- package/src/styles/abstract/_variables.scss +24 -0
- package/tsconfig.json +22 -0
- package/typedoc.json +28 -0
- package/typedoc.simple.json +14 -0
|
@@ -8,108 +8,237 @@
|
|
|
8
8
|
* @returns {Function} Higher-order function that adds API methods to component
|
|
9
9
|
* @internal This is an internal utility for the Chip component
|
|
10
10
|
*/
|
|
11
|
-
export const withAPI = ({ disabled, lifecycle }) => (component) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
getValue: () => component.element.getAttribute('data-value'),
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Sets the chip's value
|
|
23
|
-
* @param {string} value - Value to set
|
|
24
|
-
* @returns {Object} The chip instance for chaining
|
|
25
|
-
*/
|
|
26
|
-
setValue (value) {
|
|
27
|
-
component.element.setAttribute('data-value', value)
|
|
28
|
-
return this
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Enables the chip
|
|
33
|
-
* @returns {Object} The chip instance for chaining
|
|
34
|
-
*/
|
|
35
|
-
enable () {
|
|
36
|
-
disabled.enable()
|
|
37
|
-
component.element.setAttribute('aria-disabled', 'false')
|
|
38
|
-
return this
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Disables the chip
|
|
43
|
-
* @returns {Object} The chip instance for chaining
|
|
44
|
-
*/
|
|
45
|
-
disable () {
|
|
46
|
-
disabled.disable()
|
|
47
|
-
component.element.setAttribute('aria-disabled', 'true')
|
|
48
|
-
return this
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Sets the chip's text content
|
|
53
|
-
* @param {string} content - Text content
|
|
54
|
-
* @returns {Object} The chip instance for chaining
|
|
55
|
-
*/
|
|
56
|
-
setText (content) {
|
|
57
|
-
component.text.setText(content)
|
|
58
|
-
return this
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Gets the chip's text content
|
|
63
|
-
* @returns {string} The chip's text content
|
|
64
|
-
*/
|
|
65
|
-
getText () {
|
|
66
|
-
return component.text.getText()
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Sets the chip's leading icon
|
|
71
|
-
* @param {string} icon - Icon HTML content
|
|
72
|
-
* @returns {Object} The chip instance for chaining
|
|
73
|
-
*/
|
|
74
|
-
setIcon (icon) {
|
|
75
|
-
component.icon.setIcon(icon)
|
|
76
|
-
return this
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Gets the chip's icon content
|
|
81
|
-
* @returns {string} The chip's icon HTML
|
|
82
|
-
*/
|
|
83
|
-
getIcon () {
|
|
84
|
-
return component.icon.getIcon()
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Sets the chip's trailing icon
|
|
89
|
-
* @param {string} icon - Icon HTML content
|
|
90
|
-
* @returns {Object} The chip instance for chaining
|
|
91
|
-
*/
|
|
92
|
-
setTrailingIcon (icon) {
|
|
93
|
-
const trailingIconSelector = `.${component.getClass('chip')}-trailing-icon`
|
|
94
|
-
let trailingIconElement = component.element.querySelector(trailingIconSelector)
|
|
95
|
-
|
|
96
|
-
if (!trailingIconElement && icon) {
|
|
97
|
-
trailingIconElement = document.createElement('span')
|
|
98
|
-
trailingIconElement.className = `${component.getClass('chip')}-trailing-icon`
|
|
99
|
-
component.element.appendChild(trailingIconElement)
|
|
100
|
-
}
|
|
11
|
+
export const withAPI = ({ disabled, lifecycle }) => (component) => {
|
|
12
|
+
// Track selected state internally
|
|
13
|
+
let isSelected = component.element.classList.contains(`${component.getClass('chip')}--selected`);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...component,
|
|
17
|
+
element: component.element,
|
|
101
18
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Gets the chip's value
|
|
21
|
+
* @returns {string} The chip's value attribute
|
|
22
|
+
*/
|
|
23
|
+
getValue() {
|
|
24
|
+
return component.element.getAttribute('data-value') || '';
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sets the chip's value
|
|
29
|
+
* @param {string} value - Value to set
|
|
30
|
+
* @returns {Object} The chip instance for chaining
|
|
31
|
+
*/
|
|
32
|
+
setValue(value) {
|
|
33
|
+
component.element.setAttribute('data-value', value || '');
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the chip is disabled
|
|
39
|
+
* @returns {boolean} True if the chip is disabled
|
|
40
|
+
*/
|
|
41
|
+
isDisabled() {
|
|
42
|
+
return component.element.getAttribute('aria-disabled') === 'true';
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Enables the chip
|
|
47
|
+
* @returns {Object} The chip instance for chaining
|
|
48
|
+
*/
|
|
49
|
+
enable() {
|
|
50
|
+
disabled.enable();
|
|
51
|
+
component.element.classList.remove(`${component.getClass('chip')}--disabled`);
|
|
52
|
+
component.element.setAttribute('aria-disabled', 'false');
|
|
53
|
+
component.element.setAttribute('tabindex', '0');
|
|
54
|
+
return this;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Disables the chip
|
|
59
|
+
* @returns {Object} The chip instance for chaining
|
|
60
|
+
*/
|
|
61
|
+
disable() {
|
|
62
|
+
disabled.disable();
|
|
63
|
+
component.element.classList.add(`${component.getClass('chip')}--disabled`);
|
|
64
|
+
component.element.setAttribute('aria-disabled', 'true');
|
|
65
|
+
component.element.setAttribute('tabindex', '-1');
|
|
66
|
+
return this;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets the chip's text content
|
|
71
|
+
* @param {string} content - Text content
|
|
72
|
+
* @returns {Object} The chip instance for chaining
|
|
73
|
+
*/
|
|
74
|
+
setText(content) {
|
|
75
|
+
const containerSelector = `.${component.getClass('chip')}-content`;
|
|
76
|
+
const contentContainer = component.element.querySelector(containerSelector) || component.element;
|
|
77
|
+
|
|
78
|
+
const textSelector = `.${component.getClass('chip')}-text`;
|
|
79
|
+
let textElement = component.element.querySelector(textSelector);
|
|
80
|
+
|
|
81
|
+
if (!textElement && content) {
|
|
82
|
+
textElement = document.createElement('span');
|
|
83
|
+
textElement.className = `${component.getClass('chip')}-text`;
|
|
84
|
+
|
|
85
|
+
// Find the right position to insert (after leading icon if present, or as first child)
|
|
86
|
+
const leadingIcon = component.element.querySelector(`.${component.getClass('chip')}-leading-icon`);
|
|
87
|
+
if (leadingIcon) {
|
|
88
|
+
contentContainer.insertBefore(textElement, leadingIcon.nextSibling);
|
|
89
|
+
} else {
|
|
90
|
+
contentContainer.insertBefore(textElement, contentContainer.firstChild);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (textElement) {
|
|
95
|
+
textElement.textContent = content || '';
|
|
96
|
+
|
|
97
|
+
// Remove the element if content is empty
|
|
98
|
+
if (!content && textElement.parentNode) {
|
|
99
|
+
textElement.parentNode.removeChild(textElement);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gets the chip's text content
|
|
108
|
+
* @returns {string} The chip's text content
|
|
109
|
+
*/
|
|
110
|
+
getText() {
|
|
111
|
+
const textElement = component.element.querySelector(`.${component.getClass('chip')}-text`);
|
|
112
|
+
return textElement ? textElement.textContent : '';
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets the chip's leading icon (alias for setLeadingIcon)
|
|
117
|
+
* @param {string} icon - Icon HTML content
|
|
118
|
+
* @returns {Object} The chip instance for chaining
|
|
119
|
+
*/
|
|
120
|
+
setIcon(icon) {
|
|
121
|
+
return this.setLeadingIcon(icon);
|
|
122
|
+
},
|
|
105
123
|
|
|
106
|
-
|
|
107
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Gets the chip's icon content
|
|
126
|
+
* @returns {string} The chip's icon HTML
|
|
127
|
+
*/
|
|
128
|
+
getIcon() {
|
|
129
|
+
const iconElement = component.element.querySelector(`.${component.getClass('chip')}-leading-icon`);
|
|
130
|
+
return iconElement ? iconElement.innerHTML : '';
|
|
131
|
+
},
|
|
108
132
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
133
|
+
/**
|
|
134
|
+
* Sets the chip's leading icon
|
|
135
|
+
* @param {string} icon - Icon HTML content
|
|
136
|
+
* @returns {Object} The chip instance for chaining
|
|
137
|
+
*/
|
|
138
|
+
setLeadingIcon(icon) {
|
|
139
|
+
const contentContainer = component.element.querySelector(`.${component.getClass('chip')}-content`) || component.element;
|
|
140
|
+
const leadingIconSelector = `.${component.getClass('chip')}-leading-icon`;
|
|
141
|
+
let leadingIconElement = component.element.querySelector(leadingIconSelector);
|
|
142
|
+
|
|
143
|
+
if (!leadingIconElement && icon) {
|
|
144
|
+
leadingIconElement = document.createElement('span');
|
|
145
|
+
leadingIconElement.className = `${component.getClass('chip')}-leading-icon`;
|
|
146
|
+
|
|
147
|
+
// Insert as first child of the content container
|
|
148
|
+
contentContainer.insertBefore(leadingIconElement, contentContainer.firstChild);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (leadingIconElement) {
|
|
152
|
+
leadingIconElement.innerHTML = icon || '';
|
|
153
|
+
|
|
154
|
+
// Remove the element if icon is empty
|
|
155
|
+
if (!icon && leadingIconElement.parentNode) {
|
|
156
|
+
leadingIconElement.parentNode.removeChild(leadingIconElement);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return this;
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Sets the chip's trailing icon
|
|
165
|
+
* @param {string} icon - Icon HTML content
|
|
166
|
+
* @param {Function} [onClick] - Click handler for the trailing icon
|
|
167
|
+
* @returns {Object} The chip instance for chaining
|
|
168
|
+
*/
|
|
169
|
+
setTrailingIcon(icon, onClick) {
|
|
170
|
+
const contentContainer = component.element.querySelector(`.${component.getClass('chip')}-content`) || component.element;
|
|
171
|
+
const trailingIconSelector = `.${component.getClass('chip')}-trailing-icon`;
|
|
172
|
+
let trailingIconElement = component.element.querySelector(trailingIconSelector);
|
|
173
|
+
|
|
174
|
+
if (!trailingIconElement && icon) {
|
|
175
|
+
trailingIconElement = document.createElement('span');
|
|
176
|
+
trailingIconElement.className = `${component.getClass('chip')}-trailing-icon`;
|
|
177
|
+
|
|
178
|
+
// Add as last child of content container
|
|
179
|
+
contentContainer.appendChild(trailingIconElement);
|
|
180
|
+
|
|
181
|
+
// Add click handler if provided
|
|
182
|
+
if (onClick) {
|
|
183
|
+
trailingIconElement.addEventListener('click', (e) => {
|
|
184
|
+
e.stopPropagation(); // Prevent chip click event
|
|
185
|
+
onClick(this);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (trailingIconElement) {
|
|
191
|
+
trailingIconElement.innerHTML = icon || '';
|
|
192
|
+
|
|
193
|
+
// Remove the element if icon is empty
|
|
194
|
+
if (!icon && trailingIconElement.parentNode) {
|
|
195
|
+
trailingIconElement.parentNode.removeChild(trailingIconElement);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return this;
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Checks if the chip is selected
|
|
204
|
+
* @returns {boolean} True if the chip is selected
|
|
205
|
+
*/
|
|
206
|
+
isSelected() {
|
|
207
|
+
return isSelected;
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Sets the chip's selected state
|
|
212
|
+
* @param {boolean} selected - Whether the chip should be selected
|
|
213
|
+
* @returns {Object} The chip instance for chaining
|
|
214
|
+
*/
|
|
215
|
+
setSelected(selected) {
|
|
216
|
+
isSelected = !!selected;
|
|
217
|
+
|
|
218
|
+
if (selected) {
|
|
219
|
+
component.element.classList.add(`${component.getClass('chip')}--selected`);
|
|
220
|
+
component.element.setAttribute('aria-selected', 'true');
|
|
221
|
+
} else {
|
|
222
|
+
component.element.classList.remove(`${component.getClass('chip')}--selected`);
|
|
223
|
+
component.element.setAttribute('aria-selected', 'false');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Toggles the chip's selected state
|
|
231
|
+
* @returns {Object} The chip instance for chaining
|
|
232
|
+
*/
|
|
233
|
+
toggleSelected() {
|
|
234
|
+
return this.setSelected(!isSelected);
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Destroys the chip component and cleans up resources
|
|
239
|
+
*/
|
|
240
|
+
destroy() {
|
|
241
|
+
lifecycle.destroy();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
};
|