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 u } from "../../../helpers/cn.js";
2
- import { HelperRow as ft } from "../../../helpers/HelperRow.js";
3
- import { useHelperSlot as pt } from "../../../helpers/useHelperSlot.js";
4
- import y from "./StyledSlider.module.js";
5
- import { useId as ht, useRef as O, useState as Q } from "react";
6
- import { jsx as b, jsxs as H } from "react/jsx-runtime";
7
- var U = (i, l, o) => o === l ? 0 : Math.min(100, Math.max(0, (i - l) / (o - l) * 100)), mt = (i) => Array.isArray(i) ? [i[0] ?? 0, i[1] ?? 0] : null, wt = ({ dataTest: i, min: l = 0, max: o = 100, step: h = 1, value: w, defaultValue: W, disabled: s, size: z = "medium", orientation: C = "horizontal", marks: M, name: Z, className: k, classes: d, slotProps: x, error: v, errorText: tt, helperText: L, reserveHelperText: et, ariaLabel: S, ariaLabelledBy: rt, onChange: A, onChangeCommitted: _ }) => {
8
- const j = ht(), n = C === "vertical", a = z === "small" ? 6 : 8, f = O(null), g = O(null), [lt, N] = Q(null), [nt, F] = Q(W ?? l), I = lt ?? w ?? nt, c = mt(I), p = c !== null, B = v ? tt ?? L : L, { show: K, role: ot } = pt("StyledSlider", v, B, et), V = (M === !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(M) ? M : []).filter((t) => t.value >= l && t.value <= o), X = p ? Math.min(c[0], c[1]) : l, R = p ? Math.max(c[0], c[1]) : I, Y = (t) => p ? t >= X && t <= R : t <= R, $ = p ? U(X, l, o) : 0, q = U(R, l, o) - $, at = n ? {
9
- bottom: `${$}%`,
10
- height: `${q}%`
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: `${q}%`
14
- }, E = (t) => {
15
- const r = U(t, l, o);
16
- return n ? { bottom: `${r}%` } : { left: `${r}%` };
17
- }, T = (t) => {
18
- const r = t.currentTarget.getBoundingClientRect(), e = n ? 1 - (t.clientY - (r.top + a)) / (r.height - a * 2) : (t.clientX - (r.left + a)) / (r.width - a * 2), m = l + Math.round(Math.min(1, Math.max(0, e)) * ((o - l) / h)) * h;
19
- return Math.min(o, Math.max(l, m));
20
- }, ct = (t) => p && Math.abs((c?.[1] ?? l) - t) < Math.abs((c?.[0] ?? l) - t) ? 1 : 0, ut = (t) => {
21
- if (s) return;
22
- const r = T(t), e = ct(r);
23
- f.current = e, g.current = t.pointerId, t.currentTarget.setPointerCapture(t.pointerId);
24
- const m = P(r, e);
25
- N(m), A?.(t, m, e);
26
- }, it = (t) => {
27
- if (s || f.current === null || t.pointerId !== g.current) return;
28
- const r = f.current, e = P(T(t), r);
29
- N(e), A?.(t, e, r);
30
- }, st = (t) => {
31
- if (s || f.current === null || t.pointerId !== g.current) return;
32
- const r = f.current, e = P(T(t), r);
33
- w === void 0 && F(e), _?.(t, e), t.currentTarget.hasPointerCapture(t.pointerId) && t.currentTarget.releasePointerCapture(t.pointerId), N(null), f.current = null, g.current = null;
34
- }, dt = (t) => {
35
- f.current === null || t.pointerId !== g.current || (N(null), f.current = null, g.current = null);
36
- }, P = (t, r) => {
37
- if (!p) return t;
38
- const e = [c?.[0] ?? 0, c?.[1] ?? 0];
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
- }, G = (t, r, e, m) => {
41
- const J = P(e, m);
42
- w === void 0 && F(J), t && t(r, J, m);
43
- }, D = (t, r) => /* @__PURE__ */ b("input", {
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": p ? `${i}-thumb-${t}` : i,
46
- name: Z,
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: s,
52
- "aria-orientation": C,
53
- "aria-label": typeof S == "function" ? S(t) : S,
54
- "aria-labelledby": rt,
55
- "aria-invalid": v ? !0 : void 0,
56
- "aria-describedby": K ? j : void 0,
57
- className: u(y.SliderInput, n ? y.Vertical : y.Horizontal, !n && "z-0", z === "small" && y.Small, s && y.Disabled, d?.thumb, x?.thumb?.className),
58
- onChange: (e) => G(A, e, Number(e.currentTarget.value), t),
59
- onKeyUp: (e) => G(_, e, Number(e.currentTarget.value), t)
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__ */ H("div", {
62
- className: u("relative flex", n ? "h-full w-8 flex-col items-center" : "mt-px w-full flex-col", d?.root, k),
63
- children: [
64
- /* @__PURE__ */ H("div", {
65
- className: u("relative", n ? "h-full w-8" : "h-4 w-full", s ? "cursor-default" : "cursor-pointer"),
66
- style: { touchAction: "none" },
67
- onPointerDown: ut,
68
- onPointerMove: it,
69
- onPointerUp: st,
70
- onPointerCancel: dt,
71
- children: [/* @__PURE__ */ H("div", {
72
- className: u("absolute", n ? "left-1/2 w-1 -translate-x-1/2" : "top-[calc(50%+6px)] h-1 -translate-y-1/2"),
73
- style: n ? {
74
- top: a,
75
- bottom: a
76
- } : {
77
- left: a,
78
- right: a
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__ */ b("div", { className: u("absolute inset-0 rounded-full bg-delta-100", d?.rail, x?.rail?.className) }),
82
- /* @__PURE__ */ b("div", {
83
- className: u("absolute rounded-full", n ? "left-0 w-full" : "top-0 h-full", s ? "bg-delta-200" : "bg-gama-500", d?.track),
84
- style: at
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
- V.map((t) => {
87
- const r = Y(t.value);
88
- return /* @__PURE__ */ b("span", {
89
- className: u("absolute z-10 box-border h-2 w-2 -translate-x-1/2 rounded-full border border-solid", n ? "left-1/2 translate-y-1/2" : "top-1/2 -translate-y-1/2", r ? u(s ? "border-delta-200 bg-delta-200" : "border-gama-500 bg-gama-500", d?.markActive) : u("border-delta-300 bg-white", d?.mark)),
90
- style: E(t.value)
91
- }, t.value);
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
- }), p ? [D(0, c[0]), D(1, c[1])] : D(0, I)]
95
- }),
96
- V.some((t) => t.label != null) && /* @__PURE__ */ b("div", {
97
- className: u(n ? "pointer-events-none absolute inset-x-0" : "relative mt-[14px] h-6"),
98
- style: n ? {
99
- top: a,
100
- bottom: a
101
- } : {
102
- marginLeft: a,
103
- marginRight: a
104
- },
105
- children: V.map((t) => t.label == null ? null : /* @__PURE__ */ b("span", {
106
- className: u("absolute text-base font-semibold text-delta-700", n ? "left-[37px] translate-y-1/2" : "-translate-x-1/2", Y(t.value) && d?.markLabelActive, d?.markLabel, x?.markLabel?.className),
107
- style: E(t.value),
108
- children: t.label
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
- wt as StyledSlider
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 {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.86.0",
6
+ "version": "3.86.1",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",