@tachui/forms 0.7.1-alpha → 0.8.1-alpha
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/README.md +87 -272
- package/dist/DatePicker-D5nRFTUm.js +475 -0
- package/dist/DatePicker-D5nRFTUm.js.map +1 -0
- package/dist/Select-yZyKooXk.js +945 -0
- package/dist/Select-yZyKooXk.js.map +1 -0
- package/dist/Slider-0-oal5YR.js +644 -0
- package/dist/Slider-0-oal5YR.js.map +1 -0
- package/dist/TextField-hX15dY3U.js +509 -0
- package/dist/TextField-hX15dY3U.js.map +1 -0
- package/dist/components/advanced/Slider.d.ts +190 -0
- package/dist/components/advanced/Slider.d.ts.map +1 -0
- package/dist/components/advanced/Stepper.d.ts +161 -0
- package/dist/components/advanced/Stepper.d.ts.map +1 -0
- package/dist/components/advanced/index.d.ts +15 -0
- package/dist/components/advanced/index.d.ts.map +1 -0
- package/dist/components/advanced/index.js +6 -0
- package/dist/components/advanced/index.js.map +1 -0
- package/dist/components/date-picker/DatePicker.d.ts +126 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
- package/dist/components/date-picker/index.d.ts +14 -0
- package/dist/components/date-picker/index.d.ts.map +1 -0
- package/dist/components/date-picker/index.js +5 -0
- package/dist/components/date-picker/index.js.map +1 -0
- package/dist/components/form-container/index.d.ts +58 -0
- package/dist/components/form-container/index.d.ts.map +1 -0
- package/dist/components/selection/Checkbox.d.ts.map +1 -0
- package/dist/components/selection/Radio.d.ts.map +1 -0
- package/dist/components/selection/Select.d.ts.map +1 -0
- package/dist/components/selection/index.d.ts +68 -0
- package/dist/components/selection/index.d.ts.map +1 -0
- package/dist/components/selection/index.js +12 -0
- package/dist/components/selection/index.js.map +1 -0
- package/dist/components/text-input/TextField.d.ts.map +1 -0
- package/dist/components/text-input/index.d.ts +8 -0
- package/dist/components/text-input/index.d.ts.map +1 -0
- package/dist/components/text-input/index.js +18 -0
- package/dist/components/text-input/index.js.map +1 -0
- package/dist/{state/index.js → index-D3WfkqVv.js} +15 -8
- package/dist/index-D3WfkqVv.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +198 -376
- package/dist/index.js.map +1 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/validation/component-validation.d.ts +11 -2
- package/dist/validation/component-validation.d.ts.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +282 -191
- package/dist/validation/index.js.map +1 -0
- package/package.json +53 -39
- package/src/components/advanced/Slider.ts +722 -0
- package/src/components/advanced/Stepper.ts +715 -0
- package/src/components/advanced/index.ts +20 -0
- package/src/components/date-picker/DatePicker.ts +925 -0
- package/src/components/date-picker/index.ts +20 -0
- package/src/components/form-container/index.ts +266 -0
- package/src/components/selection/Checkbox.ts +478 -0
- package/src/components/selection/Radio.ts +470 -0
- package/src/components/selection/Select.ts +620 -0
- package/src/components/selection/index.ts +81 -0
- package/src/components/text-input/TextField.ts +728 -0
- package/src/components/text-input/index.ts +35 -0
- package/src/index.ts +48 -0
- package/src/state/index.ts +544 -0
- package/src/types/index.ts +579 -0
- package/src/utils/formatters.ts +184 -0
- package/src/utils/index.ts +57 -0
- package/src/validation/component-validation.ts +429 -0
- package/src/validation/index.ts +641 -0
- package/dist/TextField-CGBM3x7K.js +0 -1799
- package/dist/components/Form.d.ts +0 -76
- package/dist/components/Form.d.ts.map +0 -1
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -28
- package/dist/components/input/Checkbox.d.ts.map +0 -1
- package/dist/components/input/Radio.d.ts.map +0 -1
- package/dist/components/input/Select.d.ts.map +0 -1
- package/dist/components/input/TextField.d.ts.map +0 -1
- package/dist/components/input/index.d.ts +0 -11
- package/dist/components/input/index.d.ts.map +0 -1
- package/dist/utils/validators.d.ts +0 -101
- package/dist/utils/validators.d.ts.map +0 -1
- /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
- /package/dist/components/{input → selection}/Radio.d.ts +0 -0
- /package/dist/components/{input → selection}/Select.d.ts +0 -0
- /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import { withModifiers as g, isSignal as m, getSignalImpl as x, h as l, createEffect as b, createSignal as y, text as d } from "@tachui/core";
|
|
2
|
+
const v = {
|
|
3
|
+
colors: {
|
|
4
|
+
background: "#FFFFFF",
|
|
5
|
+
border: "#D1D1D6",
|
|
6
|
+
buttonBackground: "#F2F2F7",
|
|
7
|
+
buttonHover: "#E5E5EA",
|
|
8
|
+
buttonPress: "#D1D1D6",
|
|
9
|
+
buttonDisabled: "#F2F2F7",
|
|
10
|
+
text: "#000000",
|
|
11
|
+
buttonText: "#007AFF",
|
|
12
|
+
disabledText: "#8E8E93",
|
|
13
|
+
focusRing: "#007AFF"
|
|
14
|
+
},
|
|
15
|
+
spacing: {
|
|
16
|
+
padding: 12,
|
|
17
|
+
gap: 8,
|
|
18
|
+
borderRadius: 8,
|
|
19
|
+
buttonSize: 32
|
|
20
|
+
},
|
|
21
|
+
typography: {
|
|
22
|
+
labelSize: 16,
|
|
23
|
+
buttonSize: 18,
|
|
24
|
+
labelWeight: "400",
|
|
25
|
+
buttonWeight: "600",
|
|
26
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
|
|
27
|
+
},
|
|
28
|
+
transitions: {
|
|
29
|
+
duration: 150,
|
|
30
|
+
easing: "cubic-bezier(0.2, 0.8, 0.2, 1)"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
class S {
|
|
34
|
+
type = "component";
|
|
35
|
+
id;
|
|
36
|
+
props;
|
|
37
|
+
theme = v;
|
|
38
|
+
incrementButton = null;
|
|
39
|
+
decrementButton = null;
|
|
40
|
+
isEditing = !1;
|
|
41
|
+
longPressTimer = null;
|
|
42
|
+
longPressInterval = null;
|
|
43
|
+
constructor(t) {
|
|
44
|
+
this.props = t, this.id = `stepper-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
45
|
+
}
|
|
46
|
+
resolveValue(t) {
|
|
47
|
+
return m(t) ? t() : t;
|
|
48
|
+
}
|
|
49
|
+
getValue() {
|
|
50
|
+
return this.resolveValue(this.props.value);
|
|
51
|
+
}
|
|
52
|
+
setValue(t) {
|
|
53
|
+
const e = this.constrainValue(t);
|
|
54
|
+
if (m(this.props.value)) {
|
|
55
|
+
const i = x(this.props.value);
|
|
56
|
+
i && i.set(e);
|
|
57
|
+
}
|
|
58
|
+
this.props.onChange && this.props.onChange(e);
|
|
59
|
+
}
|
|
60
|
+
getMinimumValue() {
|
|
61
|
+
return this.props.minimumValue ?? -1 / 0;
|
|
62
|
+
}
|
|
63
|
+
getMaximumValue() {
|
|
64
|
+
return this.props.maximumValue ?? 1 / 0;
|
|
65
|
+
}
|
|
66
|
+
getStep() {
|
|
67
|
+
return this.props.step ?? 1;
|
|
68
|
+
}
|
|
69
|
+
isDisabled() {
|
|
70
|
+
return this.resolveValue(this.props.disabled ?? !1);
|
|
71
|
+
}
|
|
72
|
+
constrainValue(t) {
|
|
73
|
+
const e = this.getMinimumValue(), i = this.getMaximumValue();
|
|
74
|
+
return Math.min(Math.max(t, e), i);
|
|
75
|
+
}
|
|
76
|
+
canIncrement() {
|
|
77
|
+
if (this.isDisabled()) return !1;
|
|
78
|
+
const t = this.getValue(), e = this.getMaximumValue();
|
|
79
|
+
return t < e;
|
|
80
|
+
}
|
|
81
|
+
canDecrement() {
|
|
82
|
+
if (this.isDisabled()) return !1;
|
|
83
|
+
const t = this.getValue(), e = this.getMinimumValue();
|
|
84
|
+
return t > e;
|
|
85
|
+
}
|
|
86
|
+
increment() {
|
|
87
|
+
if (this.canIncrement())
|
|
88
|
+
if (this.props.onIncrement)
|
|
89
|
+
this.props.onIncrement();
|
|
90
|
+
else {
|
|
91
|
+
const t = this.getValue(), e = this.getStep();
|
|
92
|
+
this.setValue(t + e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
decrement() {
|
|
96
|
+
if (this.canDecrement())
|
|
97
|
+
if (this.props.onDecrement)
|
|
98
|
+
this.props.onDecrement();
|
|
99
|
+
else {
|
|
100
|
+
const t = this.getValue(), e = this.getStep();
|
|
101
|
+
this.setValue(t - e);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
formatValue(t) {
|
|
105
|
+
return this.props.valueFormatter ? this.props.valueFormatter(t) : Number.isInteger(t) ? t.toString() : parseFloat(t.toFixed(2)).toString();
|
|
106
|
+
}
|
|
107
|
+
startLongPress(t) {
|
|
108
|
+
this.stopLongPress(), this.setEditing(!0), this.longPressTimer = setTimeout(() => {
|
|
109
|
+
this.longPressInterval = setInterval(() => {
|
|
110
|
+
t();
|
|
111
|
+
}, 100);
|
|
112
|
+
}, 500);
|
|
113
|
+
}
|
|
114
|
+
stopLongPress() {
|
|
115
|
+
this.longPressTimer && (clearTimeout(this.longPressTimer), this.longPressTimer = null), this.longPressInterval && (clearInterval(this.longPressInterval), this.longPressInterval = null), this.setEditing(!1);
|
|
116
|
+
}
|
|
117
|
+
setEditing(t) {
|
|
118
|
+
this.isEditing !== t && (this.isEditing = t, this.props.onEditingChanged && this.props.onEditingChanged(t));
|
|
119
|
+
}
|
|
120
|
+
createButton(t, e, i, s) {
|
|
121
|
+
const n = l("button", {
|
|
122
|
+
type: "button",
|
|
123
|
+
disabled: !s,
|
|
124
|
+
"aria-label": t === "increment" ? this.props.incrementAccessibilityLabel || "Increment" : this.props.decrementAccessibilityLabel || "Decrement",
|
|
125
|
+
style: {
|
|
126
|
+
width: `${this.theme.spacing.buttonSize}px`,
|
|
127
|
+
height: `${this.theme.spacing.buttonSize}px`,
|
|
128
|
+
border: `1px solid ${this.theme.colors.border}`,
|
|
129
|
+
borderRadius: `${this.theme.spacing.borderRadius}px`,
|
|
130
|
+
backgroundColor: s ? this.theme.colors.buttonBackground : this.theme.colors.buttonDisabled,
|
|
131
|
+
color: s ? this.theme.colors.buttonText : this.theme.colors.disabledText,
|
|
132
|
+
fontSize: `${this.theme.typography.buttonSize}px`,
|
|
133
|
+
fontWeight: this.theme.typography.buttonWeight,
|
|
134
|
+
fontFamily: this.theme.typography.fontFamily,
|
|
135
|
+
cursor: s ? "pointer" : "not-allowed",
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
justifyContent: "center",
|
|
139
|
+
userSelect: "none",
|
|
140
|
+
outline: "none",
|
|
141
|
+
transition: `all ${this.theme.transitions.duration}ms ${this.theme.transitions.easing}`,
|
|
142
|
+
touchAction: "manipulation"
|
|
143
|
+
// Prevent double-tap zoom on mobile
|
|
144
|
+
},
|
|
145
|
+
onclick: (r) => {
|
|
146
|
+
r.preventDefault(), s && i();
|
|
147
|
+
},
|
|
148
|
+
onmousedown: (r) => {
|
|
149
|
+
r.preventDefault(), s && this.startLongPress(i);
|
|
150
|
+
},
|
|
151
|
+
onmouseup: () => {
|
|
152
|
+
this.stopLongPress();
|
|
153
|
+
},
|
|
154
|
+
ontouchstart: (r) => {
|
|
155
|
+
r.preventDefault(), s && this.startLongPress(i);
|
|
156
|
+
},
|
|
157
|
+
ontouchend: (r) => {
|
|
158
|
+
r.preventDefault(), this.stopLongPress();
|
|
159
|
+
},
|
|
160
|
+
onmouseenter: (r) => {
|
|
161
|
+
if (s) {
|
|
162
|
+
const a = r.target;
|
|
163
|
+
a.style.backgroundColor = this.theme.colors.buttonHover;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
onmouseleave: (r) => {
|
|
167
|
+
const a = r.target;
|
|
168
|
+
a.style.backgroundColor = s ? this.theme.colors.buttonBackground : this.theme.colors.buttonDisabled, this.stopLongPress();
|
|
169
|
+
},
|
|
170
|
+
onkeydown: (r) => {
|
|
171
|
+
(r.key === "Enter" || r.key === " ") && (r.preventDefault(), s && i());
|
|
172
|
+
},
|
|
173
|
+
onfocus: (r) => {
|
|
174
|
+
const a = r.target;
|
|
175
|
+
a.style.boxShadow = `0 0 0 2px ${this.theme.colors.focusRing}40`;
|
|
176
|
+
},
|
|
177
|
+
onblur: (r) => {
|
|
178
|
+
const a = r.target;
|
|
179
|
+
a.style.boxShadow = "none", this.stopLongPress();
|
|
180
|
+
}
|
|
181
|
+
}), o = n.element;
|
|
182
|
+
return o && (o.textContent = e, o.setAttribute("tabindex", "0"), t === "increment" ? this.incrementButton = o : this.decrementButton = o), n;
|
|
183
|
+
}
|
|
184
|
+
createLabel() {
|
|
185
|
+
const t = this.getValue(), e = this.formatValue(t);
|
|
186
|
+
let i = this.props.title || "";
|
|
187
|
+
this.props.displayValueInLabel !== !1 && this.props.title ? i = `${this.props.title}: ${e}` : !this.props.title && this.props.displayValueInLabel !== !1 && (i = e);
|
|
188
|
+
const s = l("span", {
|
|
189
|
+
style: {
|
|
190
|
+
fontSize: `${this.theme.typography.labelSize}px`,
|
|
191
|
+
fontWeight: this.theme.typography.labelWeight,
|
|
192
|
+
fontFamily: this.theme.typography.fontFamily,
|
|
193
|
+
color: this.isDisabled() ? this.theme.colors.disabledText : this.theme.colors.text,
|
|
194
|
+
userSelect: "none",
|
|
195
|
+
display: "flex",
|
|
196
|
+
alignItems: "center",
|
|
197
|
+
minHeight: `${this.theme.spacing.buttonSize}px`
|
|
198
|
+
}
|
|
199
|
+
}), n = s.element;
|
|
200
|
+
return n && (n.textContent = i), s;
|
|
201
|
+
}
|
|
202
|
+
render() {
|
|
203
|
+
const t = l("div", {
|
|
204
|
+
id: this.id,
|
|
205
|
+
"data-component": "stepper",
|
|
206
|
+
role: "group",
|
|
207
|
+
"aria-label": this.props.accessibilityLabel || this.props.title || "Numeric stepper",
|
|
208
|
+
"aria-describedby": this.props.accessibilityHint ? `${this.id}-hint` : void 0,
|
|
209
|
+
style: {
|
|
210
|
+
display: "inline-flex",
|
|
211
|
+
alignItems: "center",
|
|
212
|
+
gap: `${this.theme.spacing.gap}px`,
|
|
213
|
+
padding: `${this.theme.spacing.padding}px`,
|
|
214
|
+
backgroundColor: this.theme.colors.background,
|
|
215
|
+
border: `1px solid ${this.theme.colors.border}`,
|
|
216
|
+
borderRadius: `${this.theme.spacing.borderRadius}px`,
|
|
217
|
+
fontFamily: this.theme.typography.fontFamily
|
|
218
|
+
}
|
|
219
|
+
}), e = this.createButton(
|
|
220
|
+
"decrement",
|
|
221
|
+
"−",
|
|
222
|
+
// Using minus sign (U+2212) instead of hyphen for better visual appearance
|
|
223
|
+
() => this.decrement(),
|
|
224
|
+
this.canDecrement()
|
|
225
|
+
), i = this.createLabel(), s = this.createButton(
|
|
226
|
+
"increment",
|
|
227
|
+
"+",
|
|
228
|
+
() => this.increment(),
|
|
229
|
+
this.canIncrement()
|
|
230
|
+
), n = t.element;
|
|
231
|
+
if (n) {
|
|
232
|
+
const o = e.element, r = i.element, a = s.element;
|
|
233
|
+
if (o && n.appendChild(o), r && n.appendChild(r), a && n.appendChild(a), this.props.accessibilityHint) {
|
|
234
|
+
const c = l("span", {
|
|
235
|
+
id: `${this.id}-hint`,
|
|
236
|
+
style: {
|
|
237
|
+
position: "absolute",
|
|
238
|
+
width: "1px",
|
|
239
|
+
height: "1px",
|
|
240
|
+
padding: "0",
|
|
241
|
+
margin: "-1px",
|
|
242
|
+
overflow: "hidden",
|
|
243
|
+
clip: "rect(0, 0, 0, 0)",
|
|
244
|
+
whiteSpace: "nowrap",
|
|
245
|
+
border: "0"
|
|
246
|
+
}
|
|
247
|
+
}).element;
|
|
248
|
+
c && (c.textContent = this.props.accessibilityHint, n.appendChild(c));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return b(() => {
|
|
252
|
+
if (this.incrementButton) {
|
|
253
|
+
const r = this.canIncrement();
|
|
254
|
+
this.incrementButton.disabled = !r, this.incrementButton.style.backgroundColor = r ? this.theme.colors.buttonBackground : this.theme.colors.buttonDisabled, this.incrementButton.style.color = r ? this.theme.colors.buttonText : this.theme.colors.disabledText, this.incrementButton.style.cursor = r ? "pointer" : "not-allowed";
|
|
255
|
+
}
|
|
256
|
+
if (this.decrementButton) {
|
|
257
|
+
const r = this.canDecrement();
|
|
258
|
+
this.decrementButton.disabled = !r, this.decrementButton.style.backgroundColor = r ? this.theme.colors.buttonBackground : this.theme.colors.buttonDisabled, this.decrementButton.style.color = r ? this.theme.colors.buttonText : this.theme.colors.disabledText, this.decrementButton.style.cursor = r ? "pointer" : "not-allowed";
|
|
259
|
+
}
|
|
260
|
+
const o = n?.querySelector(
|
|
261
|
+
'span:not([id$="-hint"])'
|
|
262
|
+
);
|
|
263
|
+
if (o) {
|
|
264
|
+
const r = this.getValue(), a = this.formatValue(r);
|
|
265
|
+
let u = this.props.title || "";
|
|
266
|
+
this.props.displayValueInLabel !== !1 && this.props.title ? u = `${this.props.title}: ${a}` : !this.props.title && this.props.displayValueInLabel !== !1 && (u = a), o.textContent = u, o.style.color = this.isDisabled() ? this.theme.colors.disabledText : this.theme.colors.text;
|
|
267
|
+
}
|
|
268
|
+
}), t;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function k(p) {
|
|
272
|
+
return g(new S(p));
|
|
273
|
+
}
|
|
274
|
+
class V {
|
|
275
|
+
constructor(t) {
|
|
276
|
+
this.props = t, this.id = `slider-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
277
|
+
const [e, i] = y(!1);
|
|
278
|
+
this.isDragging = e, this.setIsDragging = i, b(() => {
|
|
279
|
+
const s = this.getValue();
|
|
280
|
+
this.sliderElement && !this.isDragging() && (this.sliderElement.value = String(s), this.updateTrackFill());
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
type = "component";
|
|
284
|
+
id;
|
|
285
|
+
mounted = !1;
|
|
286
|
+
cleanup = [];
|
|
287
|
+
sliderElement = null;
|
|
288
|
+
isDragging;
|
|
289
|
+
setIsDragging;
|
|
290
|
+
/**
|
|
291
|
+
* Get current value
|
|
292
|
+
*/
|
|
293
|
+
getValue() {
|
|
294
|
+
const { value: t } = this.props;
|
|
295
|
+
return m(t) ? t() : t;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Check if slider is disabled
|
|
299
|
+
*/
|
|
300
|
+
isDisabled() {
|
|
301
|
+
const { disabled: t } = this.props;
|
|
302
|
+
return typeof t == "boolean" ? t : m(t) ? t() : !1;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Format value for display
|
|
306
|
+
*/
|
|
307
|
+
formatValue(t) {
|
|
308
|
+
const { formatter: e } = this.props;
|
|
309
|
+
if (e)
|
|
310
|
+
return e(t);
|
|
311
|
+
const i = this.props.step || 1;
|
|
312
|
+
if (i < 1) {
|
|
313
|
+
const s = String(i).split(".")[1]?.length || 0;
|
|
314
|
+
return t.toFixed(s);
|
|
315
|
+
}
|
|
316
|
+
return String(Math.round(t));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Handle value change
|
|
320
|
+
*/
|
|
321
|
+
handleValueChange = (t) => {
|
|
322
|
+
const { min: e = 0, max: i = 100, step: s = 1 } = this.props;
|
|
323
|
+
let n = Math.max(e, Math.min(i, t));
|
|
324
|
+
s > 0 && (n = Math.round((n - e) / s) * s + e), this.props.onValueChange && this.props.onValueChange(n), this.updateTrackFill();
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Update track fill visual
|
|
328
|
+
*/
|
|
329
|
+
updateTrackFill() {
|
|
330
|
+
if (!this.sliderElement) return;
|
|
331
|
+
const { min: t = 0, max: e = 100 } = this.props, s = (this.getValue() - t) / (e - t) * 100;
|
|
332
|
+
this.sliderElement.style.setProperty("--slider-progress", `${s}%`);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Handle input events
|
|
336
|
+
*/
|
|
337
|
+
handleInput = (t) => {
|
|
338
|
+
const e = t.target, i = parseFloat(e.value);
|
|
339
|
+
Number.isNaN(i) || this.handleValueChange(i);
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Handle mouse/touch start
|
|
343
|
+
*/
|
|
344
|
+
handleStart = () => {
|
|
345
|
+
this.isDisabled() || this.setIsDragging(!0);
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Handle mouse/touch end
|
|
349
|
+
*/
|
|
350
|
+
handleEnd = () => {
|
|
351
|
+
this.setIsDragging(!1);
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Get slider size styles
|
|
355
|
+
*/
|
|
356
|
+
getSizeStyles() {
|
|
357
|
+
const { size: t = "medium" } = this.props;
|
|
358
|
+
switch (t) {
|
|
359
|
+
case "small":
|
|
360
|
+
return {
|
|
361
|
+
height: "4px",
|
|
362
|
+
thumbSize: "16px"
|
|
363
|
+
};
|
|
364
|
+
case "large":
|
|
365
|
+
return {
|
|
366
|
+
height: "8px",
|
|
367
|
+
thumbSize: "24px"
|
|
368
|
+
};
|
|
369
|
+
default:
|
|
370
|
+
return {
|
|
371
|
+
height: "6px",
|
|
372
|
+
thumbSize: "20px"
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get slider variant styles
|
|
378
|
+
*/
|
|
379
|
+
getVariantStyles() {
|
|
380
|
+
const {
|
|
381
|
+
variant: t = "default",
|
|
382
|
+
trackColor: e = "#e2e8f0",
|
|
383
|
+
activeTrackColor: i = "#007AFF",
|
|
384
|
+
thumbColor: s = "#ffffff"
|
|
385
|
+
} = this.props, n = this.getSizeStyles(), o = {
|
|
386
|
+
"--slider-track-color": e,
|
|
387
|
+
"--slider-active-track-color": i,
|
|
388
|
+
"--slider-thumb-color": s,
|
|
389
|
+
"--slider-height": n.height,
|
|
390
|
+
"--slider-thumb-size": n.thumbSize
|
|
391
|
+
};
|
|
392
|
+
switch (t) {
|
|
393
|
+
case "filled":
|
|
394
|
+
return {
|
|
395
|
+
...o,
|
|
396
|
+
"--slider-track-color": "#f1f5f9",
|
|
397
|
+
"--slider-active-track-color": i,
|
|
398
|
+
backgroundColor: "#f8fafc",
|
|
399
|
+
borderRadius: "12px",
|
|
400
|
+
padding: "8px"
|
|
401
|
+
};
|
|
402
|
+
case "minimal":
|
|
403
|
+
return {
|
|
404
|
+
...o,
|
|
405
|
+
"--slider-track-color": "transparent",
|
|
406
|
+
"--slider-active-track-color": i,
|
|
407
|
+
border: `1px solid ${e}`
|
|
408
|
+
};
|
|
409
|
+
default:
|
|
410
|
+
return o;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Render slider marks
|
|
415
|
+
*/
|
|
416
|
+
renderMarks() {
|
|
417
|
+
const { marks: t, min: e = 0, max: i = 100 } = this.props;
|
|
418
|
+
return !t || t.length === 0 ? [] : t.map((s) => {
|
|
419
|
+
const n = (s.value - e) / (i - e) * 100;
|
|
420
|
+
return l(
|
|
421
|
+
"div",
|
|
422
|
+
{
|
|
423
|
+
key: String(s.value),
|
|
424
|
+
style: {
|
|
425
|
+
position: "absolute",
|
|
426
|
+
left: `${n}%`,
|
|
427
|
+
top: "50%",
|
|
428
|
+
transform: "translate(-50%, -50%)",
|
|
429
|
+
display: "flex",
|
|
430
|
+
flexDirection: "column",
|
|
431
|
+
alignItems: "center",
|
|
432
|
+
pointerEvents: "none"
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
// Mark indicator
|
|
436
|
+
l("div", {
|
|
437
|
+
style: {
|
|
438
|
+
width: "2px",
|
|
439
|
+
height: "12px",
|
|
440
|
+
backgroundColor: s.color || "#666",
|
|
441
|
+
marginBottom: "4px"
|
|
442
|
+
}
|
|
443
|
+
}),
|
|
444
|
+
...s.label ? [
|
|
445
|
+
l(
|
|
446
|
+
"span",
|
|
447
|
+
{
|
|
448
|
+
style: {
|
|
449
|
+
fontSize: "12px",
|
|
450
|
+
color: "#666",
|
|
451
|
+
whiteSpace: "nowrap"
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
d(s.label)
|
|
455
|
+
)
|
|
456
|
+
] : []
|
|
457
|
+
);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Render value labels
|
|
462
|
+
*/
|
|
463
|
+
renderLabels() {
|
|
464
|
+
const {
|
|
465
|
+
showLabels: t,
|
|
466
|
+
min: e = 0,
|
|
467
|
+
max: i = 100,
|
|
468
|
+
minimumValueLabel: s,
|
|
469
|
+
maximumValueLabel: n
|
|
470
|
+
} = this.props;
|
|
471
|
+
return t ? [
|
|
472
|
+
l(
|
|
473
|
+
"div",
|
|
474
|
+
{
|
|
475
|
+
style: {
|
|
476
|
+
display: "flex",
|
|
477
|
+
justifyContent: "space-between",
|
|
478
|
+
marginTop: "8px",
|
|
479
|
+
fontSize: "12px",
|
|
480
|
+
color: "#666"
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
l("span", {}, d(s || this.formatValue(e))),
|
|
484
|
+
l("span", {}, d(n || this.formatValue(i)))
|
|
485
|
+
)
|
|
486
|
+
] : [];
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Render value display
|
|
490
|
+
*/
|
|
491
|
+
renderValueDisplay() {
|
|
492
|
+
const { showValue: t } = this.props;
|
|
493
|
+
if (!t) return [];
|
|
494
|
+
const e = this.getValue();
|
|
495
|
+
return [
|
|
496
|
+
l(
|
|
497
|
+
"div",
|
|
498
|
+
{
|
|
499
|
+
style: {
|
|
500
|
+
display: "flex",
|
|
501
|
+
justifyContent: "center",
|
|
502
|
+
marginBottom: "8px",
|
|
503
|
+
fontSize: "14px",
|
|
504
|
+
fontWeight: "600",
|
|
505
|
+
color: "#1a1a1a"
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
d(this.formatValue(e))
|
|
509
|
+
)
|
|
510
|
+
];
|
|
511
|
+
}
|
|
512
|
+
render() {
|
|
513
|
+
const {
|
|
514
|
+
min: t = 0,
|
|
515
|
+
max: e = 100,
|
|
516
|
+
step: i = 1,
|
|
517
|
+
vertical: s = !1,
|
|
518
|
+
accessibilityLabel: n,
|
|
519
|
+
accessibilityHint: o,
|
|
520
|
+
accessibilityValueDescription: r
|
|
521
|
+
} = this.props, a = this.getValue(), u = this.getVariantStyles(), c = this.isDisabled(), f = {
|
|
522
|
+
appearance: "none",
|
|
523
|
+
width: s ? "6px" : "100%",
|
|
524
|
+
height: s ? "200px" : "var(--slider-height)",
|
|
525
|
+
background: `linear-gradient(to ${s ? "top" : "right"}, var(--slider-active-track-color) 0%, var(--slider-active-track-color) var(--slider-progress, 0%), var(--slider-track-color) var(--slider-progress, 0%), var(--slider-track-color) 100%)`,
|
|
526
|
+
borderRadius: "calc(var(--slider-height) / 2)",
|
|
527
|
+
outline: "none",
|
|
528
|
+
cursor: c ? "not-allowed" : "pointer",
|
|
529
|
+
opacity: c ? 0.5 : 1,
|
|
530
|
+
transition: "all 0.2s ease",
|
|
531
|
+
// Webkit styles
|
|
532
|
+
WebkitAppearance: "none",
|
|
533
|
+
// Thumb styles
|
|
534
|
+
"&::-webkit-slider-thumb": {
|
|
535
|
+
appearance: "none",
|
|
536
|
+
width: "var(--slider-thumb-size)",
|
|
537
|
+
height: "var(--slider-thumb-size)",
|
|
538
|
+
borderRadius: "50%",
|
|
539
|
+
background: "var(--slider-thumb-color)",
|
|
540
|
+
border: "2px solid var(--slider-active-track-color)",
|
|
541
|
+
cursor: c ? "not-allowed" : "grab",
|
|
542
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
543
|
+
transition: "all 0.2s ease"
|
|
544
|
+
},
|
|
545
|
+
"&::-webkit-slider-thumb:hover": c ? {} : {
|
|
546
|
+
transform: "scale(1.1)",
|
|
547
|
+
boxShadow: "0 4px 8px rgba(0,0,0,0.15)"
|
|
548
|
+
},
|
|
549
|
+
"&::-webkit-slider-thumb:active": c ? {} : {
|
|
550
|
+
cursor: "grabbing",
|
|
551
|
+
transform: "scale(1.05)"
|
|
552
|
+
},
|
|
553
|
+
// Firefox styles
|
|
554
|
+
"&::-moz-range-thumb": {
|
|
555
|
+
width: "var(--slider-thumb-size)",
|
|
556
|
+
height: "var(--slider-thumb-size)",
|
|
557
|
+
borderRadius: "50%",
|
|
558
|
+
background: "var(--slider-thumb-color)",
|
|
559
|
+
border: "2px solid var(--slider-active-track-color)",
|
|
560
|
+
cursor: c ? "not-allowed" : "pointer",
|
|
561
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)"
|
|
562
|
+
},
|
|
563
|
+
"&::-moz-range-track": {
|
|
564
|
+
height: "var(--slider-height)",
|
|
565
|
+
borderRadius: "calc(var(--slider-height) / 2)",
|
|
566
|
+
background: "var(--slider-track-color)",
|
|
567
|
+
border: "none"
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
return l(
|
|
571
|
+
"div",
|
|
572
|
+
{
|
|
573
|
+
style: {
|
|
574
|
+
...u,
|
|
575
|
+
position: "relative",
|
|
576
|
+
display: "flex",
|
|
577
|
+
flexDirection: s ? "row" : "column",
|
|
578
|
+
alignItems: s ? "center" : "stretch",
|
|
579
|
+
gap: s ? "12px" : "0"
|
|
580
|
+
},
|
|
581
|
+
"aria-label": n,
|
|
582
|
+
"aria-describedby": o ? `${this.id}-hint` : void 0
|
|
583
|
+
},
|
|
584
|
+
...this.renderValueDisplay(),
|
|
585
|
+
// Slider container
|
|
586
|
+
l(
|
|
587
|
+
"div",
|
|
588
|
+
{
|
|
589
|
+
style: {
|
|
590
|
+
position: "relative",
|
|
591
|
+
width: s ? "auto" : "100%",
|
|
592
|
+
height: s ? "200px" : "auto"
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
// Slider input
|
|
596
|
+
l("input", {
|
|
597
|
+
ref: (h) => {
|
|
598
|
+
this.sliderElement = h, h && !this.mounted && (h.addEventListener("input", this.handleInput), h.addEventListener("mousedown", this.handleStart), h.addEventListener("mouseup", this.handleEnd), h.addEventListener("touchstart", this.handleStart), h.addEventListener("touchend", this.handleEnd), this.cleanup.push(() => {
|
|
599
|
+
h.removeEventListener("input", this.handleInput), h.removeEventListener("mousedown", this.handleStart), h.removeEventListener("mouseup", this.handleEnd), h.removeEventListener("touchstart", this.handleStart), h.removeEventListener("touchend", this.handleEnd);
|
|
600
|
+
}), this.updateTrackFill(), this.mounted = !0);
|
|
601
|
+
},
|
|
602
|
+
type: "range",
|
|
603
|
+
min: String(t),
|
|
604
|
+
max: String(e),
|
|
605
|
+
step: String(i),
|
|
606
|
+
value: String(a),
|
|
607
|
+
disabled: c,
|
|
608
|
+
orient: s ? "vertical" : void 0,
|
|
609
|
+
style: f,
|
|
610
|
+
"aria-label": n,
|
|
611
|
+
"aria-valuemin": t,
|
|
612
|
+
"aria-valuemax": e,
|
|
613
|
+
"aria-valuenow": a,
|
|
614
|
+
"aria-valuetext": r ? r(a) : this.formatValue(a)
|
|
615
|
+
}),
|
|
616
|
+
...this.renderMarks()
|
|
617
|
+
),
|
|
618
|
+
...this.renderLabels(),
|
|
619
|
+
...o ? [
|
|
620
|
+
l(
|
|
621
|
+
"div",
|
|
622
|
+
{
|
|
623
|
+
id: `${this.id}-hint`,
|
|
624
|
+
style: {
|
|
625
|
+
fontSize: "12px",
|
|
626
|
+
color: "#666",
|
|
627
|
+
marginTop: "4px"
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
d(o)
|
|
631
|
+
)
|
|
632
|
+
] : []
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function w(p, t = {}) {
|
|
637
|
+
const e = { ...t, value: p }, i = new V(e);
|
|
638
|
+
return g(i);
|
|
639
|
+
}
|
|
640
|
+
export {
|
|
641
|
+
k as S,
|
|
642
|
+
w as a
|
|
643
|
+
};
|
|
644
|
+
//# sourceMappingURL=Slider-0-oal5YR.js.map
|