@namroodinc/liquid-editorial 0.2.1 → 0.3.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.
- package/README.md +26 -1
- package/UPGRADING.md +100 -0
- package/dist/chunks/{FormEditor-DuW8x78Y.js → FormEditor-DRmPFe2E.js} +100 -102
- package/dist/chunks/FormEditor-DRmPFe2E.js.map +1 -0
- package/dist/chunks/FormEditor-PVkvKep1.cjs +2 -0
- package/dist/chunks/FormEditor-PVkvKep1.cjs.map +1 -0
- package/dist/chunks/{RichTextEditor-BxtlbjXj.cjs → RichTextEditor-C7nMfDmE.cjs} +2 -2
- package/dist/chunks/RichTextEditor-C7nMfDmE.cjs.map +1 -0
- package/dist/chunks/{RichTextEditor-Dnx4i7bQ.js → RichTextEditor-DjR10XJ-.js} +55 -53
- package/dist/chunks/RichTextEditor-DjR10XJ-.js.map +1 -0
- package/dist/chunks/binding-Bshy43sG.js +33 -0
- package/dist/chunks/binding-Bshy43sG.js.map +1 -0
- package/dist/chunks/binding-tMjrUzkU.cjs +2 -0
- package/dist/chunks/binding-tMjrUzkU.cjs.map +1 -0
- package/dist/chunks/context-BONPXF-V.cjs +2 -0
- package/dist/chunks/context-BONPXF-V.cjs.map +1 -0
- package/dist/chunks/context-CXvOl4Kt.js +7 -0
- package/dist/chunks/context-CXvOl4Kt.js.map +1 -0
- package/dist/chunks/frame-Bs_jaQRw.js +70 -0
- package/dist/chunks/frame-Bs_jaQRw.js.map +1 -0
- package/dist/chunks/frame-CNxvbg0D.cjs +2 -0
- package/dist/chunks/frame-CNxvbg0D.cjs.map +1 -0
- package/dist/chunks/group-CzbacuAY.js +29 -0
- package/dist/chunks/group-CzbacuAY.js.map +1 -0
- package/dist/chunks/group-pKDQtq-9.cjs +2 -0
- package/dist/chunks/group-pKDQtq-9.cjs.map +1 -0
- package/dist/components/Badge/index.cjs +1 -1
- package/dist/components/Badge/index.cjs.map +1 -1
- package/dist/components/Badge/index.d.cts +2 -0
- package/dist/components/Badge/index.d.cts.map +1 -1
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Badge/index.d.ts.map +1 -1
- package/dist/components/Badge/index.js +8 -8
- package/dist/components/Badge/index.js.map +1 -1
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.d.cts +3 -3
- package/dist/components/Choice/index.d.cts.map +1 -1
- package/dist/components/Choice/index.d.ts +3 -3
- package/dist/components/Choice/index.d.ts.map +1 -1
- package/dist/components/Choice/index.js +27 -27
- package/dist/components/Choice/index.js.map +1 -1
- package/dist/components/Choice/style.css +0 -7
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.cjs.map +1 -1
- package/dist/components/DatePicker/index.d.cts +5 -9
- package/dist/components/DatePicker/index.d.cts.map +1 -1
- package/dist/components/DatePicker/index.d.ts +5 -9
- package/dist/components/DatePicker/index.d.ts.map +1 -1
- package/dist/components/DatePicker/index.js +124 -120
- package/dist/components/DatePicker/index.js.map +1 -1
- package/dist/components/DatePicker/style.css +15 -1
- package/dist/components/EditLayout/style.css +0 -1
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.cjs.map +1 -1
- package/dist/components/EntryPicker/index.d.cts +3 -2
- package/dist/components/EntryPicker/index.d.cts.map +1 -1
- package/dist/components/EntryPicker/index.d.ts +3 -2
- package/dist/components/EntryPicker/index.d.ts.map +1 -1
- package/dist/components/EntryPicker/index.js +39 -46
- package/dist/components/EntryPicker/index.js.map +1 -1
- package/dist/components/EntryPicker/style.css +0 -11
- package/dist/components/Field/binding.d.cts +18 -0
- package/dist/components/Field/binding.d.cts.map +1 -0
- package/dist/components/Field/binding.d.ts +18 -0
- package/dist/components/Field/binding.d.ts.map +1 -0
- package/dist/components/Field/context.d.cts +9 -0
- package/dist/components/Field/context.d.cts.map +1 -0
- package/dist/components/Field/context.d.ts +9 -0
- package/dist/components/Field/context.d.ts.map +1 -0
- package/dist/components/Field/frame.d.cts +12 -0
- package/dist/components/Field/frame.d.cts.map +1 -0
- package/dist/components/Field/frame.d.ts +12 -0
- package/dist/components/Field/frame.d.ts.map +1 -0
- package/dist/components/Field/group.d.cts +12 -0
- package/dist/components/Field/group.d.cts.map +1 -0
- package/dist/components/Field/group.d.ts +12 -0
- package/dist/components/Field/group.d.ts.map +1 -0
- package/dist/components/Field/index.cjs +1 -1
- package/dist/components/Field/index.cjs.map +1 -1
- package/dist/components/Field/index.d.cts +4 -22
- package/dist/components/Field/index.d.cts.map +1 -1
- package/dist/components/Field/index.d.ts +4 -22
- package/dist/components/Field/index.d.ts.map +1 -1
- package/dist/components/Field/index.js +5 -42
- package/dist/components/Field/index.js.map +1 -1
- package/dist/components/Field/style.css +5 -0
- package/dist/components/Field/types.d.cts +31 -0
- package/dist/components/Field/types.d.cts.map +1 -0
- package/dist/components/Field/types.d.ts +31 -0
- package/dist/components/Field/types.d.ts.map +1 -0
- package/dist/components/FormEditor/control.d.cts +5 -3
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts +5 -3
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.d.cts.map +1 -1
- package/dist/components/FormEditor/index.d.ts.map +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/FormEditor/model.d.cts +8 -5
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +8 -5
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/ImageCropper/index.cjs +1 -1
- package/dist/components/ImageCropper/index.cjs.map +1 -1
- package/dist/components/ImageCropper/index.d.cts.map +1 -1
- package/dist/components/ImageCropper/index.d.ts.map +1 -1
- package/dist/components/ImageCropper/index.js +113 -112
- package/dist/components/ImageCropper/index.js.map +1 -1
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.cjs.map +1 -1
- package/dist/components/NumberField/index.d.cts +4 -3
- package/dist/components/NumberField/index.d.cts.map +1 -1
- package/dist/components/NumberField/index.d.ts +4 -3
- package/dist/components/NumberField/index.d.ts.map +1 -1
- package/dist/components/NumberField/index.js +57 -53
- package/dist/components/NumberField/index.js.map +1 -1
- package/dist/components/NumberField/style.css +16 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts +3 -7
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +3 -7
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.cjs.map +1 -1
- package/dist/components/Select/index.d.cts +1 -0
- package/dist/components/Select/index.d.cts.map +1 -1
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/Select/index.d.ts.map +1 -1
- package/dist/components/Select/index.js +53 -52
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.d.cts +3 -2
- package/dist/components/SelectionCard/index.d.cts.map +1 -1
- package/dist/components/SelectionCard/index.d.ts +3 -2
- package/dist/components/SelectionCard/index.d.ts.map +1 -1
- package/dist/components/SelectionCard/index.js +28 -28
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SelectionCard/style.css +1 -8
- package/dist/components/Slider/index.cjs +1 -1
- package/dist/components/Slider/index.cjs.map +1 -1
- package/dist/components/Slider/index.d.cts +8 -3
- package/dist/components/Slider/index.d.cts.map +1 -1
- package/dist/components/Slider/index.d.ts +8 -3
- package/dist/components/Slider/index.d.ts.map +1 -1
- package/dist/components/Slider/index.js +76 -66
- package/dist/components/Slider/index.js.map +1 -1
- package/dist/components/Slider/style.css +14 -0
- package/dist/components/Switch/index.cjs +1 -1
- package/dist/components/Switch/index.cjs.map +1 -1
- package/dist/components/Switch/index.d.cts +2 -0
- package/dist/components/Switch/index.d.cts.map +1 -1
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Switch/index.js +13 -12
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Switch/style.css +4 -0
- package/dist/components/TagsInput/index.cjs +1 -1
- package/dist/components/TagsInput/index.cjs.map +1 -1
- package/dist/components/TagsInput/index.d.cts +2 -5
- package/dist/components/TagsInput/index.d.cts.map +1 -1
- package/dist/components/TagsInput/index.d.ts +2 -5
- package/dist/components/TagsInput/index.d.ts.map +1 -1
- package/dist/components/TagsInput/index.js +19 -17
- package/dist/components/TagsInput/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/chunks/FormEditor-8bz3pOdP.cjs +0 -2
- package/dist/chunks/FormEditor-8bz3pOdP.cjs.map +0 -1
- package/dist/chunks/FormEditor-DuW8x78Y.js.map +0 -1
- package/dist/chunks/RichTextEditor-BxtlbjXj.cjs.map +0 -1
- package/dist/chunks/RichTextEditor-Dnx4i7bQ.js.map +0 -1
|
@@ -8,125 +8,126 @@ import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
|
8
8
|
function d(...e) {
|
|
9
9
|
return e.filter(Boolean).join(" ");
|
|
10
10
|
}
|
|
11
|
-
var f = r(function({ options: r, value: f, defaultValue: p, onValueChange: m, placeholder: h = "Select an option", size: g = "md", isDisabled: _ = !1, isInvalid: v = !1,
|
|
12
|
-
let [
|
|
13
|
-
f === void 0 &&
|
|
11
|
+
var f = r(function({ options: r, value: f, defaultValue: p, onValueChange: m, placeholder: h = "Select an option", size: g = "md", isDisabled: _ = !1, isInvalid: v = !1, "aria-invalid": y, required: b, menuPlacement: x = "bottom", className: S, disabled: C, onClick: w, onKeyDown: T, ...E }, D) {
|
|
12
|
+
let [O, k] = c(p ?? ""), A = f ?? O, [j, M] = c(!1), [N, P] = c(0), F = s(null), I = s(null), L = s(null), R = o(), z = _ || C, B = j && !z, V = r.find((e) => e.value === A), H = r.filter((e) => !e.isDisabled), U = i((e) => {
|
|
13
|
+
f === void 0 && k(e), m?.(e), M(!1);
|
|
14
14
|
}, [m, f]);
|
|
15
15
|
a(() => {
|
|
16
|
-
if (!
|
|
17
|
-
let e = r.findIndex((e) => e.value ===
|
|
18
|
-
|
|
16
|
+
if (!B) return;
|
|
17
|
+
let e = r.findIndex((e) => e.value === A && !e.isDisabled);
|
|
18
|
+
P(e < 0 ? r.indexOf(H[0]) : e);
|
|
19
19
|
let t = (e) => {
|
|
20
20
|
let t = e.target;
|
|
21
|
-
!
|
|
21
|
+
!F.current?.contains(t) && !L.current?.contains(t) && M(!1);
|
|
22
22
|
};
|
|
23
23
|
return document.addEventListener("mousedown", t), () => document.removeEventListener("mousedown", t);
|
|
24
|
-
}, [
|
|
25
|
-
|
|
26
|
-
}, [
|
|
27
|
-
let
|
|
24
|
+
}, [B]), a(() => {
|
|
25
|
+
B && (L.current?.querySelectorAll("[role='option']")[N])?.scrollIntoView({ block: "nearest" });
|
|
26
|
+
}, [N, B]);
|
|
27
|
+
let W = (e) => {
|
|
28
28
|
let t = r.map((e, t) => ({
|
|
29
29
|
option: e,
|
|
30
30
|
index: t
|
|
31
31
|
})).filter((e) => !e.option.isDisabled);
|
|
32
32
|
if (t.length === 0) return;
|
|
33
|
-
let n = t[(t.findIndex((e) => e.index ===
|
|
34
|
-
|
|
35
|
-
},
|
|
33
|
+
let n = t[(t.findIndex((e) => e.index === N) + e + t.length) % t.length];
|
|
34
|
+
P(n.index);
|
|
35
|
+
}, G = (e) => {
|
|
36
36
|
switch (e.key) {
|
|
37
37
|
case "Escape":
|
|
38
|
-
e.preventDefault(),
|
|
38
|
+
e.preventDefault(), M(!1), I.current?.focus();
|
|
39
39
|
break;
|
|
40
40
|
case "Tab":
|
|
41
|
-
|
|
41
|
+
M(!1);
|
|
42
42
|
break;
|
|
43
43
|
case "ArrowDown":
|
|
44
44
|
case "ArrowUp":
|
|
45
|
-
e.preventDefault(),
|
|
45
|
+
e.preventDefault(), W(e.key === "ArrowDown" ? 1 : -1);
|
|
46
46
|
break;
|
|
47
47
|
case "Home":
|
|
48
48
|
case "End": {
|
|
49
49
|
e.preventDefault();
|
|
50
|
-
let t = e.key === "Home" ?
|
|
51
|
-
t &&
|
|
50
|
+
let t = e.key === "Home" ? H[0] : H[H.length - 1];
|
|
51
|
+
t && P(r.indexOf(t));
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
case "Enter":
|
|
55
55
|
case " ": {
|
|
56
56
|
e.preventDefault();
|
|
57
|
-
let t = r[
|
|
58
|
-
t && !t.isDisabled &&
|
|
57
|
+
let t = r[N];
|
|
58
|
+
t && !t.isDisabled && U(t.value);
|
|
59
59
|
break;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
},
|
|
63
|
-
|
|
62
|
+
}, K = (e) => {
|
|
63
|
+
z || (B ? G(e) : [
|
|
64
64
|
"ArrowDown",
|
|
65
65
|
"ArrowUp",
|
|
66
66
|
"Enter",
|
|
67
67
|
" "
|
|
68
|
-
].includes(e.key) && (e.preventDefault(),
|
|
68
|
+
].includes(e.key) && (e.preventDefault(), M(!0)));
|
|
69
69
|
};
|
|
70
70
|
return /* @__PURE__ */ u("div", {
|
|
71
71
|
className: "ds-select-root",
|
|
72
|
-
ref:
|
|
72
|
+
ref: F,
|
|
73
73
|
children: [/* @__PURE__ */ u(t, {
|
|
74
74
|
ref: (e) => {
|
|
75
|
-
|
|
75
|
+
I.current = e, typeof D == "function" ? D(e) : D && (D.current = e);
|
|
76
76
|
},
|
|
77
77
|
size: g,
|
|
78
78
|
role: "combobox",
|
|
79
|
+
"aria-required": b || void 0,
|
|
79
80
|
"aria-haspopup": "listbox",
|
|
80
|
-
"aria-expanded":
|
|
81
|
-
"aria-controls":
|
|
82
|
-
"aria-activedescendant":
|
|
83
|
-
"aria-invalid": v || void 0,
|
|
84
|
-
isDisabled:
|
|
85
|
-
"data-placeholder":
|
|
86
|
-
className: d("ds-field-skin", "ds-select",
|
|
81
|
+
"aria-expanded": B,
|
|
82
|
+
"aria-controls": B ? R : void 0,
|
|
83
|
+
"aria-activedescendant": B && r[N] && !r[N].isDisabled ? `${R}-option-${N}` : void 0,
|
|
84
|
+
"aria-invalid": v || y || void 0,
|
|
85
|
+
isDisabled: z,
|
|
86
|
+
"data-placeholder": V ? void 0 : "",
|
|
87
|
+
className: d("ds-field-skin", "ds-select", S),
|
|
87
88
|
onClick: (e) => {
|
|
88
|
-
|
|
89
|
+
w?.(e), e.defaultPrevented || M((e) => !e);
|
|
89
90
|
},
|
|
90
91
|
onKeyDown: (e) => {
|
|
91
|
-
|
|
92
|
+
T?.(e), e.defaultPrevented || K(e);
|
|
92
93
|
},
|
|
93
|
-
...
|
|
94
|
+
...E,
|
|
94
95
|
children: [/* @__PURE__ */ l("span", {
|
|
95
96
|
className: "ds-select__value",
|
|
96
|
-
children:
|
|
97
|
+
children: V ? V.label : h
|
|
97
98
|
}), /* @__PURE__ */ l(e, {
|
|
98
99
|
name: "chevron-down",
|
|
99
100
|
size: 16,
|
|
100
101
|
className: "ds-select__chevron"
|
|
101
102
|
})]
|
|
102
103
|
}), /* @__PURE__ */ l(n, {
|
|
103
|
-
anchorRef:
|
|
104
|
-
isOpen:
|
|
105
|
-
placement:
|
|
104
|
+
anchorRef: I,
|
|
105
|
+
isOpen: B,
|
|
106
|
+
placement: x,
|
|
106
107
|
matchAnchorWidth: !0,
|
|
107
|
-
panelRef:
|
|
108
|
-
id:
|
|
108
|
+
panelRef: L,
|
|
109
|
+
id: R,
|
|
109
110
|
role: "listbox",
|
|
110
|
-
"aria-label":
|
|
111
|
-
"aria-labelledby":
|
|
111
|
+
"aria-label": E["aria-labelledby"] ? void 0 : E["aria-label"] ?? h,
|
|
112
|
+
"aria-labelledby": E["aria-labelledby"],
|
|
112
113
|
className: "ds-surface-raised ds-select__menu",
|
|
113
114
|
children: /* @__PURE__ */ l("div", {
|
|
114
|
-
onKeyDown:
|
|
115
|
+
onKeyDown: K,
|
|
115
116
|
onPointerDown: (e) => e.preventDefault(),
|
|
116
117
|
children: r.map((n, r) => /* @__PURE__ */ u(t, {
|
|
117
|
-
variant: r ===
|
|
118
|
+
variant: r === N ? "active" : "simple",
|
|
118
119
|
size: "sm",
|
|
119
120
|
isDisabled: n.isDisabled,
|
|
120
121
|
tabIndex: -1,
|
|
121
|
-
id: `${
|
|
122
|
+
id: `${R}-option-${r}`,
|
|
122
123
|
role: "option",
|
|
123
|
-
"aria-selected": n.value ===
|
|
124
|
+
"aria-selected": n.value === A,
|
|
124
125
|
"aria-disabled": n.isDisabled || void 0,
|
|
125
|
-
"data-active": r ===
|
|
126
|
+
"data-active": r === N || void 0,
|
|
126
127
|
className: "ds-select__option",
|
|
127
|
-
onMouseEnter: () => !n.isDisabled &&
|
|
128
|
+
onMouseEnter: () => !n.isDisabled && P(r),
|
|
128
129
|
onClick: () => {
|
|
129
|
-
n.isDisabled || (
|
|
130
|
+
n.isDisabled || (U(n.value), I.current?.focus());
|
|
130
131
|
},
|
|
131
132
|
children: [/* @__PURE__ */ u("span", {
|
|
132
133
|
className: "ds-select__option-body",
|
|
@@ -137,7 +138,7 @@ var f = r(function({ options: r, value: f, defaultValue: p, onValueChange: m, pl
|
|
|
137
138
|
className: "ds-select__option-description",
|
|
138
139
|
children: n.description
|
|
139
140
|
})]
|
|
140
|
-
}), n.value ===
|
|
141
|
+
}), n.value === A && /* @__PURE__ */ l(e, {
|
|
141
142
|
name: "check",
|
|
142
143
|
size: 16
|
|
143
144
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) return;\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) setOpen(false);\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) return;\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) return;\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) setActiveIndex(options.indexOf(pick));\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) commit(option.value);\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) return;\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n size={size}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) setOpen((open) => !open);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) handleKeyDown(event);\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AA+BA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,mBAAgB,UAChB,cACA,aACA,YACA,cACA,GAAGC,KAEL,GACA;CACA,IAAM,CAACC,GAAUC,KAAeC,EAASC,KAAgB,EAAE,GACrDC,IAAUC,KAASL,GACnB,CAACM,GAAQC,KAAWL,EAAS,EAAK,GAClC,CAACM,GAAaC,KAAkBP,EAAS,CAAC,GAC1CQ,IAAUC,EAA8B,IAAI,GAC5CC,IAAaD,EAAiC,IAAI,GAClDE,IAAUF,EAA8B,IAAI,GAC5CG,IAASC,EAAM,GACfC,IAAoBC,KAAcC,GAClCC,IAAYb,KAAU,CAACU,GAEvBI,IAAWC,EAAQ,MAAM,MAAWC,EAAO,UAAUlB,CAAO,GAC5DmB,IAAUF,EAAQ,QAAQ,MAAW,CAACC,EAAO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E,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA4B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Icon","cx","parts","Select","forwardRef","ariaInvalid","rest","internal","setInternal","useState","defaultValue","current","value","isOpen","setOpen","activeIndex","setActiveIndex","rootRef","useRef","triggerRef","listRef","listId","useId","effectiveDisabled","isDisabled","disabled","isVisible","selected","options","option","enabled","commit","useCallback","next","onValueChange","useEffect","index","onPointerDown","target","event","step","order","o","delta","handleListKeyDown","pick","handleKeyDown","Button","node","ref","required","isInvalid","className","onClick","open","onKeyDown","placeholder","Popover","menuPlacement"],"sources":["../../../src/components/Select/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { Icon } from \"../Icon\";\nimport { Button } from \"../Button\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport type { FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nexport interface SelectOption {\n value: string;\n label: string;\n /** Secondary line under the label. */\n description?: string;\n isDisabled?: boolean;\n}\n\nexport interface SelectProps extends Omit<\n ButtonHTMLAttributes<HTMLButtonElement>,\n \"value\" | \"defaultValue\" | \"onChange\"\n> {\n required?: boolean;\n options: SelectOption[];\n /** Controlled value. Leave undefined to let the select hold its own. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n placeholder?: string;\n size?: FieldSize;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Preferred side of the menu; flips when space requires it. */\n menuPlacement?: PopoverPlacement;\n}\n\n/**\n * One value out of a known list. Wears the field skin, opens a listbox: arrows\n * walk the options, Enter commits, Escape closes without changing anything.\n */\nexport const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select(\n {\n options,\n value,\n defaultValue,\n onValueChange,\n placeholder = \"Select an option\",\n size = \"md\",\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n required,\n menuPlacement = \"bottom\",\n className,\n disabled,\n onClick,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [activeIndex, setActiveIndex] = useState(0);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const listId = useId();\n const effectiveDisabled = isDisabled || disabled;\n const isVisible = isOpen && !effectiveDisabled;\n\n const selected = options.find((option) => option.value === current);\n const enabled = options.filter((option) => !option.isDisabled);\n\n const commit = useCallback(\n (next: string) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n setOpen(false);\n },\n [onValueChange, value],\n );\n\n useEffect(() => {\n if (!isVisible) return;\n const index = options.findIndex((option) => option.value === current && !option.isDisabled);\n setActiveIndex(index < 0 ? options.indexOf(enabled[0]!) : index);\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !listRef.current?.contains(target)) setOpen(false);\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isVisible]);\n\n useEffect(() => {\n if (!isVisible) return;\n const activeOption =\n listRef.current?.querySelectorAll<HTMLElement>(\"[role='option']\")[activeIndex];\n activeOption?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, isVisible]);\n\n const step = (delta: number) => {\n const order = options\n .map((option, index) => ({ option, index }))\n .filter((o) => !o.option.isDisabled);\n if (order.length === 0) return;\n const at = order.findIndex((o) => o.index === activeIndex);\n const next = order[(at + delta + order.length) % order.length]!;\n setActiveIndex(next.index);\n };\n\n const handleListKeyDown = (event: React.KeyboardEvent) => {\n switch (event.key) {\n case \"Escape\":\n // Claims Escape so an enclosing Drawer stays open.\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n break;\n case \"Tab\":\n setOpen(false);\n break;\n case \"ArrowDown\":\n case \"ArrowUp\":\n event.preventDefault();\n step(event.key === \"ArrowDown\" ? 1 : -1);\n break;\n case \"Home\":\n case \"End\": {\n event.preventDefault();\n const pick = event.key === \"Home\" ? enabled[0] : enabled[enabled.length - 1];\n if (pick) setActiveIndex(options.indexOf(pick));\n break;\n }\n case \"Enter\":\n case \" \": {\n event.preventDefault();\n const option = options[activeIndex];\n if (option && !option.isDisabled) commit(option.value);\n break;\n }\n }\n };\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (effectiveDisabled) return;\n if (isVisible) {\n handleListKeyDown(event);\n } else if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(event.key)) {\n event.preventDefault();\n setOpen(true);\n }\n };\n\n return (\n <div\n className=\"ds-select-root\"\n ref={rootRef}\n >\n <Button\n ref={(node) => {\n triggerRef.current = node;\n if (typeof ref === \"function\") ref(node);\n else if (ref) ref.current = node;\n }}\n size={size}\n role=\"combobox\"\n aria-required={required || undefined}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n aria-controls={isVisible ? listId : undefined}\n aria-activedescendant={\n isVisible && options[activeIndex] && !options[activeIndex].isDisabled\n ? `${listId}-option-${activeIndex}`\n : undefined\n }\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={effectiveDisabled}\n data-placeholder={selected ? undefined : \"\"}\n className={cx(\"ds-field-skin\", \"ds-select\", className)}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) setOpen((open) => !open);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (!event.defaultPrevented) handleKeyDown(event);\n }}\n {...rest}\n >\n <span className=\"ds-select__value\">{selected ? selected.label : placeholder}</span>\n <Icon\n name=\"chevron-down\"\n size={16}\n className=\"ds-select__chevron\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n isOpen={isVisible}\n placement={menuPlacement}\n matchAnchorWidth\n panelRef={listRef}\n id={listId}\n role=\"listbox\"\n aria-label={rest[\"aria-labelledby\"] ? undefined : (rest[\"aria-label\"] ?? placeholder)}\n aria-labelledby={rest[\"aria-labelledby\"]}\n className=\"ds-surface-raised ds-select__menu\"\n >\n <div\n onKeyDown={handleKeyDown}\n onPointerDown={(event) => event.preventDefault()}\n >\n {options.map((option, index) => (\n <Button\n key={option.value}\n variant={index === activeIndex ? \"active\" : \"simple\"}\n size=\"sm\"\n isDisabled={option.isDisabled}\n tabIndex={-1}\n id={`${listId}-option-${index}`}\n role=\"option\"\n aria-selected={option.value === current}\n aria-disabled={option.isDisabled || undefined}\n data-active={index === activeIndex || undefined}\n className=\"ds-select__option\"\n onMouseEnter={() => !option.isDisabled && setActiveIndex(index)}\n onClick={() => {\n if (!option.isDisabled) {\n commit(option.value);\n triggerRef.current?.focus();\n }\n }}\n >\n <span className=\"ds-select__option-body\">\n <span className=\"ds-select__option-label\">{option.label}</span>\n {option.description && (\n <span className=\"ds-select__option-description\">{option.description}</span>\n )}\n </span>\n {option.value === current && (\n <Icon\n name=\"check\"\n size={16}\n />\n )}\n </Button>\n ))}\n </div>\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;AAgBA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAgCA,IAAaC,IAASC,EAA2C,SAC/D,EACE,YACA,UACA,iBACA,kBACA,iBAAc,oBACd,UAAO,MACP,gBAAa,IACb,eAAY,IACZ,gBAAgBC,GAChB,aACA,mBAAgB,UAChB,cACA,aACA,YACA,cACA,GAAGC,KAEL,GACA;CACA,IAAM,CAACC,GAAUC,KAAeC,EAASC,KAAgB,EAAE,GACrDC,IAAUC,KAASL,GACnB,CAACM,GAAQC,KAAWL,EAAS,EAA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e;MACb,AAAKP,EAAO,eACVE,EAAOF,EAAO,KAAK,GACnBV,EAAW,SAAS,MAAM;KAE9B;KAlBF,UAAA,CAoBE,kBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,kBAAC,QAAD;OAAM,WAAU;OAA2B,UAAAU,EAAO;MAAY,CAAA,GAC7DA,EAAO,eACN,kBAAC,QAAD;OAAM,WAAU;OAAiC,UAAAA,EAAO;MAAkB,CAAA,CAExE;KACL,CAAA,GAAAA,EAAO,UAAUlB,KAChB,kBAACX,GAAD;MACE,MAAK;MACL,MAAM;KACP,CAAA,CAEG;IA/BD,GAAA6B,EAAO,KA+BN,CACT;GACE,CAAA;EACE,CAAA,CACN;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Grid/index.cjs");let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/group-pKDQtq-9.cjs"),t=require("../Grid/index.cjs");let n=require("react"),r=require("react/jsx-runtime");function i({kind:e,title:t,description:n,children:i,className:a,inputProps:o,inputRef:s}){return(0,r.jsxs)(`label`,{className:[`ds-selection-card`,a].filter(Boolean).join(` `),children:[(0,r.jsx)(`input`,{ref:s,type:e,"data-kind":e,className:`ds-selection-card__control`,...o}),(0,r.jsxs)(`span`,{className:`ds-selection-card__text`,children:[(0,r.jsx)(`span`,{className:`ds-selection-card__title`,children:t}),n&&(0,r.jsx)(`span`,{className:`ds-selection-card__description`,children:n}),i&&(0,r.jsx)(`span`,{className:`ds-selection-card__extra`,children:i})]})]})}var a=(0,n.forwardRef)(function({title:e,description:t,children:n,className:a,...o},s){return(0,r.jsx)(i,{kind:`checkbox`,title:e,description:t,className:a,inputProps:o,inputRef:s,children:n})}),o=(0,n.forwardRef)(function({title:e,description:t,children:n,className:a,...o},s){return(0,r.jsx)(i,{kind:`radio`,title:e,description:t,className:a,inputProps:o,inputRef:s,children:n})});function s({label:n,columns:i=2,gap:a=`md`,children:o,className:s,...c}){return(0,r.jsx)(e.t,{...c,label:n,className:[`ds-selection-card-group`,s].filter(Boolean).join(` `),children:(0,r.jsx)(t.Grid,{columns:i,gap:a,className:`ds-selection-card-group__grid`,children:o})})}exports.CheckboxCard=a,exports.RadioCard=o,exports.SelectionCardGroup=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","Grid","require_components_Grid_index","react","react_jsx_runtime","CardBody","className","inputRef","kind","inputProps","title","description","children","CheckboxCard","rest","ref","RadioCard","SelectionCardGroup","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","FieldGroup","Grid","require_group","require_components_Grid_index","react","react_jsx_runtime","CardBody","className","inputRef","kind","inputProps","title","description","children","CheckboxCard","rest","ref","RadioCard","SelectionCardGroup","fieldProps"],"sources":["../../../src/components/SelectionCard/index.tsx"],"sourcesContent":["import { forwardRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { FieldGroup, type FieldGroupProps } from \"../Field/group\";\nimport { Grid, type GapSize } from \"../Grid\";\nimport \"./style.css\";\n\ninterface SelectionCardBase {\n /** The commitment, in the user's words. */\n title: ReactNode;\n /** One line on what picking this means. Takes nodes, so a chip or a link can sit inline. */\n description?: ReactNode;\n /** Extra content under the description — a price, a sample, a badge. */\n children?: ReactNode;\n}\n\ntype NativeInput = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"size\" | \"children\" | \"title\"\n>;\n\nfunction CardBody({\n kind,\n title,\n description,\n children,\n className,\n inputProps,\n inputRef,\n}: SelectionCardBase & {\n kind: \"checkbox\" | \"radio\";\n className?: string;\n inputProps: NativeInput;\n inputRef: React.Ref<HTMLInputElement>;\n}) {\n return (\n <label className={[\"ds-selection-card\", className].filter(Boolean).join(\" \")}>\n <input\n ref={inputRef}\n type={kind}\n data-kind={kind}\n className=\"ds-selection-card__control\"\n {...inputProps}\n />\n <span className=\"ds-selection-card__text\">\n <span className=\"ds-selection-card__title\">{title}</span>\n {description && <span className=\"ds-selection-card__description\">{description}</span>}\n {children && <span className=\"ds-selection-card__extra\">{children}</span>}\n </span>\n </label>\n );\n}\n\nexport interface CheckboxCardProps extends SelectionCardBase, NativeInput {}\n\n/**\n * A checkbox with room to explain itself. Same 20px box as the bare control —\n * the card is a bigger target, not a different decision.\n */\nexport const CheckboxCard = forwardRef<HTMLInputElement, CheckboxCardProps>(function CheckboxCard(\n { title, description, children, className, ...rest },\n ref,\n) {\n return (\n <CardBody\n kind=\"checkbox\"\n title={title}\n description={description}\n className={className}\n inputProps={rest}\n inputRef={ref}\n >\n {children}\n </CardBody>\n );\n});\n\nexport interface RadioCardProps extends SelectionCardBase, NativeInput {}\n\n/** One of a set of mutually exclusive options, each with its own explanation. */\nexport const RadioCard = forwardRef<HTMLInputElement, RadioCardProps>(function RadioCard(\n { title, description, children, className, ...rest },\n ref,\n) {\n return (\n <CardBody\n kind=\"radio\"\n title={title}\n description={description}\n className={className}\n inputProps={rest}\n inputRef={ref}\n >\n {children}\n </CardBody>\n );\n});\n\nexport interface SelectionCardGroupProps extends FieldGroupProps {\n /** Group label — the question the cards answer. */\n label: string;\n /** Cards per row at full width. Steps down inside a narrow container. */\n columns?: 1 | 2 | 3;\n /** Space between cards in both axes, using Grid's spacing scale. Defaults to `md`. */\n gap?: GapSize;\n children: ReactNode;\n}\n\n/** A grid of selection cards under one legend, spaced by the shared Grid. */\nexport function SelectionCardGroup({\n label,\n columns = 2,\n gap = \"md\",\n children,\n className,\n ...fieldProps\n}: SelectionCardGroupProps) {\n return (\n <FieldGroup\n {...fieldProps}\n label={label}\n className={[\"ds-selection-card-group\", className].filter(Boolean).join(\" \")}\n >\n <Grid\n columns={columns}\n gap={gap}\n className=\"ds-selection-card-group__grid\"\n >\n {children}\n </Grid>\n </FieldGroup>\n );\n}\n"],"mappings":"A,2MAmBA,SAASO,EAAS,CAChB,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AAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAE1E,UAAA,EAAAF,EAAA,IAAA,CAACJ,EAAAA,KAAD,CACW,UACJ,MACL,UAAU,gCAET,UACG,CAAA,CACI,CAAA,CAEhB,C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { type FieldGroupProps } from "../Field/group.cjs";
|
|
2
3
|
import { type GapSize } from "../Grid/index.cjs";
|
|
3
4
|
interface SelectionCardBase {
|
|
4
5
|
/** The commitment, in the user's words. */
|
|
@@ -20,7 +21,7 @@ export interface RadioCardProps extends SelectionCardBase, NativeInput {
|
|
|
20
21
|
}
|
|
21
22
|
/** One of a set of mutually exclusive options, each with its own explanation. */
|
|
22
23
|
export declare const RadioCard: import("react").ForwardRefExoticComponent<RadioCardProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
23
|
-
export interface SelectionCardGroupProps {
|
|
24
|
+
export interface SelectionCardGroupProps extends FieldGroupProps {
|
|
24
25
|
/** Group label — the question the cards answer. */
|
|
25
26
|
label: string;
|
|
26
27
|
/** Cards per row at full width. Steps down inside a narrow container. */
|
|
@@ -30,6 +31,6 @@ export interface SelectionCardGroupProps {
|
|
|
30
31
|
children: ReactNode;
|
|
31
32
|
}
|
|
32
33
|
/** A grid of selection cards under one legend, spaced by the shared Grid. */
|
|
33
|
-
export declare function SelectionCardGroup({ label, columns, gap, children, }: SelectionCardGroupProps): import("react").JSX.Element;
|
|
34
|
+
export declare function SelectionCardGroup({ label, columns, gap, children, className, ...fieldProps }: SelectionCardGroupProps): import("react").JSX.Element;
|
|
34
35
|
export {};
|
|
35
36
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/SelectionCard/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,mBAAmB,EAAE,KAAK,SAAS,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G,OAAO,CACvC,CAAC;AAkCF,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB,EAAE,WAAW;CAAG;AAE5E;;;GAGG;AACH,eAAO,MAAM,YAAY,gHAgBvB,CAAC;AAEH,MAAM,WAAW,cAAe,SAAQ,iBAAiB,EAAE,WAAW;CAAG;AAEzE,iFAAiF;AACjF,eAAO,MAAM,SAAS,6GAgBpB,CAAC;AAEH,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,sFAAsF;IACtF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,OAAW,EACX,GAAU,EACV,QAAQ,EACR,SAAS,EACT,GAAG,UAAU,EACd,EAAE,uBAAuB,+BAgBzB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { type FieldGroupProps } from "../Field/group.js";
|
|
2
3
|
import { type GapSize } from "../Grid/index.js";
|
|
3
4
|
interface SelectionCardBase {
|
|
4
5
|
/** The commitment, in the user's words. */
|
|
@@ -20,7 +21,7 @@ export interface RadioCardProps extends SelectionCardBase, NativeInput {
|
|
|
20
21
|
}
|
|
21
22
|
/** One of a set of mutually exclusive options, each with its own explanation. */
|
|
22
23
|
export declare const RadioCard: import("react").ForwardRefExoticComponent<RadioCardProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
23
|
-
export interface SelectionCardGroupProps {
|
|
24
|
+
export interface SelectionCardGroupProps extends FieldGroupProps {
|
|
24
25
|
/** Group label — the question the cards answer. */
|
|
25
26
|
label: string;
|
|
26
27
|
/** Cards per row at full width. Steps down inside a narrow container. */
|
|
@@ -30,6 +31,6 @@ export interface SelectionCardGroupProps {
|
|
|
30
31
|
children: ReactNode;
|
|
31
32
|
}
|
|
32
33
|
/** A grid of selection cards under one legend, spaced by the shared Grid. */
|
|
33
|
-
export declare function SelectionCardGroup({ label, columns, gap, children, }: SelectionCardGroupProps): import("react").JSX.Element;
|
|
34
|
+
export declare function SelectionCardGroup({ label, columns, gap, children, className, ...fieldProps }: SelectionCardGroupProps): import("react").JSX.Element;
|
|
34
35
|
export {};
|
|
35
36
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,aAAa,CAAC;AAErB,UAAU,iBAAiB;IACzB,2CAA2C;IAC3C,KAAK,EAAE,SAAS,CAAC;IACjB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,KAAK,WAAW,GAAG,IAAI,CACrB,mBAAmB,CAAC,gBAAgB,CAAC,EACrC,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CACvC,CAAC;AAkCF,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB,EAAE,WAAW;CAAG;AAE5E;;;GAGG;AACH,eAAO,MAAM,YAAY,gHAgBvB,CAAC;AAEH,MAAM,WAAW,cAAe,SAAQ,iBAAiB,EAAE,WAAW;CAAG;AAEzE,iFAAiF;AACjF,eAAO,MAAM,SAAS,6GAgBpB,CAAC;AAEH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SelectionCard/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA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.js";
|
|
2
|
+
import { Grid as t } from "../Grid/index.js";
|
|
3
|
+
import { forwardRef as n } from "react";
|
|
4
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
4
5
|
//#region src/components/SelectionCard/index.tsx
|
|
5
|
-
function
|
|
6
|
-
return /* @__PURE__ */
|
|
6
|
+
function a({ kind: e, title: t, description: n, children: a, className: o, inputProps: s, inputRef: c }) {
|
|
7
|
+
return /* @__PURE__ */ i("label", {
|
|
7
8
|
className: ["ds-selection-card", o].filter(Boolean).join(" "),
|
|
8
|
-
children: [/* @__PURE__ */
|
|
9
|
+
children: [/* @__PURE__ */ r("input", {
|
|
9
10
|
ref: c,
|
|
10
11
|
type: e,
|
|
11
12
|
"data-kind": e,
|
|
12
13
|
className: "ds-selection-card__control",
|
|
13
14
|
...s
|
|
14
|
-
}), /* @__PURE__ */
|
|
15
|
+
}), /* @__PURE__ */ i("span", {
|
|
15
16
|
className: "ds-selection-card__text",
|
|
16
17
|
children: [
|
|
17
|
-
/* @__PURE__ */
|
|
18
|
+
/* @__PURE__ */ r("span", {
|
|
18
19
|
className: "ds-selection-card__title",
|
|
19
20
|
children: t
|
|
20
21
|
}),
|
|
21
|
-
|
|
22
|
+
n && /* @__PURE__ */ r("span", {
|
|
22
23
|
className: "ds-selection-card__description",
|
|
23
|
-
children:
|
|
24
|
+
children: n
|
|
24
25
|
}),
|
|
25
|
-
a && /* @__PURE__ */
|
|
26
|
+
a && /* @__PURE__ */ r("span", {
|
|
26
27
|
className: "ds-selection-card__extra",
|
|
27
28
|
children: a
|
|
28
29
|
})
|
|
@@ -30,42 +31,41 @@ function i({ kind: e, title: t, description: i, children: a, className: o, input
|
|
|
30
31
|
})]
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
var
|
|
34
|
-
return /* @__PURE__ */
|
|
34
|
+
var o = n(function({ title: e, description: t, children: n, className: i, ...o }, s) {
|
|
35
|
+
return /* @__PURE__ */ r(a, {
|
|
35
36
|
kind: "checkbox",
|
|
36
37
|
title: e,
|
|
37
38
|
description: t,
|
|
38
|
-
className:
|
|
39
|
+
className: i,
|
|
39
40
|
inputProps: o,
|
|
40
41
|
inputRef: s,
|
|
41
|
-
children:
|
|
42
|
+
children: n
|
|
42
43
|
});
|
|
43
|
-
}),
|
|
44
|
-
return /* @__PURE__ */
|
|
44
|
+
}), s = n(function({ title: e, description: t, children: n, className: i, ...o }, s) {
|
|
45
|
+
return /* @__PURE__ */ r(a, {
|
|
45
46
|
kind: "radio",
|
|
46
47
|
title: e,
|
|
47
48
|
description: t,
|
|
48
|
-
className:
|
|
49
|
+
className: i,
|
|
49
50
|
inputProps: o,
|
|
50
51
|
inputRef: s,
|
|
51
|
-
children:
|
|
52
|
+
children: n
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
|
-
function
|
|
55
|
-
return /* @__PURE__ */ r(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}), /* @__PURE__ */ n(e, {
|
|
55
|
+
function c({ label: n, columns: i = 2, gap: a = "md", children: o, className: s, ...c }) {
|
|
56
|
+
return /* @__PURE__ */ r(e, {
|
|
57
|
+
...c,
|
|
58
|
+
label: n,
|
|
59
|
+
className: ["ds-selection-card-group", s].filter(Boolean).join(" "),
|
|
60
|
+
children: /* @__PURE__ */ r(t, {
|
|
61
61
|
columns: i,
|
|
62
62
|
gap: a,
|
|
63
63
|
className: "ds-selection-card-group__grid",
|
|
64
64
|
children: o
|
|
65
|
-
})
|
|
65
|
+
})
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
//#endregion
|
|
69
|
-
export {
|
|
69
|
+
export { o as CheckboxCard, s as RadioCard, c as SelectionCardGroup };
|
|
70
70
|
|
|
71
71
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["CardBody","className","inputRef","kind","inputProps","title","description","children","CheckboxCard","forwardRef","rest","ref","RadioCard","SelectionCardGroup","
|
|
1
|
+
{"version":3,"file":"index.js","names":["FieldGroup","CardBody","className","inputRef","kind","inputProps","title","description","children","CheckboxCard","forwardRef","rest","ref","RadioCard","SelectionCardGroup","fieldProps","Grid"],"sources":["../../../src/components/SelectionCard/index.tsx"],"sourcesContent":["import { forwardRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { FieldGroup, type FieldGroupProps } from \"../Field/group\";\nimport { Grid, type GapSize } from \"../Grid\";\nimport \"./style.css\";\n\ninterface SelectionCardBase {\n /** The commitment, in the user's words. */\n title: ReactNode;\n /** One line on what picking this means. Takes nodes, so a chip or a link can sit inline. */\n description?: ReactNode;\n /** Extra content under the description — a price, a sample, a badge. */\n children?: ReactNode;\n}\n\ntype NativeInput = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"size\" | \"children\" | \"title\"\n>;\n\nfunction CardBody({\n kind,\n title,\n description,\n children,\n className,\n inputProps,\n inputRef,\n}: SelectionCardBase & {\n kind: \"checkbox\" | \"radio\";\n className?: string;\n inputProps: NativeInput;\n inputRef: React.Ref<HTMLInputElement>;\n}) {\n return (\n <label className={[\"ds-selection-card\", className].filter(Boolean).join(\" \")}>\n <input\n ref={inputRef}\n type={kind}\n data-kind={kind}\n className=\"ds-selection-card__control\"\n {...inputProps}\n />\n <span className=\"ds-selection-card__text\">\n <span className=\"ds-selection-card__title\">{title}</span>\n {description && <span className=\"ds-selection-card__description\">{description}</span>}\n {children && <span className=\"ds-selection-card__extra\">{children}</span>}\n </span>\n </label>\n );\n}\n\nexport interface CheckboxCardProps extends SelectionCardBase, NativeInput {}\n\n/**\n * A checkbox with room to explain itself. Same 20px box as the bare control —\n * the card is a bigger target, not a different decision.\n */\nexport const CheckboxCard = forwardRef<HTMLInputElement, CheckboxCardProps>(function CheckboxCard(\n { title, description, children, className, ...rest },\n ref,\n) {\n return (\n <CardBody\n kind=\"checkbox\"\n title={title}\n description={description}\n className={className}\n inputProps={rest}\n inputRef={ref}\n >\n {children}\n </CardBody>\n );\n});\n\nexport interface RadioCardProps extends SelectionCardBase, NativeInput {}\n\n/** One of a set of mutually exclusive options, each with its own explanation. */\nexport const RadioCard = forwardRef<HTMLInputElement, RadioCardProps>(function RadioCard(\n { title, description, children, className, ...rest },\n ref,\n) {\n return (\n <CardBody\n kind=\"radio\"\n title={title}\n description={description}\n className={className}\n inputProps={rest}\n inputRef={ref}\n >\n {children}\n </CardBody>\n );\n});\n\nexport interface SelectionCardGroupProps extends FieldGroupProps {\n /** Group label — the question the cards answer. */\n label: string;\n /** Cards per row at full width. Steps down inside a narrow container. */\n columns?: 1 | 2 | 3;\n /** Space between cards in both axes, using Grid's spacing scale. Defaults to `md`. */\n gap?: GapSize;\n children: ReactNode;\n}\n\n/** A grid of selection cards under one legend, spaced by the shared Grid. */\nexport function SelectionCardGroup({\n label,\n columns = 2,\n gap = \"md\",\n children,\n className,\n ...fieldProps\n}: SelectionCardGroupProps) {\n return (\n <FieldGroup\n {...fieldProps}\n label={label}\n className={[\"ds-selection-card-group\", className].filter(Boolean).join(\" \")}\n >\n <Grid\n columns={columns}\n gap={gap}\n className=\"ds-selection-card-group__grid\"\n >\n {children}\n </Grid>\n </FieldGroup>\n );\n}\n"],"mappings":";;;;;AAmBA,SAASC,EAAS,EAChB,SACA,UACA,gBACA,aACA,cACA,eACA,eAMC;CACD,OACE,kBAAC,SAAD;EAAO,WAAW,CAAC,qBAAqBC,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAA3E,UAAA,CACE,kBAAC,SAAD;GACE,KAAKC;GACL,MAAMC;GACN,aAAWA;GACX,WAAU;GACV,GAAIC;EACL,CAAA,GACD,kBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA;IACE,kBAAC,QAAD;KAAM,WAAU;KAA4B,UAAAC;IAAY,CAAA;IACvDC,KAAe,kBAAC,QAAD;KAAM,WAAU;KAAkC,UAAAA;IAAkB,CAAA;IACnFC,KAAY,kBAAC,QAAD;KAAM,WAAU;KAA4B;IAAe,CAAA;GACpE;EACD,CAAA,CAAA;;AAEX;AAQA,IAAaC,IAAeC,EAAgD,SAC1E,EAAE,UAAO,gBAAa,aAAU,cAAW,GAAGC,KAC9C,GACA;CACA,OACE,kBAACV,GAAD;EACE,MAAK;EACE;EACM;EACF;EACX,YAAYU;EACZ,UAAUC;EAET;CACO,CAAA;AAEd,CAAC,GAKYC,IAAYH,EAA6C,SACpE,EAAE,UAAO,gBAAa,aAAU,cAAW,GAAGC,KAC9C,GACA;CACA,OACE,kBAACV,GAAD;EACE,MAAK;EACE;EACM;EACF;EACX,YAAYU;EACZ,UAAUC;EAET;CACO,CAAA;AAEd,CAAC;AAaD,SAAgBE,EAAmB,EACjC,UACA,aAAU,GACV,SAAM,MACN,aACA,cACA,GAAGC,KACuB;CAC1B,OACE,kBAACf,GAAD;EACE,GAAIe;EACG;EACP,WAAW,CAAC,2BAA2Bb,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAE1E,UAAA,kBAACc,GAAD;GACW;GACJ;GACL,WAAU;GAET;EACG,CAAA;CACI,CAAA;AAEhB"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
align-items: start;
|
|
5
5
|
gap: var(--space-3);
|
|
6
6
|
padding: var(--space-4);
|
|
7
|
-
min-inline-size: var(--choice-card-min-width);
|
|
7
|
+
min-inline-size: min(100%, var(--choice-card-min-width));
|
|
8
8
|
background: var(--color-surface);
|
|
9
9
|
border: var(--control-border-width) solid var(--control-border-color);
|
|
10
10
|
border-radius: var(--field-radius);
|
|
@@ -114,13 +114,6 @@
|
|
|
114
114
|
min-inline-size: 0;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
.ds-selection-card-group__label {
|
|
118
|
-
padding: 0;
|
|
119
|
-
margin-block-end: var(--space-3);
|
|
120
|
-
font-size: var(--font-size-sm);
|
|
121
|
-
font-weight: var(--font-weight-bold);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
117
|
@media (prefers-reduced-motion: reduce) {
|
|
125
118
|
.ds-selection-card {
|
|
126
119
|
transition: none;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/binding-tMjrUzkU.cjs");let t=require("react"),n=require("react/jsx-runtime");function r(...e){return e.filter(Boolean).join(` `)}function i(e,t,n){return n===t?0:(e-t)/(n-t)*100}var a=(0,t.forwardRef)(function({value:e,defaultValue:a=0,onValueChange:o,min:s=0,max:c=100,step:l=1,hasValueLabel:u=!0,prefix:d,suffix:f,isDisabled:p=!1,className:m,disabled:h,...g},_){let[v,y]=(0,t.useState)(a),b=e??v;return(0,n.jsxs)(`div`,{className:r(`ds-slider`,m),"data-disabled":p||h||void 0,children:[(0,n.jsxs)(`div`,{className:`ds-slider__track`,"data-thumbs":`1`,"data-disabled":p||h||void 0,"data-at-min":b<=s||void 0,"data-at-max":b>=c||void 0,style:{"--slider-from":`0%`,"--slider-to":`${i(b,s,c)}%`},children:[(0,n.jsx)(`span`,{className:`ds-slider__rail`}),(0,n.jsx)(`span`,{className:`ds-slider__fill`}),(0,n.jsx)(`input`,{ref:_,type:`range`,className:`ds-slider__input`,min:s,max:c,step:l,value:b,disabled:p||h,onChange:t=>{let n=Number(t.target.value);e===void 0&&y(n),o?.(n)},...g})]}),u&&(0,n.jsxs)(`output`,{className:`ds-slider__value`,children:[d,b,f]})]})});function o({value:a,defaultValue:o={min:20,max:80},onValueChange:s,min:c=0,max:l=100,step:u=1,hasValueLabel:d=!0,prefix:f,suffix:p,isDisabled:m=!1,minLabel:h=`Minimum`,maxLabel:g=`Maximum`,className:_,...v}){let[y,b]=(0,t.useState)(o),x=a??y,S=e=>{a===void 0&&b(e),s?.(e)},{attributes:C}=e.r(v);return(0,n.jsxs)(`div`,{...C,className:r(`ds-slider`,_),"data-disabled":m||void 0,children:[(0,n.jsxs)(`div`,{className:`ds-slider__track`,"data-thumbs":`2`,"data-disabled":m||void 0,"data-at-min":x.min<=c||void 0,"data-at-max":x.max>=l||void 0,style:{"--slider-from":`${i(x.min,c,l)}%`,"--slider-to":`${i(x.max,c,l)}%`},children:[(0,n.jsx)(`span`,{className:`ds-slider__rail`}),(0,n.jsx)(`span`,{className:`ds-slider__fill`}),(0,n.jsx)(`input`,{type:`range`,"aria-invalid":v[`aria-invalid`],"aria-label":h,className:`ds-slider__input`,min:c,max:l,step:u,value:x.min,disabled:m,onChange:e=>S({...x,min:Math.min(Number(e.target.value),x.max-u)})}),(0,n.jsx)(`input`,{type:`range`,"aria-invalid":v[`aria-invalid`],"aria-label":g,className:`ds-slider__input`,min:c,max:l,step:u,value:x.max,disabled:m,onChange:e=>S({...x,max:Math.max(Number(e.target.value),x.min+u)})})]}),d&&(0,n.jsxs)(`output`,{className:`ds-slider__value`,children:[f,x.min,p,` – `,f,x.max,p]})]})}exports.RangeSlider=o,exports.Slider=a;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["forwardRef","useState","react","react_jsx_runtime","cx","parts","percent","max","min","value","Slider","rest","internal","setInternal","defaultValue","current","className","isDisabled","disabled","next","event","onValueChange","hasValueLabel","suffix","RangeSlider","commit","minLabel","step","maxLabel"],"sources":["../../../src/components/Slider/index.tsx"],"sourcesContent":["import { forwardRef, useState, type InputHTMLAttributes } from \"react\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nfunction percent(value: number, min: number, max: number) {\n if (max === min) return 0;\n return ((value - min) / (max - min)) * 100;\n}\n\nexport interface SliderProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"value\" | \"defaultValue\" | \"onChange\"\n> {\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n min?: number;\n max?: number;\n step?: number;\n /** Print the current value, in the system's mono, beside the track. */\n hasValueLabel?: boolean;\n /** Appended to the printed value — \"%\", \"px\", \"s\". */\n suffix?: string;\n isDisabled?: boolean;\n}\n\n/** One value on a continuous scale. The filled part of the track is the value. */\nexport const Slider = forwardRef<HTMLInputElement, SliderProps>(function Slider(\n {\n value,\n defaultValue = 0,\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n hasValueLabel = true,\n suffix,\n isDisabled = false,\n className,\n disabled,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n\n return (\n <div\n className={cx(\"ds-slider\", className)}\n data-disabled={isDisabled || disabled || undefined}\n >\n <div\n className=\"ds-slider__track\"\n data-thumbs=\"1\"\n data-disabled={isDisabled || disabled || undefined}\n data-at-min={current <= min || undefined}\n data-at-max={current >= max || undefined}\n style={{\n [\"--slider-from\" as string]: \"0%\",\n [\"--slider-to\" as string]: `${percent(current, min, max)}%`,\n }}\n >\n <span className=\"ds-slider__rail\" />\n <span className=\"ds-slider__fill\" />\n <input\n ref={ref}\n type=\"range\"\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current}\n disabled={isDisabled || disabled}\n onChange={(event) => {\n const next = Number(event.target.value);\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n }}\n {...rest}\n />\n </div>\n {hasValueLabel && (\n <output className=\"ds-slider__value\">\n {current}\n {suffix}\n </output>\n )}\n </div>\n );\n});\n\nexport interface RangeSliderValue {\n min: number;\n max: number;\n}\n\nexport interface RangeSliderProps {\n value?: RangeSliderValue;\n defaultValue?: RangeSliderValue;\n onValueChange?: (value: RangeSliderValue) => void;\n min?: number;\n max?: number;\n step?: number;\n hasValueLabel?: boolean;\n suffix?: string;\n isDisabled?: boolean;\n minLabel?: string;\n maxLabel?: string;\n className?: string;\n}\n\n/**\n * A span on a scale — two thumbs on one track. The thumbs cannot cross; each\n * one stops a `step` short of the other.\n */\nexport function RangeSlider({\n value,\n defaultValue = { min: 20, max: 80 },\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n hasValueLabel = true,\n suffix,\n isDisabled = false,\n minLabel = \"Minimum\",\n maxLabel = \"Maximum\",\n className,\n}: RangeSliderProps) {\n const [internal, setInternal] = useState<RangeSliderValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: RangeSliderValue) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n\n return (\n <div\n className={cx(\"ds-slider\", className)}\n data-disabled={isDisabled || undefined}\n >\n <div\n className=\"ds-slider__track\"\n data-thumbs=\"2\"\n data-disabled={isDisabled || undefined}\n data-at-min={current.min <= min || undefined}\n data-at-max={current.max >= max || undefined}\n style={{\n [\"--slider-from\" as string]: `${percent(current.min, min, max)}%`,\n [\"--slider-to\" as string]: `${percent(current.max, min, max)}%`,\n }}\n >\n <span className=\"ds-slider__rail\" />\n <span className=\"ds-slider__fill\" />\n <input\n type=\"range\"\n aria-label={minLabel}\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current.min}\n disabled={isDisabled}\n onChange={(event) =>\n commit({ ...current, min: Math.min(Number(event.target.value), current.max - step) })\n }\n />\n <input\n type=\"range\"\n aria-label={maxLabel}\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current.max}\n disabled={isDisabled}\n onChange={(event) =>\n commit({ ...current, max: Math.max(Number(event.target.value), current.min + step) })\n }\n />\n </div>\n {hasValueLabel && (\n <output className=\"ds-slider__value\">\n {current.min}\n {suffix} – {current.max}\n {suffix}\n </output>\n )}\n </div>\n );\n}\n"],"mappings":"A,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["forwardRef","useState","useGroupBinding","require_binding","react","react_jsx_runtime","cx","parts","percent","max","min","value","Slider","rest","internal","setInternal","defaultValue","current","className","isDisabled","disabled","next","event","onValueChange","hasValueLabel","prefix","suffix","RangeSlider","binding","commit","attributes","minLabel","step","maxLabel"],"sources":["../../../src/components/Slider/index.tsx"],"sourcesContent":["import { forwardRef, useState, type InputHTMLAttributes } from \"react\";\nimport { useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding } from \"../Field\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nfunction percent(value: number, min: number, max: number) {\n if (max === min) return 0;\n return ((value - min) / (max - min)) * 100;\n}\n\nexport interface SliderProps extends Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"value\" | \"defaultValue\" | \"onChange\" | \"prefix\"\n> {\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n min?: number;\n max?: number;\n step?: number;\n /** Print the current value, in the system's mono, beside the track. */\n hasValueLabel?: boolean;\n /** Prepended to the printed value — \"£\", \"$\", \"€\". */\n prefix?: string;\n /** Appended to the printed value — \"%\", \"px\", \"s\". */\n suffix?: string;\n isDisabled?: boolean;\n}\n\n/** One value on a continuous scale. The filled part of the track is the value. */\nexport const Slider = forwardRef<HTMLInputElement, SliderProps>(function Slider(\n {\n value,\n defaultValue = 0,\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n hasValueLabel = true,\n prefix,\n suffix,\n isDisabled = false,\n className,\n disabled,\n ...rest\n },\n ref,\n) {\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n\n return (\n <div\n className={cx(\"ds-slider\", className)}\n data-disabled={isDisabled || disabled || undefined}\n >\n <div\n className=\"ds-slider__track\"\n data-thumbs=\"1\"\n data-disabled={isDisabled || disabled || undefined}\n data-at-min={current <= min || undefined}\n data-at-max={current >= max || undefined}\n style={{\n [\"--slider-from\" as string]: \"0%\",\n [\"--slider-to\" as string]: `${percent(current, min, max)}%`,\n }}\n >\n <span className=\"ds-slider__rail\" />\n <span className=\"ds-slider__fill\" />\n <input\n ref={ref}\n type=\"range\"\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current}\n disabled={isDisabled || disabled}\n onChange={(event) => {\n const next = Number(event.target.value);\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n }}\n {...rest}\n />\n </div>\n {hasValueLabel && (\n <output className=\"ds-slider__value\">\n {prefix}\n {current}\n {suffix}\n </output>\n )}\n </div>\n );\n});\n\nexport interface RangeSliderValue {\n min: number;\n max: number;\n}\n\nexport interface RangeSliderProps extends FieldBinding {\n value?: RangeSliderValue;\n defaultValue?: RangeSliderValue;\n onValueChange?: (value: RangeSliderValue) => void;\n min?: number;\n max?: number;\n step?: number;\n hasValueLabel?: boolean;\n /** Prepended to both printed values. */\n prefix?: string;\n suffix?: string;\n isDisabled?: boolean;\n minLabel?: string;\n maxLabel?: string;\n className?: string;\n}\n\n/**\n * A span on a scale — two thumbs on one track. The thumbs cannot cross; each\n * one stops a `step` short of the other.\n */\nexport function RangeSlider({\n value,\n defaultValue = { min: 20, max: 80 },\n onValueChange,\n min = 0,\n max = 100,\n step = 1,\n hasValueLabel = true,\n prefix,\n suffix,\n isDisabled = false,\n minLabel = \"Minimum\",\n maxLabel = \"Maximum\",\n className,\n ...binding\n}: RangeSliderProps) {\n const [internal, setInternal] = useState<RangeSliderValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: RangeSliderValue) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-slider\", className)}\n data-disabled={isDisabled || undefined}\n >\n <div\n className=\"ds-slider__track\"\n data-thumbs=\"2\"\n data-disabled={isDisabled || undefined}\n data-at-min={current.min <= min || undefined}\n data-at-max={current.max >= max || undefined}\n style={{\n [\"--slider-from\" as string]: `${percent(current.min, min, max)}%`,\n [\"--slider-to\" as string]: `${percent(current.max, min, max)}%`,\n }}\n >\n <span className=\"ds-slider__rail\" />\n <span className=\"ds-slider__fill\" />\n <input\n type=\"range\"\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={minLabel}\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current.min}\n disabled={isDisabled}\n onChange={(event) =>\n commit({ ...current, min: Math.min(Number(event.target.value), current.max - step) })\n }\n />\n <input\n type=\"range\"\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={maxLabel}\n className=\"ds-slider__input\"\n min={min}\n max={max}\n step={step}\n value={current.max}\n disabled={isDisabled}\n onChange={(event) =>\n commit({ ...current, max: Math.max(Number(event.target.value), current.min + step) })\n }\n />\n </div>\n {hasValueLabel && (\n <output className=\"ds-slider__value\">\n {prefix}\n {current.min}\n {suffix} – {prefix}\n {current.max}\n {suffix}\n </output>\n )}\n </div>\n );\n}\n"],"mappings":"A,8KAKA,SAASM,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAEA,SAASC,EAAQ,EAAe,EAAa,EAAa,CAExD,OADIC,IAAQC,EAAY,GACfC,EAAQD,IAAQD,EAAMC,GAAQ,GACzC,CAsBA,IAAaE,GAAA,EAASZ,EAAAA,WAAAA,CAA0C,SAC9D,CACE,QACA,eAAe,EACf,gBACA,MAAM,EACN,MAAM,IACN,OAAO,EACP,gBAAgB,GAChB,SACA,SACA,aAAa,GACb,YACA,WACA,GAAGa,GAEL,EACA,CACA,GAAM,CAACC,EAAUC,IAAA,EAAed,EAAAA,SAAAA,CAASe,CAAY,EAC/CC,EAAUN,GAASG,EAEzB,OACE,EAAAT,EAAA,KAAA,CAAC,MAAD,CACE,UAAWC,EAAG,YAAaY,CAAS,EACpC,gBAAeC,GAAcC,GAAY,IAAA,GAF3C,SAAA,EAIE,EAAAf,EAAA,KAAA,CAAC,MAAD,CACE,UAAU,mBACV,cAAY,IACZ,gBAAec,GAAcC,GAAY,IAAA,GACzC,cAAaH,GAAWP,GAAO,IAAA,GAC/B,cAAaO,GAAWR,GAAO,IAAA,GAC/B,MAAO,CACJ,gBAA4B,KAC5B,cAA0B,GAAGD,EAAQS,EAASP,EAAKD,CAAG,EAAE,EAC3D,EATF,SAAA,EAWE,EAAAJ,EAAA,IAAA,C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