mtrl 0.2.6 → 0.2.8
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/demo/build.ts +349 -0
- package/demo/index.html +110 -0
- package/demo/main.js +448 -0
- package/demo/styles.css +239 -0
- package/index.ts +18 -0
- package/package.json +14 -3
- package/server.ts +86 -0
- package/src/components/badge/api.ts +70 -63
- package/src/components/badge/badge.ts +16 -2
- package/src/components/badge/config.ts +66 -13
- package/src/components/badge/features.ts +51 -42
- package/src/components/badge/index.ts +27 -2
- package/src/components/badge/types.ts +62 -30
- package/src/components/bottom-app-bar/bottom-app-bar.ts +154 -0
- package/src/components/bottom-app-bar/config.ts +29 -0
- package/src/components/bottom-app-bar/index.ts +17 -0
- package/src/components/bottom-app-bar/types.ts +114 -0
- package/src/components/button/api.ts +5 -0
- package/src/components/button/button.ts +0 -1
- package/src/components/button/config.ts +6 -2
- package/src/components/button/index.ts +10 -2
- package/src/components/button/types.ts +20 -2
- package/src/components/card/card.ts +13 -25
- package/src/components/card/config.ts +83 -30
- package/src/components/card/content.ts +8 -10
- package/src/components/card/features.ts +4 -3
- package/src/components/card/index.ts +29 -2
- package/src/components/card/types.ts +33 -22
- package/src/components/checkbox/config.ts +3 -4
- package/src/components/checkbox/index.ts +1 -2
- package/src/components/checkbox/types.ts +12 -3
- package/src/components/chip/api.ts +170 -221
- package/src/components/chip/chip.ts +34 -302
- package/src/components/chip/config.ts +1 -2
- package/src/components/chip/index.ts +10 -2
- package/src/components/chip/types.ts +224 -35
- package/src/components/datepicker/api.ts +265 -0
- package/src/components/datepicker/config.ts +141 -0
- package/src/components/datepicker/datepicker.ts +341 -0
- package/src/components/datepicker/index.ts +12 -0
- package/src/components/datepicker/render.ts +450 -0
- package/src/components/datepicker/types.ts +397 -0
- package/src/components/datepicker/utils.ts +289 -0
- package/src/components/dialog/api.ts +55 -21
- package/src/components/dialog/config.ts +12 -9
- package/src/components/dialog/dialog.ts +6 -3
- package/src/components/dialog/features.ts +345 -151
- package/src/components/dialog/index.ts +38 -8
- package/src/components/dialog/types.ts +40 -14
- 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 +9 -0
- package/src/components/divider/types.ts +55 -0
- package/src/components/extended-fab/api.ts +141 -0
- package/src/components/extended-fab/config.ts +112 -0
- package/src/components/extended-fab/extended-fab.ts +125 -0
- package/src/components/extended-fab/index.ts +9 -0
- package/src/components/extended-fab/types.ts +304 -0
- package/src/components/fab/api.ts +97 -0
- package/src/components/fab/config.ts +93 -0
- package/src/components/fab/fab.ts +67 -0
- package/src/components/fab/index.ts +9 -0
- package/src/components/fab/types.ts +251 -0
- package/src/components/list/config.ts +4 -5
- package/src/components/list/features.ts +6 -7
- package/src/components/list/index.ts +7 -9
- package/src/components/list/list-item.ts +12 -13
- package/src/components/list/types.ts +50 -5
- package/src/components/list/utils.ts +30 -3
- package/src/components/menu/features/items-manager.ts +9 -9
- package/src/components/menu/features/positioning.ts +7 -7
- package/src/components/menu/features/visibility.ts +7 -7
- package/src/components/menu/index.ts +7 -9
- package/src/components/menu/menu-item.ts +6 -6
- package/src/components/menu/menu.ts +22 -0
- package/src/components/menu/types.ts +29 -10
- package/src/components/menu/utils.ts +67 -0
- package/src/components/navigation/api.ts +78 -50
- package/src/components/navigation/config.ts +22 -10
- package/src/components/navigation/features/items.ts +284 -0
- package/src/components/navigation/index.ts +0 -6
- package/src/components/navigation/nav-item.ts +70 -33
- package/src/components/navigation/navigation.ts +53 -3
- package/src/components/navigation/types.ts +117 -70
- package/src/components/progress/api.ts +2 -3
- package/src/components/progress/config.ts +2 -3
- package/src/components/progress/index.ts +0 -1
- package/src/components/progress/progress.ts +1 -2
- package/src/components/progress/types.ts +186 -33
- package/src/components/radios/config.ts +1 -1
- package/src/components/radios/index.ts +0 -1
- package/src/components/radios/types.ts +0 -7
- package/src/components/search/api.ts +203 -0
- package/src/components/search/config.ts +86 -0
- package/src/components/search/features/index.ts +4 -0
- package/src/components/search/features/search.ts +717 -0
- package/src/components/search/features/states.ts +169 -0
- package/src/components/search/features/structure.ts +197 -0
- package/src/components/search/index.ts +7 -0
- package/src/components/search/search.ts +52 -0
- package/src/components/search/types.ts +175 -0
- package/src/components/segmented-button/config.ts +80 -0
- package/src/components/segmented-button/index.ts +4 -0
- package/src/components/segmented-button/segment.ts +154 -0
- package/src/components/segmented-button/segmented-button.ts +249 -0
- package/src/components/segmented-button/types.ts +254 -0
- 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 +67 -26
- package/src/components/snackbar/config.ts +2 -3
- package/src/components/snackbar/constants.ts +0 -32
- package/src/components/snackbar/index.ts +0 -1
- package/src/components/snackbar/position.ts +9 -1
- package/src/components/snackbar/types.ts +122 -46
- package/src/components/switch/config.ts +2 -3
- package/src/components/switch/index.ts +0 -1
- package/src/components/switch/types.ts +3 -2
- package/src/components/tabs/config.ts +3 -4
- package/src/components/tabs/features.ts +4 -2
- package/src/components/tabs/index.ts +0 -15
- package/src/components/tabs/indicator.ts +73 -13
- package/src/components/tabs/tab-api.ts +12 -4
- package/src/components/tabs/tab.ts +18 -6
- package/src/components/tabs/types.ts +23 -5
- package/src/components/textfield/config.ts +2 -3
- package/src/components/textfield/index.ts +0 -1
- package/src/components/textfield/types.ts +17 -3
- package/src/components/timepicker/README.md +277 -0
- package/src/components/timepicker/api.ts +632 -0
- package/src/components/timepicker/clockdial.ts +482 -0
- package/src/components/timepicker/config.ts +228 -0
- package/src/components/timepicker/index.ts +3 -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/tooltip/api.ts +1 -1
- package/src/components/tooltip/config.ts +27 -6
- package/src/components/tooltip/index.ts +0 -1
- package/src/components/tooltip/types.ts +13 -3
- 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 +23 -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/components/_badge.scss +182 -0
- package/src/styles/components/_bottom-app-bar.scss +103 -0
- package/src/{components/button/_styles.scss → styles/components/_button.scss} +0 -10
- package/src/{components/checkbox/_styles.scss → styles/components/_checkbox.scss} +0 -2
- package/src/styles/components/_datepicker.scss +358 -0
- package/src/styles/components/_dialog.scss +259 -0
- package/src/styles/components/_divider.scss +57 -0
- package/src/styles/components/_extended-fab.scss +267 -0
- package/src/styles/components/_fab.scss +225 -0
- package/src/{components/navigation/_styles.scss → styles/components/_navigation.scss} +1 -0
- package/src/styles/components/_search.scss +306 -0
- package/src/styles/components/_segmented-button.scss +117 -0
- package/src/{components/slider/_styles.scss → styles/components/_slider.scss} +83 -24
- package/src/{components/switch/_styles.scss → styles/components/_switch.scss} +0 -2
- package/src/{components/tabs/_styles.scss → styles/components/_tabs.scss} +95 -33
- package/src/{components/textfield/_styles.scss → styles/components/_textfield.scss} +70 -67
- package/src/styles/components/_timepicker.scss +451 -0
- package/src/styles/components/_top-app-bar.scss +225 -0
- package/src/styles/main.scss +98 -49
- 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/badge/_styles.scss +0 -174
- package/src/components/badge/constants.ts +0 -30
- package/src/components/button/constants.ts +0 -11
- package/src/components/card/constants.ts +0 -84
- package/src/components/dialog/_styles.scss +0 -213
- package/src/components/dialog/constants.ts +0 -32
- package/src/components/menu/constants.ts +0 -154
- package/src/components/navigation/constants.ts +0 -200
- package/src/components/navigation/features/items.js +0 -192
- package/src/components/progress/constants.ts +0 -29
- 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/components/switch/constants.ts +0 -80
- package/src/components/tabs/constants.ts +0 -89
- package/src/core/collection/adapters/mongodb.js +0 -232
- /package/src/{components/card/_styles.scss → styles/components/_card.scss} +0 -0
- /package/src/{components/carousel/_styles.scss → styles/components/_carousel.scss} +0 -0
- /package/src/{components/chip/_styles.scss → styles/components/_chip.scss} +0 -0
- /package/src/{components/list/_styles.scss → styles/components/_list.scss} +0 -0
- /package/src/{components/menu/_styles.scss → styles/components/_menu.scss} +0 -0
- /package/src/{components/progress/_styles.scss → styles/components/_progress.scss} +0 -0
- /package/src/{components/radios/_styles.scss → styles/components/_radios.scss} +0 -0
- /package/src/{components/sheet/_styles.scss → styles/components/_sheet.scss} +0 -0
- /package/src/{components/snackbar/_styles.scss → styles/components/_snackbar.scss} +0 -0
- /package/src/{components/tooltip/_styles.scss → styles/components/_tooltip.scss} +0 -0
- /package/src/styles/utilities/{_color.scss → _colors.scss} +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// src/components/slider/features/structure.ts
|
|
2
2
|
import { SLIDER_COLORS, SLIDER_SIZES } from '../constants';
|
|
3
3
|
import { SliderConfig } from '../types';
|
|
4
|
+
import createLayout from '../../../core/layout';
|
|
5
|
+
import { createElement } from '../../../core/dom/create';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* Creates the slider DOM structure
|
|
8
|
+
* Creates the slider DOM structure using layout system
|
|
7
9
|
* @param config Slider configuration
|
|
8
10
|
* @returns Component enhancer with DOM structure
|
|
9
11
|
*/
|
|
@@ -11,241 +13,169 @@ export const withStructure = (config: SliderConfig) => component => {
|
|
|
11
13
|
// Set default values
|
|
12
14
|
const min = config.min || 0;
|
|
13
15
|
const max = config.max || 100;
|
|
14
|
-
const range = max - min;
|
|
15
16
|
const value = config.value !== undefined ? config.value : min;
|
|
16
17
|
const secondValue = config.secondValue !== undefined ? config.secondValue : null;
|
|
17
18
|
const isRangeSlider = config.range && secondValue !== null;
|
|
18
19
|
const isDisabled = config.disabled === true;
|
|
19
20
|
|
|
20
|
-
//
|
|
21
|
-
const getPercentage = (val) => ((val - min) / range) * 100;
|
|
22
|
-
const valuePercent = getPercentage(value);
|
|
23
|
-
|
|
24
|
-
// Create track element and segments
|
|
25
|
-
const track = createElement('slider-track');
|
|
26
|
-
const remainingTrack = createElement('slider-remaining-track');
|
|
27
|
-
const startTrack = createElement('slider-start-track');
|
|
28
|
-
const activeTrack = createElement('slider-active-track');
|
|
29
|
-
|
|
30
|
-
// Create ticks container
|
|
31
|
-
const ticksContainer = createElement('slider-ticks-container');
|
|
32
|
-
|
|
33
|
-
// Create dots for track ends
|
|
34
|
-
const startDot = createElement('slider-dot');
|
|
35
|
-
startDot.classList.add(component.getClass('slider-dot--start'));
|
|
36
|
-
|
|
37
|
-
const endDot = createElement('slider-dot');
|
|
38
|
-
endDot.classList.add(component.getClass('slider-dot--end'));
|
|
39
|
-
|
|
40
|
-
// Create value bubble and format the value
|
|
21
|
+
// Format the values
|
|
41
22
|
const formatter = config.valueFormatter || (val => val.toString());
|
|
42
|
-
const valueBubble = createElement('slider-value');
|
|
43
|
-
valueBubble.textContent = formatter(value);
|
|
44
|
-
|
|
45
|
-
// Create thumb element with improved accessibility attributes
|
|
46
|
-
const thumb = createElement('slider-thumb');
|
|
47
|
-
thumb.setAttribute('role', 'slider');
|
|
48
|
-
thumb.setAttribute('aria-valuemin', String(min));
|
|
49
|
-
thumb.setAttribute('aria-valuemax', String(max));
|
|
50
|
-
thumb.setAttribute('aria-valuenow', String(value));
|
|
51
|
-
thumb.setAttribute('aria-orientation', 'horizontal');
|
|
52
|
-
|
|
53
|
-
// Set tabindex based on disabled state
|
|
54
|
-
thumb.setAttribute('tabindex', isDisabled ? '-1' : '0');
|
|
55
|
-
if (isDisabled) {
|
|
56
|
-
thumb.setAttribute('aria-disabled', 'true');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Set initial thumb position
|
|
60
|
-
thumb.style.left = `${valuePercent}%`;
|
|
61
|
-
|
|
62
|
-
// Calculate padding adjustment (8px equivalent as percentage)
|
|
63
|
-
const paddingAdjustment = 8; // 8px padding
|
|
64
|
-
const estimatedTrackSize = 300; // A reasonable guess at track width
|
|
65
|
-
const paddingPercent = (paddingAdjustment / estimatedTrackSize) * 100;
|
|
66
|
-
|
|
67
|
-
// Create second thumb and value bubble for range slider
|
|
68
|
-
let secondThumb = null;
|
|
69
|
-
let secondValueBubble = null;
|
|
70
23
|
|
|
24
|
+
// Get prefixed class names
|
|
25
|
+
const getClass = (className) => component.getClass(className);
|
|
26
|
+
|
|
27
|
+
// Define slider structure
|
|
28
|
+
const structure = [
|
|
29
|
+
[createElement, 'container', {
|
|
30
|
+
className: getClass('slider-container')
|
|
31
|
+
}, [
|
|
32
|
+
// Track with segments
|
|
33
|
+
[createElement, 'track', {
|
|
34
|
+
className: getClass('slider-track')
|
|
35
|
+
}, [
|
|
36
|
+
[createElement, 'startTrack', {
|
|
37
|
+
className: getClass('slider-start-track')
|
|
38
|
+
}],
|
|
39
|
+
[createElement, 'activeTrack', {
|
|
40
|
+
className: getClass('slider-active-track')
|
|
41
|
+
}],
|
|
42
|
+
[createElement, 'remainingTrack', {
|
|
43
|
+
className: getClass('slider-remaining-track')
|
|
44
|
+
}]
|
|
45
|
+
]],
|
|
46
|
+
|
|
47
|
+
// Ticks container
|
|
48
|
+
[createElement, 'ticksContainer', {
|
|
49
|
+
className: getClass('slider-ticks-container')
|
|
50
|
+
}],
|
|
51
|
+
|
|
52
|
+
// Dots for ends
|
|
53
|
+
[createElement, 'startDot', {
|
|
54
|
+
className: [
|
|
55
|
+
getClass('slider-dot'),
|
|
56
|
+
getClass('slider-dot--start')
|
|
57
|
+
]
|
|
58
|
+
}],
|
|
59
|
+
[createElement, 'endDot', {
|
|
60
|
+
className: [
|
|
61
|
+
getClass('slider-dot'),
|
|
62
|
+
getClass('slider-dot--end')
|
|
63
|
+
]
|
|
64
|
+
}],
|
|
65
|
+
|
|
66
|
+
// Main handle
|
|
67
|
+
[createElement, 'handle', {
|
|
68
|
+
className: getClass('slider-handle'),
|
|
69
|
+
attrs: {
|
|
70
|
+
'role': 'slider',
|
|
71
|
+
'aria-valuemin': String(min),
|
|
72
|
+
'aria-valuemax': String(max),
|
|
73
|
+
'aria-valuenow': String(value),
|
|
74
|
+
'aria-orientation': 'horizontal',
|
|
75
|
+
'tabindex': isDisabled ? '-1' : '0',
|
|
76
|
+
'aria-disabled': isDisabled ? 'true' : 'false'
|
|
77
|
+
},
|
|
78
|
+
style: {
|
|
79
|
+
left: `${((value - min) / (max - min)) * 100}%`
|
|
80
|
+
}
|
|
81
|
+
}],
|
|
82
|
+
|
|
83
|
+
// Main value bubble
|
|
84
|
+
[createElement, 'valueBubble', {
|
|
85
|
+
className: getClass('slider-value'),
|
|
86
|
+
text: formatter(value)
|
|
87
|
+
}]
|
|
88
|
+
]]
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
// Add second handle and bubble for range slider
|
|
71
92
|
if (isRangeSlider) {
|
|
72
|
-
|
|
73
|
-
secondThumb.setAttribute('role', 'slider');
|
|
74
|
-
secondThumb.setAttribute('aria-valuemin', String(min));
|
|
75
|
-
secondThumb.setAttribute('aria-valuemax', String(max));
|
|
76
|
-
secondThumb.setAttribute('aria-valuenow', String(secondValue));
|
|
77
|
-
secondThumb.setAttribute('aria-orientation', 'horizontal');
|
|
78
|
-
|
|
79
|
-
// Set tabindex based on disabled state
|
|
80
|
-
secondThumb.setAttribute('tabindex', isDisabled ? '-1' : '0');
|
|
81
|
-
if (isDisabled) {
|
|
82
|
-
secondThumb.setAttribute('aria-disabled', 'true');
|
|
83
|
-
}
|
|
93
|
+
const secondHandlePos = ((secondValue - min) / (max - min)) * 100;
|
|
84
94
|
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
// Add second handle to structure
|
|
96
|
+
structure[0][3].push(
|
|
97
|
+
[createElement, 'secondHandle', {
|
|
98
|
+
className: getClass('slider-handle'),
|
|
99
|
+
attrs: {
|
|
100
|
+
'role': 'slider',
|
|
101
|
+
'aria-valuemin': String(min),
|
|
102
|
+
'aria-valuemax': String(max),
|
|
103
|
+
'aria-valuenow': String(secondValue),
|
|
104
|
+
'aria-orientation': 'horizontal',
|
|
105
|
+
'tabindex': isDisabled ? '-1' : '0',
|
|
106
|
+
'aria-disabled': isDisabled ? 'true' : 'false'
|
|
107
|
+
},
|
|
108
|
+
style: {
|
|
109
|
+
left: `${secondHandlePos}%`
|
|
110
|
+
}
|
|
111
|
+
}]
|
|
112
|
+
);
|
|
87
113
|
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
// Add second bubble to structure
|
|
115
|
+
structure[0][3].push(
|
|
116
|
+
[createElement, 'secondValueBubble', {
|
|
117
|
+
className: getClass('slider-value'),
|
|
118
|
+
text: formatter(secondValue)
|
|
119
|
+
}]
|
|
120
|
+
);
|
|
90
121
|
}
|
|
91
122
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// Add tracks to container
|
|
96
|
-
track.appendChild(remainingTrack);
|
|
97
|
-
track.appendChild(startTrack);
|
|
98
|
-
track.appendChild(activeTrack);
|
|
123
|
+
// Create layout and get structure elements
|
|
124
|
+
const components = createLayout(structure, component.element).component;
|
|
99
125
|
|
|
100
|
-
// Add
|
|
126
|
+
// Add component base class and accessibility attributes
|
|
101
127
|
component.element.classList.add(component.getClass('slider'));
|
|
102
|
-
|
|
103
|
-
// Accessibility enhancement: Container is not focusable
|
|
104
128
|
component.element.setAttribute('tabindex', '-1');
|
|
105
|
-
|
|
106
|
-
// Set container aria attributes
|
|
107
129
|
component.element.setAttribute('role', 'none');
|
|
108
130
|
component.element.setAttribute('aria-disabled', isDisabled ? 'true' : 'false');
|
|
109
131
|
|
|
110
|
-
|
|
111
|
-
component.element.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
component.element.appendChild(valueBubble);
|
|
116
|
-
|
|
117
|
-
if (isRangeSlider && secondThumb && secondValueBubble) {
|
|
118
|
-
component.element.classList.add(`${component.getClass('slider')}--range`);
|
|
119
|
-
component.element.appendChild(secondThumb);
|
|
120
|
-
component.element.appendChild(secondValueBubble);
|
|
132
|
+
// Position any icon properly
|
|
133
|
+
const iconElement = component.element.querySelector(`.${component.getClass('icon')}`);
|
|
134
|
+
if (iconElement && config.label) {
|
|
135
|
+
iconElement.classList.add(component.getClass('slider-icon'));
|
|
136
|
+
component.element.classList.add(component.getClass('slider--icon'));
|
|
121
137
|
}
|
|
122
138
|
|
|
123
|
-
// Apply
|
|
124
|
-
applyStyleClasses();
|
|
125
|
-
|
|
126
|
-
// Schedule UI update after DOM is attached
|
|
127
|
-
setTimeout(() => {
|
|
128
|
-
component.slider?.updateUi?.();
|
|
129
|
-
}, 0);
|
|
139
|
+
// Apply style classes
|
|
140
|
+
applyStyleClasses(component, config, isRangeSlider, isDisabled);
|
|
130
141
|
|
|
131
142
|
// Return enhanced component with structure
|
|
132
143
|
return {
|
|
133
144
|
...component,
|
|
134
|
-
structure:
|
|
135
|
-
track,
|
|
136
|
-
activeTrack,
|
|
137
|
-
startTrack,
|
|
138
|
-
remainingTrack,
|
|
139
|
-
ticksContainer,
|
|
140
|
-
thumb,
|
|
141
|
-
valueBubble,
|
|
142
|
-
secondThumb,
|
|
143
|
-
secondValueBubble,
|
|
144
|
-
startDot,
|
|
145
|
-
endDot
|
|
146
|
-
}
|
|
145
|
+
structure: components
|
|
147
146
|
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Applies style classes based on configuration
|
|
151
|
+
*/
|
|
152
|
+
function applyStyleClasses(component, config, isRangeSlider, isDisabled) {
|
|
153
|
+
const baseClass = component.getClass('slider');
|
|
148
154
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*/
|
|
154
|
-
function createElement(className) {
|
|
155
|
-
const element = document.createElement('div');
|
|
156
|
-
element.classList.add(component.getClass(className));
|
|
157
|
-
return element;
|
|
155
|
+
// Apply size class
|
|
156
|
+
const size = config.size || SLIDER_SIZES.MEDIUM;
|
|
157
|
+
if (size !== SLIDER_SIZES.MEDIUM) {
|
|
158
|
+
component.element.classList.add(`${baseClass}--${size}`);
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (isRangeSlider) {
|
|
165
|
-
// Range slider with two thumbs
|
|
166
|
-
const lowerValue = Math.min(value, secondValue);
|
|
167
|
-
const higherValue = Math.max(value, secondValue);
|
|
168
|
-
const lowerPercent = getPercentage(lowerValue);
|
|
169
|
-
const higherPercent = getPercentage(higherValue);
|
|
170
|
-
|
|
171
|
-
// Adjust positions to account for spacing
|
|
172
|
-
let adjustedLowerPercent = lowerPercent + paddingPercent;
|
|
173
|
-
let adjustedHigherPercent = higherPercent - paddingPercent;
|
|
174
|
-
|
|
175
|
-
// Handle case when thumbs are very close
|
|
176
|
-
if (adjustedHigherPercent <= adjustedLowerPercent) {
|
|
177
|
-
adjustedLowerPercent = (lowerPercent + higherPercent) / 2 - 1;
|
|
178
|
-
adjustedHigherPercent = (lowerPercent + higherPercent) / 2 + 1;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Calculate segment sizes
|
|
182
|
-
const startWidth = Math.max(0, lowerPercent - paddingPercent);
|
|
183
|
-
const activeWidth = Math.max(0, adjustedHigherPercent - adjustedLowerPercent);
|
|
184
|
-
const remainingWidth = Math.max(0, 100 - higherPercent - paddingPercent);
|
|
185
|
-
|
|
186
|
-
// Set styles
|
|
187
|
-
startTrack.style.display = 'block';
|
|
188
|
-
activeTrack.style.display = 'block';
|
|
189
|
-
remainingTrack.style.display = 'block';
|
|
190
|
-
|
|
191
|
-
// Horizontal orientation
|
|
192
|
-
setTrackStyles(startTrack, startWidth, 0);
|
|
193
|
-
setTrackStyles(activeTrack, activeWidth, adjustedLowerPercent);
|
|
194
|
-
setTrackStyles(remainingTrack, remainingWidth, higherPercent + paddingPercent);
|
|
195
|
-
} else {
|
|
196
|
-
// Single thumb slider
|
|
197
|
-
const adjustedWidth = Math.max(0, valuePercent - paddingPercent);
|
|
198
|
-
const remainingWidth = Math.max(0, 100 - valuePercent - paddingPercent);
|
|
199
|
-
|
|
200
|
-
// Hide start track for single thumb
|
|
201
|
-
startTrack.style.display = 'none';
|
|
202
|
-
activeTrack.style.display = 'block';
|
|
203
|
-
remainingTrack.style.display = 'block';
|
|
204
|
-
|
|
205
|
-
// Horizontal orientation
|
|
206
|
-
setTrackStyles(activeTrack, adjustedWidth, 0);
|
|
207
|
-
setTrackStyles(remainingTrack, remainingWidth, valuePercent + paddingPercent);
|
|
208
|
-
}
|
|
161
|
+
// Apply color class
|
|
162
|
+
const color = config.color || SLIDER_COLORS.PRIMARY;
|
|
163
|
+
if (color !== SLIDER_COLORS.PRIMARY) {
|
|
164
|
+
component.element.classList.add(`${baseClass}--${color}`);
|
|
209
165
|
}
|
|
210
166
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
* @param width Width as percentage
|
|
215
|
-
* @param left Left position as percentage
|
|
216
|
-
*/
|
|
217
|
-
function setTrackStyles(element, width, left) {
|
|
218
|
-
element.style.width = `${width}%`;
|
|
219
|
-
element.style.left = `${left}%`;
|
|
220
|
-
element.style.height = '100%';
|
|
167
|
+
// Apply discrete class if step is specified
|
|
168
|
+
if (config.step !== undefined && config.step > 0) {
|
|
169
|
+
component.element.classList.add(`${baseClass}--discrete`);
|
|
221
170
|
}
|
|
222
171
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (size !== SLIDER_SIZES.MEDIUM) {
|
|
232
|
-
component.element.classList.add(`${baseClass}--${size}`);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Apply color class
|
|
236
|
-
const color = config.color || SLIDER_COLORS.PRIMARY;
|
|
237
|
-
if (color !== SLIDER_COLORS.PRIMARY) {
|
|
238
|
-
component.element.classList.add(`${baseClass}--${color}`);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Apply discrete class if step is specified
|
|
242
|
-
if (config.step !== undefined && config.step > 0) {
|
|
243
|
-
component.element.classList.add(`${baseClass}--discrete`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Apply disabled class if needed
|
|
247
|
-
if (isDisabled) {
|
|
248
|
-
component.element.classList.add(`${baseClass}--disabled`);
|
|
249
|
-
}
|
|
172
|
+
// Apply disabled class if needed
|
|
173
|
+
if (isDisabled) {
|
|
174
|
+
component.element.classList.add(`${baseClass}--disabled`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Apply range class if needed
|
|
178
|
+
if (isRangeSlider) {
|
|
179
|
+
component.element.classList.add(`${baseClass}--range`);
|
|
250
180
|
}
|
|
251
|
-
}
|
|
181
|
+
}
|