mtrl 0.2.6 → 0.2.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.
- package/index.ts +18 -0
- package/package.json +1 -1
- package/src/components/badge/_styles.scss +117 -109
- package/src/components/badge/api.ts +57 -59
- package/src/components/badge/badge.ts +16 -2
- package/src/components/badge/config.ts +65 -11
- package/src/components/badge/constants.ts +22 -12
- package/src/components/badge/features.ts +44 -40
- package/src/components/badge/types.ts +42 -30
- package/src/components/bottom-app-bar/_styles.scss +103 -0
- package/src/components/bottom-app-bar/bottom-app-bar.ts +196 -0
- package/src/components/bottom-app-bar/config.ts +73 -0
- package/src/components/bottom-app-bar/index.ts +11 -0
- package/src/components/bottom-app-bar/types.ts +108 -0
- package/src/components/button/_styles.scss +0 -10
- package/src/components/button/api.ts +5 -0
- package/src/components/button/config.ts +5 -0
- package/src/components/button/types.ts +6 -0
- package/src/components/card/card.ts +13 -25
- package/src/components/card/config.ts +67 -22
- package/src/components/card/features.ts +3 -0
- package/src/components/card/types.ts +28 -0
- package/src/components/checkbox/_styles.scss +0 -2
- package/src/components/datepicker/_styles.scss +358 -0
- package/src/components/datepicker/api.ts +272 -0
- package/src/components/datepicker/config.ts +144 -0
- package/src/components/datepicker/constants.ts +98 -0
- package/src/components/datepicker/datepicker.ts +346 -0
- package/src/components/datepicker/index.ts +9 -0
- package/src/components/datepicker/render.ts +452 -0
- package/src/components/datepicker/types.ts +268 -0
- package/src/components/datepicker/utils.ts +290 -0
- package/src/components/dialog/_styles.scss +174 -128
- package/src/components/dialog/api.ts +48 -13
- package/src/components/dialog/config.ts +9 -5
- package/src/components/dialog/dialog.ts +6 -3
- package/src/components/dialog/features.ts +290 -130
- package/src/components/dialog/types.ts +7 -4
- package/src/components/divider/_styles.scss +57 -0
- package/src/components/divider/config.ts +81 -0
- package/src/components/divider/divider.ts +37 -0
- package/src/components/divider/features.ts +207 -0
- package/src/components/divider/index.ts +5 -0
- package/src/components/divider/types.ts +55 -0
- package/src/components/extended-fab/_styles.scss +267 -0
- package/src/components/extended-fab/api.ts +141 -0
- package/src/components/extended-fab/config.ts +108 -0
- package/src/components/extended-fab/constants.ts +36 -0
- package/src/components/extended-fab/extended-fab.ts +125 -0
- package/src/components/extended-fab/index.ts +4 -0
- package/src/components/extended-fab/types.ts +287 -0
- package/src/components/fab/_styles.scss +225 -0
- package/src/components/fab/api.ts +97 -0
- package/src/components/fab/config.ts +94 -0
- package/src/components/fab/constants.ts +41 -0
- package/src/components/fab/fab.ts +67 -0
- package/src/components/fab/index.ts +4 -0
- package/src/components/fab/types.ts +234 -0
- package/src/components/navigation/_styles.scss +1 -0
- package/src/components/navigation/api.ts +78 -50
- package/src/components/navigation/features/items.ts +280 -0
- package/src/components/navigation/nav-item.ts +72 -23
- package/src/components/navigation/navigation.ts +54 -2
- package/src/components/navigation/types.ts +210 -188
- package/src/components/search/_styles.scss +306 -0
- package/src/components/search/api.ts +203 -0
- package/src/components/search/config.ts +87 -0
- package/src/components/search/constants.ts +21 -0
- package/src/components/search/features/index.ts +4 -0
- package/src/components/search/features/search.ts +718 -0
- package/src/components/search/features/states.ts +165 -0
- package/src/components/search/features/structure.ts +198 -0
- package/src/components/search/index.ts +10 -0
- package/src/components/search/search.ts +52 -0
- package/src/components/search/types.ts +163 -0
- package/src/components/segmented-button/_styles.scss +117 -0
- package/src/components/segmented-button/config.ts +67 -0
- package/src/components/segmented-button/constants.ts +42 -0
- package/src/components/segmented-button/index.ts +4 -0
- package/src/components/segmented-button/segment.ts +155 -0
- package/src/components/segmented-button/segmented-button.ts +250 -0
- package/src/components/segmented-button/types.ts +219 -0
- package/src/components/slider/_styles.scss +83 -24
- package/src/components/slider/accessibility.md +5 -5
- package/src/components/slider/api.ts +41 -120
- package/src/components/slider/config.ts +51 -47
- package/src/components/slider/features/handlers.ts +495 -0
- package/src/components/slider/features/index.ts +1 -2
- package/src/components/slider/features/slider.ts +66 -84
- package/src/components/slider/features/states.ts +195 -0
- package/src/components/slider/features/structure.ts +136 -206
- package/src/components/slider/features/ui.ts +145 -206
- package/src/components/slider/index.ts +2 -11
- package/src/components/slider/slider.ts +9 -12
- package/src/components/slider/types.ts +39 -24
- package/src/components/switch/_styles.scss +0 -2
- package/src/components/tabs/_styles.scss +94 -32
- package/src/components/tabs/features.ts +4 -2
- package/src/components/tabs/indicator.ts +73 -13
- package/src/components/tabs/types.ts +10 -2
- package/src/components/timepicker/README.md +277 -0
- package/src/components/timepicker/_styles.scss +451 -0
- package/src/components/timepicker/api.ts +632 -0
- package/src/components/timepicker/clockdial.ts +482 -0
- package/src/components/timepicker/config.ts +130 -0
- package/src/components/timepicker/constants.ts +138 -0
- package/src/components/timepicker/index.ts +8 -0
- package/src/components/timepicker/render.ts +613 -0
- package/src/components/timepicker/timepicker.ts +117 -0
- package/src/components/timepicker/types.ts +336 -0
- package/src/components/timepicker/utils.ts +241 -0
- package/src/components/top-app-bar/_styles.scss +225 -0
- package/src/components/top-app-bar/config.ts +83 -0
- package/src/components/top-app-bar/index.ts +11 -0
- package/src/components/top-app-bar/top-app-bar.ts +316 -0
- package/src/components/top-app-bar/types.ts +140 -0
- package/src/core/build/_ripple.scss +6 -6
- package/src/core/build/ripple.ts +72 -95
- package/src/core/compose/features/icon.ts +3 -1
- package/src/core/compose/features/ripple.ts +4 -1
- package/src/core/compose/features/textlabel.ts +26 -2
- package/src/core/dom/create.ts +5 -0
- package/src/index.ts +9 -0
- package/src/styles/abstract/_theme.scss +9 -1
- package/src/styles/themes/_autumn.scss +21 -0
- package/src/styles/themes/_base-theme.scss +61 -0
- package/src/styles/themes/_baseline.scss +58 -0
- package/src/styles/themes/_bluekhaki.scss +125 -0
- package/src/styles/themes/_brownbeige.scss +125 -0
- package/src/styles/themes/_browngreen.scss +125 -0
- package/src/styles/themes/_forest.scss +6 -0
- package/src/styles/themes/_greenbeige.scss +125 -0
- package/src/styles/themes/_material.scss +125 -0
- package/src/styles/themes/_ocean.scss +6 -0
- package/src/styles/themes/_sageivory.scss +125 -0
- package/src/styles/themes/_spring.scss +6 -0
- package/src/styles/themes/_summer.scss +5 -0
- package/src/styles/themes/_sunset.scss +5 -0
- package/src/styles/themes/_tealcaramel.scss +125 -0
- package/src/styles/themes/_winter.scss +6 -0
- package/src/components/navigation/features/items.js +0 -192
- package/src/components/slider/features/appearance.ts +0 -94
- package/src/components/slider/features/disabled.ts +0 -68
- package/src/components/slider/features/events.ts +0 -164
- package/src/components/slider/features/interactions.ts +0 -396
- package/src/components/slider/features/keyboard.ts +0 -233
- package/src/core/collection/adapters/mongodb.js +0 -232
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// src/components/slider/features/slider.ts
|
|
1
|
+
// src/components/slider/features/slider.ts
|
|
2
2
|
import { SLIDER_EVENTS } from '../constants';
|
|
3
3
|
import { SliderConfig } from '../types';
|
|
4
4
|
import { createUiHelpers } from './ui';
|
|
5
|
-
import {
|
|
6
|
-
import { createKeyboardHandlers } from './keyboard';
|
|
7
|
-
import { createEventHelpers } from './events';
|
|
5
|
+
import { createHandlers } from './handlers';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Add main slider functionality to component
|
|
@@ -16,20 +14,18 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
16
14
|
if (!component.events) {
|
|
17
15
|
component.events = {
|
|
18
16
|
listeners: {},
|
|
19
|
-
on
|
|
20
|
-
if (!this.listeners[event])
|
|
21
|
-
this.listeners[event] = [];
|
|
22
|
-
}
|
|
17
|
+
on(event, handler) {
|
|
18
|
+
if (!this.listeners[event]) this.listeners[event] = [];
|
|
23
19
|
this.listeners[event].push(handler);
|
|
24
20
|
return this;
|
|
25
21
|
},
|
|
26
|
-
off
|
|
22
|
+
off(event, handler) {
|
|
27
23
|
if (this.listeners[event]) {
|
|
28
24
|
this.listeners[event] = this.listeners[event].filter(h => h !== handler);
|
|
29
25
|
}
|
|
30
26
|
return this;
|
|
31
27
|
},
|
|
32
|
-
trigger
|
|
28
|
+
trigger(event, data) {
|
|
33
29
|
if (this.listeners[event]) {
|
|
34
30
|
this.listeners[event].forEach(handler => handler(data));
|
|
35
31
|
}
|
|
@@ -47,25 +43,32 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
47
43
|
step: config.step !== undefined ? config.step : 1,
|
|
48
44
|
dragging: false,
|
|
49
45
|
activeBubble: null,
|
|
50
|
-
|
|
46
|
+
activeHandle: null,
|
|
51
47
|
ticks: [],
|
|
52
|
-
|
|
48
|
+
valueHideTimer: null,
|
|
53
49
|
component
|
|
54
50
|
};
|
|
55
51
|
|
|
56
|
-
// Create
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
// Create event helpers
|
|
53
|
+
const eventHelpers = {
|
|
54
|
+
triggerEvent(eventName, originalEvent = null) {
|
|
55
|
+
const eventData = {
|
|
56
|
+
slider: state.component,
|
|
57
|
+
value: state.value,
|
|
58
|
+
secondValue: state.secondValue,
|
|
59
|
+
originalEvent,
|
|
60
|
+
preventDefault: () => { eventData.defaultPrevented = true; },
|
|
61
|
+
defaultPrevented: false
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
state.component.events.trigger(eventName, eventData);
|
|
65
|
+
return eventData;
|
|
66
|
+
}
|
|
64
67
|
};
|
|
65
68
|
|
|
66
|
-
// Create
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
+
// Create UI helpers and handlers
|
|
70
|
+
const uiHelpers = createUiHelpers(config, state);
|
|
71
|
+
const handlers = createHandlers(config, state, uiHelpers, eventHelpers);
|
|
69
72
|
|
|
70
73
|
// Initialize slider
|
|
71
74
|
const initSlider = () => {
|
|
@@ -79,52 +82,42 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
const {
|
|
85
|
+
const { handle, secondHandle } = component.structure;
|
|
83
86
|
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
secondThumb.setAttribute('aria-valuemin', String(state.min));
|
|
95
|
-
secondThumb.setAttribute('aria-valuemax', String(state.max));
|
|
96
|
-
secondThumb.setAttribute('aria-valuenow', String(state.secondValue));
|
|
87
|
+
if (handle) {
|
|
88
|
+
handle.setAttribute('aria-valuemin', String(state.min));
|
|
89
|
+
handle.setAttribute('aria-valuemax', String(state.max));
|
|
90
|
+
handle.setAttribute('aria-valuenow', String(state.value));
|
|
91
|
+
|
|
92
|
+
if (config.range && secondHandle && state.secondValue !== null) {
|
|
93
|
+
secondHandle.setAttribute('aria-valuemin', String(state.min));
|
|
94
|
+
secondHandle.setAttribute('aria-valuemax', String(state.max));
|
|
95
|
+
secondHandle.setAttribute('aria-valuenow', String(state.secondValue));
|
|
96
|
+
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
//
|
|
99
|
+
// Initial UI update
|
|
100
100
|
uiHelpers.updateUi();
|
|
101
101
|
|
|
102
102
|
// Generate ticks if needed
|
|
103
103
|
if (config.ticks || config.tickLabels) {
|
|
104
104
|
uiHelpers.generateTicks();
|
|
105
|
-
uiHelpers.updateTicks();
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
// Setup event listeners
|
|
109
|
-
|
|
108
|
+
handlers.setupEventListeners();
|
|
110
109
|
|
|
111
|
-
// Force one more UI update after a delay to ensure
|
|
112
|
-
// This is especially important for range sliders
|
|
110
|
+
// Force one more UI update after a delay to ensure proper positioning
|
|
113
111
|
setTimeout(() => {
|
|
114
112
|
uiHelpers.updateUi();
|
|
115
113
|
}, 50);
|
|
116
114
|
};
|
|
117
115
|
|
|
118
|
-
//
|
|
119
|
-
const cleanup = () => {
|
|
120
|
-
eventHelpers.cleanupEventListeners(interactionHandlers, keyboardHandlers);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// Register with lifecycle
|
|
116
|
+
// Register with lifecycle if available
|
|
124
117
|
if (component.lifecycle) {
|
|
125
118
|
const originalDestroy = component.lifecycle.destroy || (() => {});
|
|
126
119
|
component.lifecycle.destroy = () => {
|
|
127
|
-
|
|
120
|
+
handlers.cleanupEventListeners();
|
|
128
121
|
originalDestroy();
|
|
129
122
|
};
|
|
130
123
|
}
|
|
@@ -132,24 +125,21 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
132
125
|
// Initialize slider
|
|
133
126
|
initSlider();
|
|
134
127
|
|
|
135
|
-
// Return enhanced component
|
|
136
|
-
|
|
128
|
+
// Return enhanced component
|
|
129
|
+
return {
|
|
137
130
|
...component,
|
|
138
131
|
slider: {
|
|
139
132
|
/**
|
|
140
133
|
* Sets slider value
|
|
141
134
|
* @param value New value
|
|
142
135
|
* @param triggerEvent Whether to trigger change event
|
|
136
|
+
* @returns Slider controller for chaining
|
|
143
137
|
*/
|
|
144
138
|
setValue(value, triggerEvent = true) {
|
|
145
|
-
// Validate and set value
|
|
146
139
|
const newValue = uiHelpers.clamp(value, state.min, state.max);
|
|
147
140
|
state.value = newValue;
|
|
148
|
-
|
|
149
|
-
// Update UI
|
|
150
141
|
uiHelpers.updateUi();
|
|
151
142
|
|
|
152
|
-
// Trigger events if needed
|
|
153
143
|
if (triggerEvent) {
|
|
154
144
|
eventHelpers.triggerEvent(SLIDER_EVENTS.CHANGE);
|
|
155
145
|
}
|
|
@@ -169,18 +159,15 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
169
159
|
* Sets secondary slider value (for range slider)
|
|
170
160
|
* @param value New secondary value
|
|
171
161
|
* @param triggerEvent Whether to trigger change event
|
|
162
|
+
* @returns Slider controller for chaining
|
|
172
163
|
*/
|
|
173
164
|
setSecondValue(value, triggerEvent = true) {
|
|
174
165
|
if (!config.range) return this;
|
|
175
166
|
|
|
176
|
-
// Validate and set value
|
|
177
167
|
const newValue = uiHelpers.clamp(value, state.min, state.max);
|
|
178
168
|
state.secondValue = newValue;
|
|
179
|
-
|
|
180
|
-
// Update UI
|
|
181
169
|
uiHelpers.updateUi();
|
|
182
170
|
|
|
183
|
-
// Trigger events if needed
|
|
184
171
|
if (triggerEvent) {
|
|
185
172
|
eventHelpers.triggerEvent(SLIDER_EVENTS.CHANGE);
|
|
186
173
|
}
|
|
@@ -199,23 +186,23 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
199
186
|
/**
|
|
200
187
|
* Sets slider minimum value
|
|
201
188
|
* @param min New minimum value
|
|
189
|
+
* @returns Slider controller for chaining
|
|
202
190
|
*/
|
|
203
191
|
setMin(min) {
|
|
204
192
|
state.min = min;
|
|
205
193
|
|
|
206
194
|
// Update ARIA attributes
|
|
207
195
|
component.element.setAttribute('aria-valuemin', String(min));
|
|
208
|
-
component.structure.
|
|
209
|
-
|
|
210
|
-
if (config.range && component.structure.secondThumb) {
|
|
211
|
-
component.structure.secondThumb.setAttribute('aria-valuemin', String(min));
|
|
196
|
+
if (component.structure.handle) {
|
|
197
|
+
component.structure.handle.setAttribute('aria-valuemin', String(min));
|
|
212
198
|
}
|
|
213
199
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
state.value = min;
|
|
200
|
+
if (config.range && component.structure.secondHandle) {
|
|
201
|
+
component.structure.secondHandle.setAttribute('aria-valuemin', String(min));
|
|
217
202
|
}
|
|
218
203
|
|
|
204
|
+
// Clamp values to new min
|
|
205
|
+
if (state.value < min) state.value = min;
|
|
219
206
|
if (config.range && state.secondValue !== null && state.secondValue < min) {
|
|
220
207
|
state.secondValue = min;
|
|
221
208
|
}
|
|
@@ -225,9 +212,7 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
225
212
|
uiHelpers.generateTicks();
|
|
226
213
|
}
|
|
227
214
|
|
|
228
|
-
// Update UI
|
|
229
215
|
uiHelpers.updateUi();
|
|
230
|
-
|
|
231
216
|
return this;
|
|
232
217
|
},
|
|
233
218
|
|
|
@@ -242,23 +227,23 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
242
227
|
/**
|
|
243
228
|
* Sets slider maximum value
|
|
244
229
|
* @param max New maximum value
|
|
230
|
+
* @returns Slider controller for chaining
|
|
245
231
|
*/
|
|
246
232
|
setMax(max) {
|
|
247
233
|
state.max = max;
|
|
248
234
|
|
|
249
235
|
// Update ARIA attributes
|
|
250
236
|
component.element.setAttribute('aria-valuemax', String(max));
|
|
251
|
-
component.structure.
|
|
252
|
-
|
|
253
|
-
if (config.range && component.structure.secondThumb) {
|
|
254
|
-
component.structure.secondThumb.setAttribute('aria-valuemax', String(max));
|
|
237
|
+
if (component.structure.handle) {
|
|
238
|
+
component.structure.handle.setAttribute('aria-valuemax', String(max));
|
|
255
239
|
}
|
|
256
240
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
state.value = max;
|
|
241
|
+
if (config.range && component.structure.secondHandle) {
|
|
242
|
+
component.structure.secondHandle.setAttribute('aria-valuemax', String(max));
|
|
260
243
|
}
|
|
261
244
|
|
|
245
|
+
// Clamp values to new max
|
|
246
|
+
if (state.value > max) state.value = max;
|
|
262
247
|
if (config.range && state.secondValue !== null && state.secondValue > max) {
|
|
263
248
|
state.secondValue = max;
|
|
264
249
|
}
|
|
@@ -268,9 +253,7 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
268
253
|
uiHelpers.generateTicks();
|
|
269
254
|
}
|
|
270
255
|
|
|
271
|
-
// Update UI
|
|
272
256
|
uiHelpers.updateUi();
|
|
273
|
-
|
|
274
257
|
return this;
|
|
275
258
|
},
|
|
276
259
|
|
|
@@ -285,16 +268,15 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
285
268
|
/**
|
|
286
269
|
* Sets slider step size
|
|
287
270
|
* @param step New step size
|
|
271
|
+
* @returns Slider controller for chaining
|
|
288
272
|
*/
|
|
289
273
|
setStep(step) {
|
|
290
274
|
state.step = step;
|
|
291
275
|
|
|
292
276
|
// Add or remove discrete class
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
component.element.classList.remove(`${component.getClass('slider')}--discrete`);
|
|
297
|
-
}
|
|
277
|
+
component.element.classList[step > 0 ? 'add' : 'remove'](
|
|
278
|
+
`${component.getClass('slider')}--discrete`
|
|
279
|
+
);
|
|
298
280
|
|
|
299
281
|
// Regenerate ticks if needed
|
|
300
282
|
if (config.ticks || config.tickLabels) {
|
|
@@ -315,6 +297,7 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
315
297
|
|
|
316
298
|
/**
|
|
317
299
|
* Regenerate tick marks and labels
|
|
300
|
+
* @returns Slider controller for chaining
|
|
318
301
|
*/
|
|
319
302
|
regenerateTicks() {
|
|
320
303
|
uiHelpers.generateTicks();
|
|
@@ -324,6 +307,7 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
324
307
|
|
|
325
308
|
/**
|
|
326
309
|
* Update all UI elements
|
|
310
|
+
* @returns Slider controller for chaining
|
|
327
311
|
*/
|
|
328
312
|
updateUi() {
|
|
329
313
|
uiHelpers.updateUi();
|
|
@@ -331,6 +315,4 @@ export const withSlider = (config: SliderConfig) => component => {
|
|
|
331
315
|
}
|
|
332
316
|
}
|
|
333
317
|
};
|
|
334
|
-
|
|
335
|
-
return enhancedComponent;
|
|
336
318
|
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// src/components/slider/features/states.ts
|
|
2
|
+
import { SLIDER_COLORS, SLIDER_SIZES } from '../constants';
|
|
3
|
+
import { SliderConfig } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Add state management features to slider component
|
|
7
|
+
* Combines appearance and disabled functionality into a single feature
|
|
8
|
+
*
|
|
9
|
+
* @param config Slider configuration
|
|
10
|
+
* @returns Component enhancer with state management features
|
|
11
|
+
*/
|
|
12
|
+
export const withStates = (config: SliderConfig) => component => {
|
|
13
|
+
// Track initial disabled state
|
|
14
|
+
const isDisabled = config.disabled === true;
|
|
15
|
+
|
|
16
|
+
// Apply initial disabled state if needed
|
|
17
|
+
if (isDisabled) {
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
disableComponent();
|
|
20
|
+
}, 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Disables the component
|
|
25
|
+
*/
|
|
26
|
+
function disableComponent() {
|
|
27
|
+
component.element.classList.add(`${component.getClass('slider')}--disabled`);
|
|
28
|
+
component.element.setAttribute('aria-disabled', 'true');
|
|
29
|
+
|
|
30
|
+
// Ensure handles cannot receive focus when disabled
|
|
31
|
+
if (component.structure?.handle) {
|
|
32
|
+
component.structure.handle.tabIndex = -1;
|
|
33
|
+
component.structure.handle.setAttribute('aria-disabled', 'true');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (config.range && component.structure?.secondHandle) {
|
|
37
|
+
component.structure.secondHandle.tabIndex = -1;
|
|
38
|
+
component.structure.secondHandle.setAttribute('aria-disabled', 'true');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Enables the component
|
|
44
|
+
*/
|
|
45
|
+
function enableComponent() {
|
|
46
|
+
component.element.classList.remove(`${component.getClass('slider')}--disabled`);
|
|
47
|
+
component.element.setAttribute('aria-disabled', 'false');
|
|
48
|
+
|
|
49
|
+
// Re-enable focus on handles
|
|
50
|
+
if (component.structure?.handle) {
|
|
51
|
+
component.structure.handle.tabIndex = 0;
|
|
52
|
+
component.structure.handle.setAttribute('aria-disabled', 'false');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (config.range && component.structure?.secondHandle) {
|
|
56
|
+
component.structure.secondHandle.tabIndex = 0;
|
|
57
|
+
component.structure.secondHandle.setAttribute('aria-disabled', 'false');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Gets the active color class
|
|
63
|
+
*/
|
|
64
|
+
function getActiveColor() {
|
|
65
|
+
return Object.values(SLIDER_COLORS).find(colorName =>
|
|
66
|
+
component.element.classList.contains(`${component.getClass('slider')}--${colorName}`)
|
|
67
|
+
) || SLIDER_COLORS.PRIMARY;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets the active size class
|
|
72
|
+
*/
|
|
73
|
+
function getActiveSize() {
|
|
74
|
+
return Object.values(SLIDER_SIZES).find(sizeName =>
|
|
75
|
+
component.element.classList.contains(`${component.getClass('slider')}--${sizeName}`)
|
|
76
|
+
) || SLIDER_SIZES.MEDIUM;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Return enhanced component
|
|
80
|
+
return {
|
|
81
|
+
...component,
|
|
82
|
+
|
|
83
|
+
// Disabled state management
|
|
84
|
+
disabled: {
|
|
85
|
+
/**
|
|
86
|
+
* Enables the component
|
|
87
|
+
* @returns Disabled manager for chaining
|
|
88
|
+
*/
|
|
89
|
+
enable() {
|
|
90
|
+
enableComponent();
|
|
91
|
+
return this;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Disables the component
|
|
96
|
+
* @returns Disabled manager for chaining
|
|
97
|
+
*/
|
|
98
|
+
disable() {
|
|
99
|
+
disableComponent();
|
|
100
|
+
return this;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Checks if component is disabled
|
|
105
|
+
* @returns True if disabled
|
|
106
|
+
*/
|
|
107
|
+
isDisabled() {
|
|
108
|
+
return component.element.classList.contains(`${component.getClass('slider')}--disabled`);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
// Appearance management
|
|
113
|
+
appearance: {
|
|
114
|
+
/**
|
|
115
|
+
* Sets slider color
|
|
116
|
+
* @param color Color variant
|
|
117
|
+
* @returns Appearance manager for chaining
|
|
118
|
+
*/
|
|
119
|
+
setColor(color: keyof typeof SLIDER_COLORS | SLIDER_COLORS) {
|
|
120
|
+
// Remove existing color classes
|
|
121
|
+
Object.values(SLIDER_COLORS).forEach(colorName => {
|
|
122
|
+
component.element.classList.remove(`${component.getClass('slider')}--${colorName}`);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Add new color class if not primary (default)
|
|
126
|
+
if (color !== SLIDER_COLORS.PRIMARY) {
|
|
127
|
+
component.element.classList.add(`${component.getClass('slider')}--${color}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Gets slider color
|
|
135
|
+
* @returns Current color name
|
|
136
|
+
*/
|
|
137
|
+
getColor() {
|
|
138
|
+
return getActiveColor();
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets slider size
|
|
143
|
+
* @param size Size variant
|
|
144
|
+
* @returns Appearance manager for chaining
|
|
145
|
+
*/
|
|
146
|
+
setSize(size: keyof typeof SLIDER_SIZES | SLIDER_SIZES) {
|
|
147
|
+
// Remove existing size classes
|
|
148
|
+
Object.values(SLIDER_SIZES).forEach(sizeName => {
|
|
149
|
+
component.element.classList.remove(`${component.getClass('slider')}--${sizeName}`);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Add new size class if not medium (default)
|
|
153
|
+
if (size !== SLIDER_SIZES.MEDIUM) {
|
|
154
|
+
component.element.classList.add(`${component.getClass('slider')}--${size}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return this;
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Gets slider size
|
|
162
|
+
* @returns Current size name
|
|
163
|
+
*/
|
|
164
|
+
getSize() {
|
|
165
|
+
return getActiveSize();
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Shows or hides tick marks
|
|
170
|
+
* @param show Whether to show ticks
|
|
171
|
+
* @returns Appearance manager for chaining
|
|
172
|
+
*/
|
|
173
|
+
showTicks(show: boolean) {
|
|
174
|
+
config.ticks = show;
|
|
175
|
+
|
|
176
|
+
// Regenerate ticks if slider is initialized
|
|
177
|
+
if (component.slider) {
|
|
178
|
+
component.slider.regenerateTicks();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return this;
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Shows or hides current value bubble during interaction
|
|
186
|
+
* @param show Whether to show value bubble
|
|
187
|
+
* @returns Appearance manager for chaining
|
|
188
|
+
*/
|
|
189
|
+
showCurrentValue(show: boolean) {
|
|
190
|
+
config.showValue = show;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
};
|