mtrl 0.2.4 → 0.2.6
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/package.json +6 -3
- package/src/components/badge/_styles.scss +9 -9
- package/src/components/button/_styles.scss +0 -56
- package/src/components/button/button.ts +0 -2
- package/src/components/button/constants.ts +0 -6
- package/src/components/button/index.ts +2 -2
- package/src/components/button/types.ts +1 -7
- package/src/components/card/_styles.scss +67 -25
- package/src/components/card/api.ts +54 -3
- package/src/components/card/card.ts +33 -2
- package/src/components/card/config.ts +143 -21
- package/src/components/card/constants.ts +20 -19
- package/src/components/card/content.ts +299 -2
- package/src/components/card/features.ts +155 -4
- package/src/components/card/index.ts +31 -9
- package/src/components/card/types.ts +138 -15
- package/src/components/chip/chip.ts +1 -9
- package/src/components/chip/constants.ts +0 -10
- package/src/components/chip/index.ts +1 -1
- package/src/components/chip/types.ts +1 -4
- package/src/components/progress/_styles.scss +0 -65
- package/src/components/progress/config.ts +1 -2
- package/src/components/progress/constants.ts +0 -14
- package/src/components/progress/index.ts +1 -1
- package/src/components/progress/progress.ts +1 -4
- package/src/components/progress/types.ts +1 -4
- package/src/components/radios/_styles.scss +0 -45
- package/src/components/radios/api.ts +85 -60
- package/src/components/radios/config.ts +1 -2
- package/src/components/radios/constants.ts +0 -9
- package/src/components/radios/index.ts +1 -1
- package/src/components/radios/radio.ts +34 -11
- package/src/components/radios/radios.ts +2 -1
- package/src/components/radios/types.ts +1 -7
- package/src/components/slider/_styles.scss +193 -281
- package/src/components/slider/accessibility.md +59 -0
- package/src/components/slider/api.ts +36 -101
- package/src/components/slider/config.ts +29 -78
- package/src/components/slider/constants.ts +12 -8
- package/src/components/slider/features/appearance.ts +1 -47
- package/src/components/slider/features/disabled.ts +41 -16
- package/src/components/slider/features/interactions.ts +166 -26
- package/src/components/slider/features/keyboard.ts +125 -6
- package/src/components/slider/features/structure.ts +182 -195
- package/src/components/slider/features/ui.ts +234 -303
- package/src/components/slider/index.ts +11 -1
- package/src/components/slider/slider.ts +1 -1
- package/src/components/slider/types.ts +10 -25
- package/src/components/tabs/_styles.scss +285 -155
- package/src/components/tabs/api.ts +178 -400
- package/src/components/tabs/config.ts +46 -52
- package/src/components/tabs/constants.ts +85 -8
- package/src/components/tabs/features.ts +401 -0
- package/src/components/tabs/index.ts +60 -3
- package/src/components/tabs/indicator.ts +225 -0
- package/src/components/tabs/responsive.ts +144 -0
- package/src/components/tabs/scroll-indicators.ts +149 -0
- package/src/components/tabs/state.ts +186 -0
- package/src/components/tabs/tab-api.ts +258 -0
- package/src/components/tabs/tab.ts +255 -0
- package/src/components/tabs/tabs.ts +50 -31
- package/src/components/tabs/types.ts +324 -128
- package/src/components/tabs/utils.ts +107 -0
- package/src/components/textfield/_styles.scss +0 -98
- package/src/components/textfield/config.ts +2 -3
- package/src/components/textfield/constants.ts +0 -14
- package/src/components/textfield/index.ts +2 -2
- package/src/components/textfield/textfield.ts +0 -2
- package/src/components/textfield/types.ts +1 -4
- package/src/core/compose/component.ts +1 -1
- package/src/core/compose/features/badge.ts +79 -0
- package/src/core/compose/features/index.ts +3 -1
- package/src/styles/abstract/_theme.scss +106 -2
- package/src/components/card/actions.ts +0 -48
- package/src/components/card/header.ts +0 -88
- package/src/components/card/media.ts +0 -52
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// src/components/slider/api.ts
|
|
2
2
|
import { SliderComponent, SliderEvent } from './types';
|
|
3
|
-
import { SLIDER_COLORS, SLIDER_SIZES,
|
|
3
|
+
import { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './constants';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* API options interface - structured by feature area
|
|
7
|
+
*/
|
|
5
8
|
interface ApiOptions {
|
|
6
9
|
slider: {
|
|
7
10
|
setValue: (value: number, triggerEvent?: boolean) => any;
|
|
@@ -26,10 +29,7 @@ interface ApiOptions {
|
|
|
26
29
|
getColor: () => string;
|
|
27
30
|
setSize: (size: string) => void;
|
|
28
31
|
getSize: () => string;
|
|
29
|
-
setOrientation: (orientation: string) => void;
|
|
30
|
-
getOrientation: () => string;
|
|
31
32
|
showTicks: (show: boolean) => void;
|
|
32
|
-
showTickLabels: (show: boolean | string[]) => void;
|
|
33
33
|
showCurrentValue: (show: boolean) => void;
|
|
34
34
|
};
|
|
35
35
|
events: {
|
|
@@ -41,6 +41,9 @@ interface ApiOptions {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Component with elements
|
|
46
|
+
*/
|
|
44
47
|
interface ComponentWithElements {
|
|
45
48
|
element: HTMLElement;
|
|
46
49
|
}
|
|
@@ -53,46 +56,6 @@ interface ComponentWithElements {
|
|
|
53
56
|
*/
|
|
54
57
|
export const withAPI = (options: ApiOptions) =>
|
|
55
58
|
(component: ComponentWithElements): SliderComponent => {
|
|
56
|
-
// Make sure options is defined with fallbacks
|
|
57
|
-
const safeOptions: ApiOptions = options || {
|
|
58
|
-
slider: {
|
|
59
|
-
setValue: () => {},
|
|
60
|
-
getValue: () => 0,
|
|
61
|
-
setSecondValue: () => {},
|
|
62
|
-
getSecondValue: () => null,
|
|
63
|
-
setMin: () => {},
|
|
64
|
-
getMin: () => 0,
|
|
65
|
-
setMax: () => {},
|
|
66
|
-
getMax: () => 100,
|
|
67
|
-
setStep: () => {},
|
|
68
|
-
getStep: () => 1,
|
|
69
|
-
regenerateTicks: () => {}
|
|
70
|
-
},
|
|
71
|
-
disabled: {
|
|
72
|
-
enable: () => {},
|
|
73
|
-
disable: () => {},
|
|
74
|
-
isDisabled: () => false
|
|
75
|
-
},
|
|
76
|
-
appearance: {
|
|
77
|
-
setColor: () => {},
|
|
78
|
-
getColor: () => 'primary',
|
|
79
|
-
setSize: () => {},
|
|
80
|
-
getSize: () => 'medium',
|
|
81
|
-
setOrientation: () => {},
|
|
82
|
-
getOrientation: () => 'horizontal',
|
|
83
|
-
showTicks: () => {},
|
|
84
|
-
showTickLabels: () => {},
|
|
85
|
-
showCurrentValue: () => {}
|
|
86
|
-
},
|
|
87
|
-
events: {
|
|
88
|
-
on: () => {},
|
|
89
|
-
off: () => {}
|
|
90
|
-
},
|
|
91
|
-
lifecycle: {
|
|
92
|
-
destroy: () => {}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
59
|
return {
|
|
97
60
|
...component as any,
|
|
98
61
|
|
|
@@ -103,7 +66,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
103
66
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
104
67
|
*/
|
|
105
68
|
setValue(value: number, triggerEvent: boolean = true) {
|
|
106
|
-
|
|
69
|
+
options.slider.setValue(value, triggerEvent);
|
|
107
70
|
return this;
|
|
108
71
|
},
|
|
109
72
|
|
|
@@ -112,7 +75,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
112
75
|
* @returns {number} Current slider value
|
|
113
76
|
*/
|
|
114
77
|
getValue() {
|
|
115
|
-
return
|
|
78
|
+
return options.slider.getValue();
|
|
116
79
|
},
|
|
117
80
|
|
|
118
81
|
/**
|
|
@@ -122,7 +85,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
122
85
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
123
86
|
*/
|
|
124
87
|
setSecondValue(value: number, triggerEvent: boolean = true) {
|
|
125
|
-
|
|
88
|
+
options.slider.setSecondValue(value, triggerEvent);
|
|
126
89
|
return this;
|
|
127
90
|
},
|
|
128
91
|
|
|
@@ -131,7 +94,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
131
94
|
* @returns {number|null} Current secondary value or null
|
|
132
95
|
*/
|
|
133
96
|
getSecondValue() {
|
|
134
|
-
return
|
|
97
|
+
return options.slider.getSecondValue();
|
|
135
98
|
},
|
|
136
99
|
|
|
137
100
|
/**
|
|
@@ -140,7 +103,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
140
103
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
141
104
|
*/
|
|
142
105
|
setMin(min: number) {
|
|
143
|
-
|
|
106
|
+
options.slider.setMin(min);
|
|
144
107
|
return this;
|
|
145
108
|
},
|
|
146
109
|
|
|
@@ -149,7 +112,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
149
112
|
* @returns {number} Current minimum value
|
|
150
113
|
*/
|
|
151
114
|
getMin() {
|
|
152
|
-
return
|
|
115
|
+
return options.slider.getMin();
|
|
153
116
|
},
|
|
154
117
|
|
|
155
118
|
/**
|
|
@@ -158,7 +121,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
158
121
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
159
122
|
*/
|
|
160
123
|
setMax(max: number) {
|
|
161
|
-
|
|
124
|
+
options.slider.setMax(max);
|
|
162
125
|
return this;
|
|
163
126
|
},
|
|
164
127
|
|
|
@@ -167,7 +130,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
167
130
|
* @returns {number} Current maximum value
|
|
168
131
|
*/
|
|
169
132
|
getMax() {
|
|
170
|
-
return
|
|
133
|
+
return options.slider.getMax();
|
|
171
134
|
},
|
|
172
135
|
|
|
173
136
|
/**
|
|
@@ -176,7 +139,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
176
139
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
177
140
|
*/
|
|
178
141
|
setStep(step: number) {
|
|
179
|
-
|
|
142
|
+
options.slider.setStep(step);
|
|
180
143
|
return this;
|
|
181
144
|
},
|
|
182
145
|
|
|
@@ -185,7 +148,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
185
148
|
* @returns {number} Current step size
|
|
186
149
|
*/
|
|
187
150
|
getStep() {
|
|
188
|
-
return
|
|
151
|
+
return options.slider.getStep();
|
|
189
152
|
},
|
|
190
153
|
|
|
191
154
|
/**
|
|
@@ -193,7 +156,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
193
156
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
194
157
|
*/
|
|
195
158
|
enable() {
|
|
196
|
-
|
|
159
|
+
options.disabled.enable();
|
|
197
160
|
return this;
|
|
198
161
|
},
|
|
199
162
|
|
|
@@ -202,7 +165,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
202
165
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
203
166
|
*/
|
|
204
167
|
disable() {
|
|
205
|
-
|
|
168
|
+
options.disabled.disable();
|
|
206
169
|
return this;
|
|
207
170
|
},
|
|
208
171
|
|
|
@@ -211,7 +174,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
211
174
|
* @returns {boolean} True if slider is disabled
|
|
212
175
|
*/
|
|
213
176
|
isDisabled() {
|
|
214
|
-
return
|
|
177
|
+
return options.disabled.isDisabled();
|
|
215
178
|
},
|
|
216
179
|
|
|
217
180
|
/**
|
|
@@ -219,8 +182,8 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
219
182
|
* @param {string} color - Color variant
|
|
220
183
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
221
184
|
*/
|
|
222
|
-
setColor(color: keyof typeof SLIDER_COLORS | SLIDER_COLORS) {
|
|
223
|
-
|
|
185
|
+
setColor(color: keyof typeof SLIDER_COLORS | typeof SLIDER_COLORS[keyof typeof SLIDER_COLORS]) {
|
|
186
|
+
options.appearance.setColor(color);
|
|
224
187
|
return this;
|
|
225
188
|
},
|
|
226
189
|
|
|
@@ -229,7 +192,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
229
192
|
* @returns {string} Current color name
|
|
230
193
|
*/
|
|
231
194
|
getColor() {
|
|
232
|
-
return
|
|
195
|
+
return options.appearance.getColor();
|
|
233
196
|
},
|
|
234
197
|
|
|
235
198
|
/**
|
|
@@ -237,8 +200,8 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
237
200
|
* @param {string} size - Size variant
|
|
238
201
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
239
202
|
*/
|
|
240
|
-
setSize(size: keyof typeof SLIDER_SIZES | SLIDER_SIZES) {
|
|
241
|
-
|
|
203
|
+
setSize(size: keyof typeof SLIDER_SIZES | typeof SLIDER_SIZES[keyof typeof SLIDER_SIZES]) {
|
|
204
|
+
options.appearance.setSize(size);
|
|
242
205
|
return this;
|
|
243
206
|
},
|
|
244
207
|
|
|
@@ -247,25 +210,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
247
210
|
* @returns {string} Current size name
|
|
248
211
|
*/
|
|
249
212
|
getSize() {
|
|
250
|
-
return
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Sets slider orientation
|
|
255
|
-
* @param {string} orientation - Orientation variant
|
|
256
|
-
* @returns {SliderComponent} Slider component instance for chaining
|
|
257
|
-
*/
|
|
258
|
-
setOrientation(orientation: keyof typeof SLIDER_ORIENTATIONS | SLIDER_ORIENTATIONS) {
|
|
259
|
-
safeOptions.appearance.setOrientation(orientation);
|
|
260
|
-
return this;
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Gets slider orientation
|
|
265
|
-
* @returns {string} Current orientation name
|
|
266
|
-
*/
|
|
267
|
-
getOrientation() {
|
|
268
|
-
return safeOptions.appearance.getOrientation();
|
|
213
|
+
return options.appearance.getSize();
|
|
269
214
|
},
|
|
270
215
|
|
|
271
216
|
/**
|
|
@@ -274,17 +219,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
274
219
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
275
220
|
*/
|
|
276
221
|
showTicks(show: boolean) {
|
|
277
|
-
|
|
278
|
-
return this;
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Shows or hides tick labels
|
|
283
|
-
* @param {boolean|string[]} show - Whether to show labels or array of label texts
|
|
284
|
-
* @returns {SliderComponent} Slider component instance for chaining
|
|
285
|
-
*/
|
|
286
|
-
showTickLabels(show: boolean | string[]) {
|
|
287
|
-
safeOptions.appearance.showTickLabels(show);
|
|
222
|
+
options.appearance.showTicks(show);
|
|
288
223
|
return this;
|
|
289
224
|
},
|
|
290
225
|
|
|
@@ -294,7 +229,7 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
294
229
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
295
230
|
*/
|
|
296
231
|
showCurrentValue(show: boolean) {
|
|
297
|
-
|
|
232
|
+
options.appearance.showCurrentValue(show);
|
|
298
233
|
return this;
|
|
299
234
|
},
|
|
300
235
|
|
|
@@ -304,9 +239,9 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
304
239
|
* @param {Function} handler - Event handler
|
|
305
240
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
306
241
|
*/
|
|
307
|
-
on(event: keyof typeof SLIDER_EVENTS | SLIDER_EVENTS, handler: (event: SliderEvent) => void) {
|
|
308
|
-
if (
|
|
309
|
-
|
|
242
|
+
on(event: keyof typeof SLIDER_EVENTS | typeof SLIDER_EVENTS[keyof typeof SLIDER_EVENTS], handler: (event: SliderEvent) => void) {
|
|
243
|
+
if (options.events && typeof options.events.on === 'function') {
|
|
244
|
+
options.events.on(event, handler);
|
|
310
245
|
}
|
|
311
246
|
return this;
|
|
312
247
|
},
|
|
@@ -317,9 +252,9 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
317
252
|
* @param {Function} handler - Event handler
|
|
318
253
|
* @returns {SliderComponent} Slider component instance for chaining
|
|
319
254
|
*/
|
|
320
|
-
off(event: keyof typeof SLIDER_EVENTS | SLIDER_EVENTS, handler: (event: SliderEvent) => void) {
|
|
321
|
-
if (
|
|
322
|
-
|
|
255
|
+
off(event: keyof typeof SLIDER_EVENTS | typeof SLIDER_EVENTS[keyof typeof SLIDER_EVENTS], handler: (event: SliderEvent) => void) {
|
|
256
|
+
if (options.events && typeof options.events.off === 'function') {
|
|
257
|
+
options.events.off(event, handler);
|
|
323
258
|
}
|
|
324
259
|
return this;
|
|
325
260
|
},
|
|
@@ -328,8 +263,8 @@ export const withAPI = (options: ApiOptions) =>
|
|
|
328
263
|
* Destroys the slider component and cleans up resources
|
|
329
264
|
*/
|
|
330
265
|
destroy() {
|
|
331
|
-
if (
|
|
332
|
-
|
|
266
|
+
if (options.lifecycle && typeof options.lifecycle.destroy === 'function') {
|
|
267
|
+
options.lifecycle.destroy();
|
|
333
268
|
}
|
|
334
269
|
}
|
|
335
270
|
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createElementConfig
|
|
5
5
|
} from '../../core/config/component-config';
|
|
6
6
|
import { SliderConfig } from './types';
|
|
7
|
-
import { SLIDER_COLORS, SLIDER_SIZES
|
|
7
|
+
import { SLIDER_COLORS, SLIDER_SIZES } from './constants';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Default configuration for the Slider component
|
|
@@ -17,9 +17,7 @@ export const defaultConfig: SliderConfig = {
|
|
|
17
17
|
disabled: false,
|
|
18
18
|
color: SLIDER_COLORS.PRIMARY,
|
|
19
19
|
size: SLIDER_SIZES.MEDIUM,
|
|
20
|
-
orientation: SLIDER_ORIENTATIONS.HORIZONTAL,
|
|
21
20
|
ticks: false,
|
|
22
|
-
tickLabels: false,
|
|
23
21
|
showValue: true,
|
|
24
22
|
snapToSteps: true,
|
|
25
23
|
range: false,
|
|
@@ -43,13 +41,11 @@ export const getElementConfig = (config: SliderConfig) => {
|
|
|
43
41
|
return createElementConfig(config, {
|
|
44
42
|
tag: 'div',
|
|
45
43
|
attrs: {
|
|
46
|
-
|
|
47
|
-
'tabindex':
|
|
44
|
+
// Accessibility improvement: Container is not focusable; only thumbs are
|
|
45
|
+
'tabindex': '-1',
|
|
48
46
|
'aria-disabled': config.disabled === true ? true : false,
|
|
49
|
-
|
|
50
|
-
'
|
|
51
|
-
'aria-valuenow': config.value,
|
|
52
|
-
'aria-orientation': config.orientation
|
|
47
|
+
// ARIA attributes will be set directly on thumbs instead
|
|
48
|
+
'role': 'none',
|
|
53
49
|
},
|
|
54
50
|
className: config.class
|
|
55
51
|
});
|
|
@@ -61,85 +57,40 @@ export const getElementConfig = (config: SliderConfig) => {
|
|
|
61
57
|
* @returns {Object} API configuration object
|
|
62
58
|
*/
|
|
63
59
|
export const getApiConfig = (comp) => {
|
|
64
|
-
// Create
|
|
65
|
-
const safeCall = (obj, path, fallback = () => {}) => {
|
|
66
|
-
try {
|
|
67
|
-
const parts = path.split('.');
|
|
68
|
-
let current = obj;
|
|
69
|
-
|
|
70
|
-
for (const part of parts) {
|
|
71
|
-
if (current === undefined || current === null) return fallback;
|
|
72
|
-
current = current[part];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return typeof current === 'function' ? current : fallback;
|
|
76
|
-
} catch {
|
|
77
|
-
return fallback;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const safeGetter = (obj, path, defaultValue = null) => {
|
|
82
|
-
try {
|
|
83
|
-
const parts = path.split('.');
|
|
84
|
-
let current = obj;
|
|
85
|
-
|
|
86
|
-
for (const part of parts) {
|
|
87
|
-
if (current === undefined || current === null) return defaultValue;
|
|
88
|
-
current = current[part];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return current === undefined ? defaultValue : current;
|
|
92
|
-
} catch {
|
|
93
|
-
return defaultValue;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Create API configuration using safe accessors
|
|
60
|
+
// Create API configuration using accessor pattern
|
|
98
61
|
return {
|
|
99
62
|
slider: {
|
|
100
|
-
setValue: (value, triggerEvent) =>
|
|
101
|
-
getValue: () =>
|
|
102
|
-
setSecondValue: (value, triggerEvent) =>
|
|
103
|
-
getSecondValue: () =>
|
|
104
|
-
setMin: (min) =>
|
|
105
|
-
getMin: () =>
|
|
106
|
-
setMax: (max) =>
|
|
107
|
-
getMax: () =>
|
|
108
|
-
setStep: (step) =>
|
|
109
|
-
getStep: () =>
|
|
63
|
+
setValue: (value, triggerEvent) => comp.slider?.setValue(value, triggerEvent),
|
|
64
|
+
getValue: () => comp.slider?.getValue() ?? 0,
|
|
65
|
+
setSecondValue: (value, triggerEvent) => comp.slider?.setSecondValue(value, triggerEvent),
|
|
66
|
+
getSecondValue: () => comp.slider?.getSecondValue() ?? null,
|
|
67
|
+
setMin: (min) => comp.slider?.setMin(min),
|
|
68
|
+
getMin: () => comp.slider?.getMin() ?? 0,
|
|
69
|
+
setMax: (max) => comp.slider?.setMax(max),
|
|
70
|
+
getMax: () => comp.slider?.getMax() ?? 100,
|
|
71
|
+
setStep: (step) => comp.slider?.setStep(step),
|
|
72
|
+
getStep: () => comp.slider?.getStep() ?? 1,
|
|
73
|
+
regenerateTicks: () => comp.slider?.regenerateTicks?.()
|
|
110
74
|
},
|
|
111
75
|
disabled: {
|
|
112
|
-
enable: () =>
|
|
113
|
-
disable: () =>
|
|
114
|
-
isDisabled: () =>
|
|
76
|
+
enable: () => comp.disabled?.enable?.(),
|
|
77
|
+
disable: () => comp.disabled?.disable?.(),
|
|
78
|
+
isDisabled: () => comp.disabled?.isDisabled?.() ?? false
|
|
115
79
|
},
|
|
116
80
|
appearance: {
|
|
117
|
-
setColor: (color) =>
|
|
118
|
-
getColor: () =>
|
|
119
|
-
setSize: (size) =>
|
|
120
|
-
getSize: () =>
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
showTicks: (show) => safeCall(comp, 'appearance.showTicks')(show),
|
|
124
|
-
showTickLabels: (show) => safeCall(comp, 'appearance.showTickLabels')(show),
|
|
125
|
-
showCurrentValue: (show) => safeCall(comp, 'appearance.showCurrentValue')(show)
|
|
81
|
+
setColor: (color) => comp.appearance?.setColor?.(color),
|
|
82
|
+
getColor: () => comp.appearance?.getColor?.() ?? 'primary',
|
|
83
|
+
setSize: (size) => comp.appearance?.setSize?.(size),
|
|
84
|
+
getSize: () => comp.appearance?.getSize?.() ?? 'medium',
|
|
85
|
+
showTicks: (show) => comp.appearance?.showTicks?.(show),
|
|
86
|
+
showCurrentValue: (show) => comp.appearance?.showCurrentValue?.(show)
|
|
126
87
|
},
|
|
127
88
|
events: {
|
|
128
|
-
on: (event, handler) =>
|
|
129
|
-
|
|
130
|
-
return comp.events.on(event, handler);
|
|
131
|
-
}
|
|
132
|
-
return undefined;
|
|
133
|
-
},
|
|
134
|
-
off: (event, handler) => {
|
|
135
|
-
if (comp && comp.events && typeof comp.events.off === 'function') {
|
|
136
|
-
return comp.events.off(event, handler);
|
|
137
|
-
}
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
89
|
+
on: (event, handler) => comp.on?.(event, handler),
|
|
90
|
+
off: (event, handler) => comp.off?.(event, handler)
|
|
140
91
|
},
|
|
141
92
|
lifecycle: {
|
|
142
|
-
destroy: () =>
|
|
93
|
+
destroy: () => comp.lifecycle?.destroy?.()
|
|
143
94
|
}
|
|
144
95
|
};
|
|
145
96
|
};
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
// src/components/slider/constants.ts
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Available slider color variants
|
|
5
|
+
*/
|
|
3
6
|
export const SLIDER_COLORS = {
|
|
4
7
|
PRIMARY: 'primary',
|
|
5
8
|
SECONDARY: 'secondary',
|
|
6
9
|
TERTIARY: 'tertiary',
|
|
7
10
|
ERROR: 'error'
|
|
8
|
-
};
|
|
11
|
+
} as const;
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Available slider size variants
|
|
15
|
+
*/
|
|
10
16
|
export const SLIDER_SIZES = {
|
|
11
17
|
SMALL: 'small',
|
|
12
18
|
MEDIUM: 'medium',
|
|
13
19
|
LARGE: 'large'
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const SLIDER_ORIENTATIONS = {
|
|
17
|
-
HORIZONTAL: 'horizontal',
|
|
18
|
-
VERTICAL: 'vertical'
|
|
19
|
-
};
|
|
20
|
+
} as const;
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Available slider events
|
|
24
|
+
*/
|
|
21
25
|
export const SLIDER_EVENTS = {
|
|
22
26
|
CHANGE: 'change',
|
|
23
27
|
INPUT: 'input',
|
|
@@ -25,4 +29,4 @@ export const SLIDER_EVENTS = {
|
|
|
25
29
|
BLUR: 'blur',
|
|
26
30
|
START: 'start',
|
|
27
31
|
END: 'end'
|
|
28
|
-
};
|
|
32
|
+
} as const;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/components/slider/features/appearance.ts
|
|
2
|
-
import { SLIDER_COLORS, SLIDER_SIZES
|
|
2
|
+
import { SLIDER_COLORS, SLIDER_SIZES } from '../constants';
|
|
3
3
|
import { SliderConfig } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -69,39 +69,6 @@ export const withAppearance = (config: SliderConfig) => component => {
|
|
|
69
69
|
return sizeClass || SLIDER_SIZES.MEDIUM;
|
|
70
70
|
},
|
|
71
71
|
|
|
72
|
-
/**
|
|
73
|
-
* Sets slider orientation
|
|
74
|
-
* @param orientation Orientation variant
|
|
75
|
-
*/
|
|
76
|
-
setOrientation(orientation: keyof typeof SLIDER_ORIENTATIONS | SLIDER_ORIENTATIONS) {
|
|
77
|
-
// Clear existing orientation class
|
|
78
|
-
component.element.classList.remove(`${component.getClass('slider')}--${SLIDER_ORIENTATIONS.VERTICAL}`);
|
|
79
|
-
|
|
80
|
-
// Add orientation class if vertical
|
|
81
|
-
if (orientation === SLIDER_ORIENTATIONS.VERTICAL) {
|
|
82
|
-
component.element.classList.add(`${component.getClass('slider')}--${SLIDER_ORIENTATIONS.VERTICAL}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Update ARIA attribute
|
|
86
|
-
component.element.setAttribute('aria-orientation', orientation);
|
|
87
|
-
|
|
88
|
-
// Update visual elements
|
|
89
|
-
if (component.slider) {
|
|
90
|
-
const eventData = { slider: component, value: component.slider.getValue() };
|
|
91
|
-
component.events.trigger('change', eventData);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Gets slider orientation
|
|
97
|
-
* @returns Current orientation name
|
|
98
|
-
*/
|
|
99
|
-
getOrientation() {
|
|
100
|
-
return component.element.classList.contains(`${component.getClass('slider')}--${SLIDER_ORIENTATIONS.VERTICAL}`)
|
|
101
|
-
? SLIDER_ORIENTATIONS.VERTICAL
|
|
102
|
-
: SLIDER_ORIENTATIONS.HORIZONTAL;
|
|
103
|
-
},
|
|
104
|
-
|
|
105
72
|
/**
|
|
106
73
|
* Shows or hides tick marks
|
|
107
74
|
* @param show Whether to show ticks
|
|
@@ -115,19 +82,6 @@ export const withAppearance = (config: SliderConfig) => component => {
|
|
|
115
82
|
}
|
|
116
83
|
},
|
|
117
84
|
|
|
118
|
-
/**
|
|
119
|
-
* Shows or hides tick labels
|
|
120
|
-
* @param show Whether to show labels or array of label texts
|
|
121
|
-
*/
|
|
122
|
-
showTickLabels(show: boolean | string[]) {
|
|
123
|
-
config.tickLabels = show;
|
|
124
|
-
|
|
125
|
-
// Regenerate ticks if slider is initialized
|
|
126
|
-
if (component.slider) {
|
|
127
|
-
component.slider.regenerateTicks();
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
|
|
131
85
|
/**
|
|
132
86
|
* Shows or hides current value bubble while dragging
|
|
133
87
|
* @param show Whether to show value bubble
|
|
@@ -10,29 +10,54 @@ export const withDisabled = (config: SliderConfig) => component => {
|
|
|
10
10
|
// Initial disabled state
|
|
11
11
|
const isDisabled = config.disabled === true;
|
|
12
12
|
|
|
13
|
+
// Apply initial disabled state if needed
|
|
14
|
+
if (isDisabled && component.structure) {
|
|
15
|
+
setTimeout(() => {
|
|
16
|
+
disableComponent();
|
|
17
|
+
}, 0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function disableComponent() {
|
|
21
|
+
component.element.classList.add(`${component.getClass('slider')}--disabled`);
|
|
22
|
+
component.element.setAttribute('aria-disabled', 'true');
|
|
23
|
+
|
|
24
|
+
// Ensure thumbs cannot receive focus when disabled
|
|
25
|
+
if (component.structure.thumb) {
|
|
26
|
+
component.structure.thumb.tabIndex = -1;
|
|
27
|
+
component.structure.thumb.setAttribute('aria-disabled', 'true');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (config.range && component.structure.secondThumb) {
|
|
31
|
+
component.structure.secondThumb.tabIndex = -1;
|
|
32
|
+
component.structure.secondThumb.setAttribute('aria-disabled', 'true');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function enableComponent() {
|
|
37
|
+
component.element.classList.remove(`${component.getClass('slider')}--disabled`);
|
|
38
|
+
component.element.setAttribute('aria-disabled', 'false');
|
|
39
|
+
|
|
40
|
+
// Re-enable focus on thumbs
|
|
41
|
+
if (component.structure.thumb) {
|
|
42
|
+
component.structure.thumb.tabIndex = 0;
|
|
43
|
+
component.structure.thumb.setAttribute('aria-disabled', 'false');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (config.range && component.structure.secondThumb) {
|
|
47
|
+
component.structure.secondThumb.tabIndex = 0;
|
|
48
|
+
component.structure.secondThumb.setAttribute('aria-disabled', 'false');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
13
52
|
return {
|
|
14
53
|
...component,
|
|
15
54
|
disabled: {
|
|
16
55
|
enable() {
|
|
17
|
-
|
|
18
|
-
component.element.setAttribute('aria-disabled', 'false');
|
|
19
|
-
component.element.tabIndex = 0;
|
|
20
|
-
component.structure.thumb.tabIndex = 0;
|
|
21
|
-
|
|
22
|
-
if (config.range && component.structure.secondThumb) {
|
|
23
|
-
component.structure.secondThumb.tabIndex = 0;
|
|
24
|
-
}
|
|
56
|
+
enableComponent();
|
|
25
57
|
},
|
|
26
58
|
|
|
27
59
|
disable() {
|
|
28
|
-
|
|
29
|
-
component.element.setAttribute('aria-disabled', 'true');
|
|
30
|
-
component.element.tabIndex = -1;
|
|
31
|
-
component.structure.thumb.tabIndex = -1;
|
|
32
|
-
|
|
33
|
-
if (config.range && component.structure.secondThumb) {
|
|
34
|
-
component.structure.secondThumb.tabIndex = -1;
|
|
35
|
-
}
|
|
60
|
+
disableComponent();
|
|
36
61
|
},
|
|
37
62
|
|
|
38
63
|
isDisabled() {
|