asma-ui-core 3.86.0 → 3.86.1
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.
|
@@ -1,123 +1,174 @@
|
|
|
1
|
-
import { cn as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { cn as c } from "../../../helpers/cn.js";
|
|
2
|
+
import { PlusIcon as yt } from "../../icons/plus-icon/PlusIcon.js";
|
|
3
|
+
import { RemoveIcon as xt } from "../../icons/remove-icon/RemoveIcon.js";
|
|
4
|
+
import { StyledButton as tt } from "../button/StyledButton.js";
|
|
5
|
+
import { HelperRow as Nt } from "../../../helpers/HelperRow.js";
|
|
6
|
+
import { useHelperSlot as Mt } from "../../../helpers/useHelperSlot.js";
|
|
7
|
+
import x from "./StyledSlider.module.js";
|
|
8
|
+
import { useId as Pt, useRef as et, useState as rt } from "react";
|
|
9
|
+
import { jsx as i, jsxs as y } from "react/jsx-runtime";
|
|
10
|
+
var j = (m, l, o) => o === l ? 0 : Math.min(100, Math.max(0, (m - l) / (o - l) * 100)), It = (m) => Array.isArray(m) ? [m[0] ?? 0, m[1] ?? 0] : null, Ut = ({ dataTest: m, min: l = 0, max: o = 100, step: h = 1, value: V, defaultValue: lt, disabled: u, size: B = "medium", orientation: F = "horizontal", marks: A, name: at, className: nt, classes: p, slotProps: R, error: N, errorText: ot, helperText: K, reserveHelperText: ct, fromLabel: T, toLabel: D, showButtons: X, ariaLabel: $, ariaLabelledBy: it, onChange: M, onChangeCommitted: k }) => {
|
|
11
|
+
const Y = Pt(), a = F === "vertical", s = B === "small" ? 6 : 8, b = et(null), g = et(null), [st, P] = rt(null), [ut, q] = rt(lt ?? l), v = st ?? V ?? ut, n = It(v), d = n !== null, E = N ? ot ?? K : K, { show: G, role: dt } = Mt("StyledSlider", N, E, ct), H = (A === !0 && Number.isFinite(h) && h > 0 && o > l ? Array.from({ length: Math.floor((o - l) / h) + 1 }, (t, r) => ({ value: l + h * r })) : Array.isArray(A) ? A : []).filter((t) => t.value >= l && t.value <= o), J = d ? Math.min(n[0], n[1]) : l, U = d ? Math.max(n[0], n[1]) : v, O = (t) => d ? t >= J && t <= U : t <= U, ft = d ? Math.min(n[0], n[1]) <= l : v <= l, ht = d ? Math.max(n[0], n[1]) >= o : v >= o, z = d ? j(J, l, o) : 0, Q = j(U, l, o) - z, mt = a ? {
|
|
12
|
+
bottom: `${z}%`,
|
|
13
|
+
height: `${Q}%`
|
|
11
14
|
} : {
|
|
12
|
-
left: `${
|
|
13
|
-
width: `${
|
|
14
|
-
},
|
|
15
|
-
const r =
|
|
16
|
-
return
|
|
17
|
-
},
|
|
18
|
-
const r = t.currentTarget.getBoundingClientRect(), e =
|
|
19
|
-
return Math.min(o, Math.max(l,
|
|
20
|
-
},
|
|
21
|
-
if (
|
|
22
|
-
const r =
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
if (
|
|
28
|
-
const r =
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
if (
|
|
32
|
-
const r =
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
if (
|
|
38
|
-
const e =
|
|
15
|
+
left: `${z}%`,
|
|
16
|
+
width: `${Q}%`
|
|
17
|
+
}, W = (t) => {
|
|
18
|
+
const r = j(t, l, o);
|
|
19
|
+
return a ? { bottom: `${r}%` } : { left: `${r}%` };
|
|
20
|
+
}, C = (t) => {
|
|
21
|
+
const r = t.currentTarget.getBoundingClientRect(), e = a ? 1 - (t.clientY - (r.top + s)) / (r.height - s * 2) : (t.clientX - (r.left + s)) / (r.width - s * 2), f = l + Math.round(Math.min(1, Math.max(0, e)) * ((o - l) / h)) * h;
|
|
22
|
+
return Math.min(o, Math.max(l, f));
|
|
23
|
+
}, pt = (t) => d && Math.abs((n?.[1] ?? l) - t) < Math.abs((n?.[0] ?? l) - t) ? 1 : 0, bt = (t) => {
|
|
24
|
+
if (u) return;
|
|
25
|
+
const r = C(t), e = pt(r);
|
|
26
|
+
b.current = e, g.current = t.pointerId, t.currentTarget.setPointerCapture(t.pointerId);
|
|
27
|
+
const f = I(r, e);
|
|
28
|
+
P(f), M?.(t, f, e);
|
|
29
|
+
}, gt = (t) => {
|
|
30
|
+
if (u || b.current === null || t.pointerId !== g.current) return;
|
|
31
|
+
const r = b.current, e = I(C(t), r);
|
|
32
|
+
P(e), M?.(t, e, r);
|
|
33
|
+
}, vt = (t) => {
|
|
34
|
+
if (u || b.current === null || t.pointerId !== g.current) return;
|
|
35
|
+
const r = b.current, e = I(C(t), r);
|
|
36
|
+
V === void 0 && q(e), k?.(t, e), t.currentTarget.hasPointerCapture(t.pointerId) && t.currentTarget.releasePointerCapture(t.pointerId), P(null), b.current = null, g.current = null;
|
|
37
|
+
}, wt = (t) => {
|
|
38
|
+
b.current === null || t.pointerId !== g.current || (P(null), b.current = null, g.current = null);
|
|
39
|
+
}, Z = (t) => (r) => {
|
|
40
|
+
if (u) return;
|
|
41
|
+
const e = t === "increment" ? h || 1 : -(h || 1);
|
|
42
|
+
let f = 0, w;
|
|
43
|
+
d ? (f = t === "increment" ? 1 : 0, w = t === "increment" ? Math.max(n[0], n[1]) : Math.min(n[0], n[1])) : w = v;
|
|
44
|
+
const L = Math.min(o, Math.max(l, w + e));
|
|
45
|
+
S(M, r, L, f), S(k, r, L, f);
|
|
46
|
+
}, I = (t, r) => {
|
|
47
|
+
if (!d) return t;
|
|
48
|
+
const e = [n?.[0] ?? 0, n?.[1] ?? 0];
|
|
39
49
|
return e[r] = t, r === 0 && e[0] > e[1] && (e[0] = e[1]), r === 1 && e[1] < e[0] && (e[1] = e[0]), e;
|
|
40
|
-
},
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
},
|
|
50
|
+
}, S = (t, r, e, f) => {
|
|
51
|
+
const w = I(e, f);
|
|
52
|
+
V === void 0 && q(w), t && t(r, w, f);
|
|
53
|
+
}, _ = (t, r) => /* @__PURE__ */ i("input", {
|
|
44
54
|
type: "range",
|
|
45
|
-
"data-testid":
|
|
46
|
-
name:
|
|
55
|
+
"data-testid": d ? `${m}-thumb-${t}` : m,
|
|
56
|
+
name: at,
|
|
47
57
|
min: l,
|
|
48
58
|
max: o,
|
|
49
59
|
step: h,
|
|
50
60
|
value: r,
|
|
51
|
-
disabled:
|
|
52
|
-
"aria-orientation":
|
|
53
|
-
"aria-label": typeof
|
|
54
|
-
"aria-labelledby":
|
|
55
|
-
"aria-invalid":
|
|
56
|
-
"aria-describedby":
|
|
57
|
-
className:
|
|
58
|
-
onChange: (e) =>
|
|
59
|
-
onKeyUp: (e) =>
|
|
61
|
+
disabled: u,
|
|
62
|
+
"aria-orientation": F,
|
|
63
|
+
"aria-label": typeof $ == "function" ? $(t) : $,
|
|
64
|
+
"aria-labelledby": it,
|
|
65
|
+
"aria-invalid": N ? !0 : void 0,
|
|
66
|
+
"aria-describedby": G ? Y : void 0,
|
|
67
|
+
className: c(x.SliderInput, a ? x.Vertical : x.Horizontal, !a && "z-0", B === "small" && x.Small, u && x.Disabled, p?.thumb, R?.thumb?.className),
|
|
68
|
+
onChange: (e) => S(M, e, Number(e.currentTarget.value), t),
|
|
69
|
+
onKeyUp: (e) => S(k, e, Number(e.currentTarget.value), t)
|
|
60
70
|
}, t);
|
|
61
|
-
return /* @__PURE__ */
|
|
62
|
-
className:
|
|
63
|
-
children: [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
return /* @__PURE__ */ y("div", {
|
|
72
|
+
className: c("flex max-w-[600px] flex-col gap-3", a && "h-full"),
|
|
73
|
+
children: [!a && (T ?? D) && /* @__PURE__ */ y("div", {
|
|
74
|
+
className: "grid w-full grid-cols-2 gap-4",
|
|
75
|
+
children: [!a && T && /* @__PURE__ */ i("span", {
|
|
76
|
+
className: "min-w-0 break-words text-left font-normal text-delta-800",
|
|
77
|
+
children: T
|
|
78
|
+
}), !a && D && /* @__PURE__ */ i("span", {
|
|
79
|
+
className: "min-w-0 break-words text-right font-normal text-delta-800",
|
|
80
|
+
children: D
|
|
81
|
+
})]
|
|
82
|
+
}), /* @__PURE__ */ y("div", {
|
|
83
|
+
className: c("flex", !a && "w-full items-start gap-3", a && "h-full flex-col items-center"),
|
|
84
|
+
children: [
|
|
85
|
+
!a && X && /* @__PURE__ */ i(tt, {
|
|
86
|
+
dataTest: "slider-from-button",
|
|
87
|
+
"aria-label": "Decrease value",
|
|
88
|
+
className: "-mt-0.5 w-8",
|
|
89
|
+
variant: "outlined",
|
|
90
|
+
disabled: u ?? ft,
|
|
91
|
+
startIcon: /* @__PURE__ */ i(xt, {
|
|
92
|
+
width: 24,
|
|
93
|
+
height: 24
|
|
94
|
+
}),
|
|
95
|
+
onClick: Z("decrement")
|
|
96
|
+
}),
|
|
97
|
+
/* @__PURE__ */ y("div", {
|
|
98
|
+
className: c("relative flex", a ? "h-full w-8 flex-col items-center" : "mt-px w-full flex-col", p?.root, nt),
|
|
80
99
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
/* @__PURE__ */ y("div", {
|
|
101
|
+
className: c("relative", a ? "h-full w-8" : "h-4 w-full", u ? "cursor-default" : "cursor-pointer"),
|
|
102
|
+
style: { touchAction: "none" },
|
|
103
|
+
onPointerDown: bt,
|
|
104
|
+
onPointerMove: gt,
|
|
105
|
+
onPointerUp: vt,
|
|
106
|
+
onPointerCancel: wt,
|
|
107
|
+
children: [/* @__PURE__ */ y("div", {
|
|
108
|
+
className: c("absolute", a ? "left-1/2 w-1 -translate-x-1/2" : "top-[calc(50%+6px)] h-1 -translate-y-1/2"),
|
|
109
|
+
style: a ? {
|
|
110
|
+
top: s,
|
|
111
|
+
bottom: s
|
|
112
|
+
} : {
|
|
113
|
+
left: s,
|
|
114
|
+
right: s
|
|
115
|
+
},
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ i("div", { className: c("absolute inset-0 rounded-full bg-delta-100", p?.rail, R?.rail?.className) }),
|
|
118
|
+
/* @__PURE__ */ i("div", {
|
|
119
|
+
className: c("absolute rounded-full", a ? "left-0 w-full" : "top-0 h-full", u ? "bg-delta-200" : "bg-gama-500", p?.track),
|
|
120
|
+
style: mt
|
|
121
|
+
}),
|
|
122
|
+
H.map((t) => {
|
|
123
|
+
const r = O(t.value);
|
|
124
|
+
return /* @__PURE__ */ i("span", {
|
|
125
|
+
className: c("absolute z-10 box-border h-2 w-2 -translate-x-1/2 rounded-full border border-solid", a ? "left-1/2 translate-y-1/2" : "top-1/2 -translate-y-1/2", r ? c(u ? "border-delta-200 bg-delta-200" : "border-gama-500 bg-gama-500", p?.markActive) : c("border-delta-300 bg-white", p?.mark)),
|
|
126
|
+
style: W(t.value)
|
|
127
|
+
}, t.value);
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}), d ? [_(0, n[0]), _(1, n[1])] : _(0, v)]
|
|
85
131
|
}),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
132
|
+
H.some((t) => t.label != null) && /* @__PURE__ */ i("div", {
|
|
133
|
+
className: c(a ? "pointer-events-none absolute inset-x-0" : "relative mt-[14px] h-6"),
|
|
134
|
+
style: a ? {
|
|
135
|
+
top: s,
|
|
136
|
+
bottom: s
|
|
137
|
+
} : {
|
|
138
|
+
marginLeft: s,
|
|
139
|
+
marginRight: s
|
|
140
|
+
},
|
|
141
|
+
children: H.map((t) => t.label == null ? null : /* @__PURE__ */ i("span", {
|
|
142
|
+
className: c("absolute text-base font-semibold text-delta-700", a ? "left-[37px] translate-y-1/2" : "-translate-x-1/2", O(t.value) && p?.markLabelActive, p?.markLabel, R?.markLabel?.className),
|
|
143
|
+
style: W(t.value),
|
|
144
|
+
children: t.label
|
|
145
|
+
}, t.value))
|
|
146
|
+
}),
|
|
147
|
+
G && /* @__PURE__ */ i(Nt, {
|
|
148
|
+
id: Y,
|
|
149
|
+
role: dt,
|
|
150
|
+
error: N,
|
|
151
|
+
message: E,
|
|
152
|
+
className: "m-0 items-center"
|
|
92
153
|
})
|
|
93
154
|
]
|
|
94
|
-
}),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, t.value))
|
|
110
|
-
}),
|
|
111
|
-
K && /* @__PURE__ */ b(ft, {
|
|
112
|
-
id: j,
|
|
113
|
-
role: ot,
|
|
114
|
-
error: v,
|
|
115
|
-
message: B,
|
|
116
|
-
className: "m-0 items-center"
|
|
117
|
-
})
|
|
118
|
-
]
|
|
155
|
+
}),
|
|
156
|
+
!a && X && /* @__PURE__ */ i(tt, {
|
|
157
|
+
dataTest: "slider-to-button",
|
|
158
|
+
"aria-label": "Increase value",
|
|
159
|
+
className: "-mt-0.5 w-8",
|
|
160
|
+
variant: "outlined",
|
|
161
|
+
disabled: u ?? ht,
|
|
162
|
+
startIcon: /* @__PURE__ */ i(yt, {
|
|
163
|
+
width: 24,
|
|
164
|
+
height: 24
|
|
165
|
+
}),
|
|
166
|
+
onClick: Z("increment")
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
})]
|
|
119
170
|
});
|
|
120
171
|
};
|
|
121
172
|
export {
|
|
122
|
-
|
|
173
|
+
Ut as StyledSlider
|
|
123
174
|
};
|
|
@@ -50,6 +50,9 @@ export interface StyledSliderProps {
|
|
|
50
50
|
errorText?: string;
|
|
51
51
|
helperText?: string;
|
|
52
52
|
reserveHelperText?: boolean;
|
|
53
|
+
fromLabel?: ReactNode;
|
|
54
|
+
toLabel?: ReactNode;
|
|
55
|
+
showButtons?: boolean;
|
|
53
56
|
/** Accessible name for the thumb input(s) — there is no visible label to derive it from
|
|
54
57
|
* (axe `label`). A function receives the thumb index (0, or 0/1 for a two-thumb range) so each
|
|
55
58
|
* thumb of a range slider can get a distinct name. */
|
|
@@ -67,5 +70,5 @@ export interface StyledSliderProps {
|
|
|
67
70
|
* CI is the visual gate. Upgrade path: tune the 8px thumb inset if a diff shows misalignment.
|
|
68
71
|
* TASK-204.
|
|
69
72
|
*/
|
|
70
|
-
export declare const StyledSlider: ({ dataTest, min, max, step, value, defaultValue, disabled, size, orientation, marks, name, className, classes, slotProps, error, errorText, helperText, reserveHelperText, ariaLabel, ariaLabelledBy, onChange, onChangeCommitted, }: StyledSliderProps) => JSX.Element;
|
|
73
|
+
export declare const StyledSlider: ({ dataTest, min, max, step, value, defaultValue, disabled, size, orientation, marks, name, className, classes, slotProps, error, errorText, helperText, reserveHelperText, fromLabel, toLabel, showButtons, ariaLabel, ariaLabelledBy, onChange, onChangeCommitted, }: StyledSliderProps) => JSX.Element;
|
|
71
74
|
export {};
|