@cascivo/react 0.17.1 → 1.0.0
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 +4 -3
- package/dist/action-sheet/action-sheet.js +1 -1
- package/dist/breadcrumb/breadcrumb.js +7 -7
- package/dist/checkbox/checkbox.js +11 -10
- package/dist/color-picker/color-picker.js +81 -77
- package/dist/combobox/combobox.js +81 -76
- package/dist/command-menu/command-menu.js +104 -104
- package/dist/comparison/comparison.js +18 -18
- package/dist/data-table/data-table.css +1 -1
- package/dist/data-table/data-table.js +148 -121
- package/dist/data-table/data-table.module.js +29 -29
- package/dist/date-picker/date-picker.js +98 -93
- package/dist/date-range-picker/date-range-picker.js +1 -1
- package/dist/dock/dock.js +2 -2
- package/dist/dropdown/dropdown.js +43 -40
- package/dist/editable/editable.js +29 -20
- package/dist/fab/fab.js +37 -37
- package/dist/field/field.js +24 -17
- package/dist/file-uploader/file-uploader.js +24 -23
- package/dist/filter/filter.js +11 -11
- package/dist/index.d.ts +1302 -85
- package/dist/input/input.js +14 -13
- package/dist/navigation-menu/navigation-menu.js +9 -9
- package/dist/node/action-sheet/action-sheet.js +1 -1
- package/dist/node/breadcrumb/breadcrumb.js +7 -7
- package/dist/node/checkbox/checkbox.js +11 -10
- package/dist/node/color-picker/color-picker.js +81 -77
- package/dist/node/combobox/combobox.js +81 -76
- package/dist/node/command-menu/command-menu.js +104 -104
- package/dist/node/comparison/comparison.js +18 -18
- package/dist/node/data-table/data-table.js +148 -121
- package/dist/node/data-table/data-table.module.js +29 -29
- package/dist/node/date-picker/date-picker.js +98 -93
- package/dist/node/date-range-picker/date-range-picker.js +1 -1
- package/dist/node/dock/dock.js +2 -2
- package/dist/node/dropdown/dropdown.js +43 -40
- package/dist/node/editable/editable.js +29 -20
- package/dist/node/fab/fab.js +37 -37
- package/dist/node/field/field.js +24 -17
- package/dist/node/file-uploader/file-uploader.js +24 -23
- package/dist/node/filter/filter.js +11 -11
- package/dist/node/input/input.js +14 -13
- package/dist/node/navigation-menu/navigation-menu.js +9 -9
- package/dist/node/number-input/number-input.js +28 -27
- package/dist/node/overflow-menu/overflow-menu.js +7 -7
- package/dist/node/progress/progress.js +3 -3
- package/dist/node/progress-circle/progress-circle.js +8 -8
- package/dist/node/progress-indicator/progress-indicator.js +1 -1
- package/dist/node/qr-code/qr-code.js +11 -11
- package/dist/node/radial-progress/radial-progress.js +9 -9
- package/dist/node/radio/radio.js +10 -9
- package/dist/node/react/src/index.js +93 -93
- package/dist/node/resizable/resizable.js +24 -24
- package/dist/node/search/search.js +35 -31
- package/dist/node/select/select.js +15 -14
- package/dist/node/side-nav/side-nav.js +35 -35
- package/dist/node/side-nav/side-nav.module.js +27 -27
- package/dist/node/slider/slider.js +13 -12
- package/dist/node/spinner/spinner.js +4 -4
- package/dist/node/steps/steps.js +10 -10
- package/dist/node/structured-list/structured-list.js +14 -14
- package/dist/node/swap/swap.js +5 -5
- package/dist/node/switcher/switcher.js +5 -5
- package/dist/node/tags-input/tags-input.js +20 -16
- package/dist/node/textarea/textarea.js +14 -13
- package/dist/node/time-picker/time-picker.js +21 -20
- package/dist/node/toggle/toggle.js +8 -7
- package/dist/node/tree-view/tree-view.js +43 -43
- package/dist/node/virtual-list/virtual-list.js +10 -10
- package/dist/node/wheel-picker/wheel-picker.js +36 -36
- package/dist/number-input/number-input.js +28 -27
- package/dist/overflow-menu/overflow-menu.js +7 -7
- package/dist/progress/progress.js +3 -3
- package/dist/progress-circle/progress-circle.js +8 -8
- package/dist/progress-indicator/progress-indicator.js +1 -1
- package/dist/qr-code/qr-code.js +11 -11
- package/dist/radial-progress/radial-progress.js +9 -9
- package/dist/radio/radio.js +10 -9
- package/dist/react/src/index.js +93 -93
- package/dist/resizable/resizable.js +24 -24
- package/dist/search/search.js +35 -31
- package/dist/select/select.js +15 -14
- package/dist/side-nav/side-nav.css +1 -1
- package/dist/side-nav/side-nav.js +35 -35
- package/dist/side-nav/side-nav.module.js +27 -27
- package/dist/slider/slider.js +13 -12
- package/dist/spinner/spinner.js +4 -4
- package/dist/steps/steps.js +10 -10
- package/dist/structured-list/structured-list.js +14 -14
- package/dist/styles.css +2 -2
- package/dist/swap/swap.js +5 -5
- package/dist/switcher/switcher.js +5 -5
- package/dist/tags-input/tags-input.js +20 -16
- package/dist/textarea/textarea.js +14 -13
- package/dist/time-picker/time-picker.js +21 -20
- package/dist/toggle/toggle.js +8 -7
- package/dist/tree-view/tree-view.js +43 -43
- package/dist/virtual-list/virtual-list.js +10 -10
- package/dist/wheel-picker/wheel-picker.js +36 -36
- package/package.json +4 -4
- package/readme.body.md +4 -3
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ grayscale (`ThemeProvider` warns in dev when that happens).
|
|
|
60
60
|
In a Server Component file (e.g. `app/layout.tsx`), import the themes once:
|
|
61
61
|
|
|
62
62
|
```tsx
|
|
63
|
-
import '@cascivo/themes/
|
|
63
|
+
import '@cascivo/themes/light-dark.css'
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Component CSS ships **per component** and is pulled in automatically when you
|
|
@@ -103,7 +103,8 @@ RSC without any extra wrapper.
|
|
|
103
103
|
|
|
104
104
|
```tsx
|
|
105
105
|
// once, in your entry file — themes are the only global import
|
|
106
|
-
import '@cascivo/themes/
|
|
106
|
+
import '@cascivo/themes/light-dark.css' // tokens (once) + base typography + light & dark
|
|
107
|
+
// swap for '@cascivo/themes/all.css' only if you ship a theme picker (all twelve, ~2x)
|
|
107
108
|
|
|
108
109
|
// anywhere — each component brings its own CSS along
|
|
109
110
|
import { Button, Card, CardContent, Toggle } from '@cascivo/react'
|
|
@@ -396,7 +397,7 @@ routing break after adding one of these, check that the import resolves to
|
|
|
396
397
|
- **SideNav** — Collapsible sidebar navigation with optional icons and one level of grouping
|
|
397
398
|
- **SkipNav** — Skip link that jumps keyboard users past the navigation to the main content
|
|
398
399
|
- **Steps** — Visual progress indicator for multi-step flows with horizontal and vertical orientations
|
|
399
|
-
- **Switcher** —
|
|
400
|
+
- **Switcher** — Always-visible app/product switcher LIST — every entry is rendered at once, it does not collapse. Lives inside HeaderPanel; renders links with an active indicator and optional dividers. For a collapsed trigger with a menu, use Dropdown.
|
|
400
401
|
- **Tabs** — Switch between related panels of content
|
|
401
402
|
- **Toc** — Table of contents with scroll-spy highlighting of the active section
|
|
402
403
|
|
|
@@ -5,20 +5,20 @@ import { cn as t, getLinkComponent as n, useSignals as r } from "@cascivo/core";
|
|
|
5
5
|
import { builtin as i, t as a } from "@cascivo/i18n";
|
|
6
6
|
import { jsx as o } from "react/jsx-runtime";
|
|
7
7
|
//#region ../components/src/breadcrumb/breadcrumb.tsx
|
|
8
|
-
function s({ items: s, maxVisible: c, className: l, ariaLabel: u }) {
|
|
8
|
+
function s({ items: s, maxVisible: c, className: l, ariaLabel: u, label: d }) {
|
|
9
9
|
r();
|
|
10
|
-
let
|
|
11
|
-
return
|
|
12
|
-
|
|
10
|
+
let f = n(), p = u ?? d ?? a(i.breadcrumb.nav), m = s, h = s[0];
|
|
11
|
+
return h !== void 0 && c !== void 0 && s.length > c && (m = [
|
|
12
|
+
h,
|
|
13
13
|
{ label: "…" },
|
|
14
14
|
...s.slice(s.length - (c - 2))
|
|
15
15
|
]), /* @__PURE__ */ o("nav", {
|
|
16
|
-
"aria-label":
|
|
16
|
+
"aria-label": p,
|
|
17
17
|
className: t(e.breadcrumb, l),
|
|
18
|
-
children: /* @__PURE__ */ o("ol", { children:
|
|
18
|
+
children: /* @__PURE__ */ o("ol", { children: m.map((e, t) => /* @__PURE__ */ o("li", { children: t === m.length - 1 ? /* @__PURE__ */ o("span", {
|
|
19
19
|
"aria-current": "page",
|
|
20
20
|
children: e.label
|
|
21
|
-
}) : e.href === void 0 ? /* @__PURE__ */ o("span", { children: e.label }) : /* @__PURE__ */ o(
|
|
21
|
+
}) : e.href === void 0 ? /* @__PURE__ */ o("span", { children: e.label }) : /* @__PURE__ */ o(f, {
|
|
22
22
|
href: e.href,
|
|
23
23
|
children: e.label
|
|
24
24
|
}) }, e.id ?? `${t}-${e.label}`)) })
|
|
@@ -5,23 +5,24 @@ import { forwardRef as t, useRef as n } from "react";
|
|
|
5
5
|
import { cn as r, composeRefs as i, useEffectPropSignal as a, useSignalEffect as o } from "@cascivo/core";
|
|
6
6
|
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
7
7
|
//#region ../components/src/checkbox/checkbox.tsx
|
|
8
|
-
var l = t(function({ label: t, indeterminate: l = !1,
|
|
9
|
-
let
|
|
8
|
+
var l = t(function({ label: t, indeterminate: l = !1, ariaLabel: u, className: d, id: f, disabled: p, ...m }, h) {
|
|
9
|
+
let g = n(null), _ = a(l);
|
|
10
10
|
o(() => {
|
|
11
|
-
|
|
11
|
+
g.current && (g.current.indeterminate = _.value);
|
|
12
12
|
});
|
|
13
|
-
let
|
|
13
|
+
let v = f ?? (t ? `cascade-checkbox-${t.toLowerCase().replace(/\s+/g, "-")}` : void 0);
|
|
14
14
|
return /* @__PURE__ */ c("label", {
|
|
15
|
-
className: r(e.wrapper,
|
|
16
|
-
"data-disabled":
|
|
15
|
+
className: r(e.wrapper, d),
|
|
16
|
+
"data-disabled": p || void 0,
|
|
17
17
|
children: [
|
|
18
18
|
/* @__PURE__ */ s("input", {
|
|
19
|
-
ref: i(
|
|
20
|
-
id:
|
|
19
|
+
ref: i(h, g),
|
|
20
|
+
id: v,
|
|
21
21
|
type: "checkbox",
|
|
22
22
|
className: e.input,
|
|
23
|
-
disabled:
|
|
24
|
-
...
|
|
23
|
+
disabled: p,
|
|
24
|
+
...m,
|
|
25
|
+
"aria-label": m["aria-label"] ?? u
|
|
25
26
|
}),
|
|
26
27
|
/* @__PURE__ */ s("span", {
|
|
27
28
|
className: e.control,
|
|
@@ -73,86 +73,86 @@ function _({ h: e, s: t, l: n, a: r }) {
|
|
|
73
73
|
a: r
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
function v({ value: v, defaultValue: y, onValueChange: b, presets: x, alpha: S = !0, label: C,
|
|
76
|
+
function v({ value: v, defaultValue: y, onValueChange: b, presets: x, alpha: S = !0, label: C, ariaLabel: w, disabled: T, size: E = "md", className: D, labels: O, id: k, "aria-labelledby": A, "aria-describedby": j, "aria-invalid": M }) {
|
|
77
77
|
s();
|
|
78
|
-
let
|
|
78
|
+
let N = t(), [P, F] = i({
|
|
79
79
|
value: v,
|
|
80
80
|
defaultValue: y ?? "#3b82f6",
|
|
81
81
|
onChange: b
|
|
82
|
-
}),
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
let n =
|
|
82
|
+
}), I = n(null), L = a(!1), R = g(m(P.value)), z = (e) => {
|
|
83
|
+
F(h(_(e), S));
|
|
84
|
+
}, B = (e, t) => {
|
|
85
|
+
let n = I.current;
|
|
86
86
|
if (!n) return;
|
|
87
87
|
let r = n.getBoundingClientRect(), i = p((e - r.left) / r.width, 0, 1), a = p((t - r.top) / r.height, 0, 1);
|
|
88
|
-
|
|
89
|
-
h:
|
|
88
|
+
z({
|
|
89
|
+
h: R.h,
|
|
90
90
|
s: i * 100,
|
|
91
91
|
l: (1 - a) * 100,
|
|
92
|
-
a:
|
|
92
|
+
a: R.a
|
|
93
93
|
});
|
|
94
94
|
};
|
|
95
95
|
o(() => {
|
|
96
|
-
if (!
|
|
97
|
-
let e = (e) =>
|
|
98
|
-
|
|
96
|
+
if (!L.value) return;
|
|
97
|
+
let e = (e) => B(e.clientX, e.clientY), t = () => {
|
|
98
|
+
L.value = !1;
|
|
99
99
|
};
|
|
100
100
|
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", t), () => {
|
|
101
101
|
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", t);
|
|
102
102
|
};
|
|
103
103
|
});
|
|
104
|
-
let
|
|
105
|
-
let t = e.shiftKey ? 10 : 2, { s: n, l: r } =
|
|
104
|
+
let V = (e) => {
|
|
105
|
+
let t = e.shiftKey ? 10 : 2, { s: n, l: r } = R;
|
|
106
106
|
if (e.key === "ArrowLeft") n -= t;
|
|
107
107
|
else if (e.key === "ArrowRight") n += t;
|
|
108
108
|
else if (e.key === "ArrowUp") r += t;
|
|
109
109
|
else if (e.key === "ArrowDown") r -= t;
|
|
110
110
|
else return;
|
|
111
|
-
e.preventDefault(),
|
|
112
|
-
h:
|
|
111
|
+
e.preventDefault(), z({
|
|
112
|
+
h: R.h,
|
|
113
113
|
s: p(n, 0, 100),
|
|
114
114
|
l: p(r, 0, 100),
|
|
115
|
-
a:
|
|
115
|
+
a: R.a
|
|
116
116
|
});
|
|
117
|
-
},
|
|
118
|
-
!x || x.length === 0 ||
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
hue:
|
|
123
|
-
alpha:
|
|
124
|
-
colorArea:
|
|
125
|
-
eyedropper:
|
|
126
|
-
},
|
|
117
|
+
}, H = (e, t) => {
|
|
118
|
+
!x || x.length === 0 || F(x[(t + e + x.length) % x.length]);
|
|
119
|
+
}, U = typeof window < "u" ? window.EyeDropper : void 0, W = () => {
|
|
120
|
+
U && new U().open().then((e) => F(e.sRGBHex));
|
|
121
|
+
}, G = {
|
|
122
|
+
hue: O?.hue ?? l(c.colorPicker.hue),
|
|
123
|
+
alpha: O?.alpha ?? l(c.colorPicker.alpha),
|
|
124
|
+
colorArea: O?.colorArea ?? l(c.colorPicker.colorArea),
|
|
125
|
+
eyedropper: O?.eyedropper ?? l(c.colorPicker.eyedropper)
|
|
126
|
+
}, K = h(m(P.value), !1), q = `hsl(${R.h} 100% 50%)`;
|
|
127
127
|
return /* @__PURE__ */ f("div", {
|
|
128
|
-
className: r(e.picker,
|
|
129
|
-
"data-size":
|
|
130
|
-
"data-disabled":
|
|
128
|
+
className: r(e.picker, D),
|
|
129
|
+
"data-size": E,
|
|
130
|
+
"data-disabled": T || void 0,
|
|
131
131
|
children: [
|
|
132
132
|
C && /* @__PURE__ */ d("span", {
|
|
133
133
|
className: e.label,
|
|
134
|
-
id: `${
|
|
134
|
+
id: `${N}-label`,
|
|
135
135
|
children: C
|
|
136
136
|
}),
|
|
137
137
|
/* @__PURE__ */ d("div", {
|
|
138
|
-
ref:
|
|
138
|
+
ref: I,
|
|
139
139
|
className: e.area,
|
|
140
140
|
role: "slider",
|
|
141
|
-
"aria-label":
|
|
142
|
-
"aria-valuetext":
|
|
143
|
-
"aria-disabled":
|
|
144
|
-
tabIndex:
|
|
145
|
-
style: { background:
|
|
141
|
+
"aria-label": G.colorArea,
|
|
142
|
+
"aria-valuetext": K,
|
|
143
|
+
"aria-disabled": T || void 0,
|
|
144
|
+
tabIndex: T ? -1 : 0,
|
|
145
|
+
style: { background: q },
|
|
146
146
|
onPointerDown: (e) => {
|
|
147
|
-
|
|
147
|
+
T || (e.preventDefault(), L.value = !0, B(e.clientX, e.clientY));
|
|
148
148
|
},
|
|
149
|
-
onKeyDown:
|
|
149
|
+
onKeyDown: V,
|
|
150
150
|
children: /* @__PURE__ */ d("span", {
|
|
151
151
|
className: e.thumb,
|
|
152
152
|
style: {
|
|
153
|
-
insetInlineStart: `${
|
|
154
|
-
insetBlockStart: `${100 -
|
|
155
|
-
backgroundColor:
|
|
153
|
+
insetInlineStart: `${R.s}%`,
|
|
154
|
+
insetBlockStart: `${100 - R.l}%`,
|
|
155
|
+
backgroundColor: K
|
|
156
156
|
}
|
|
157
157
|
})
|
|
158
158
|
}),
|
|
@@ -161,45 +161,45 @@ function v({ value: v, defaultValue: y, onValueChange: b, presets: x, alpha: S =
|
|
|
161
161
|
children: [
|
|
162
162
|
/* @__PURE__ */ d("label", {
|
|
163
163
|
className: e.srOnly,
|
|
164
|
-
htmlFor: `${
|
|
165
|
-
children:
|
|
164
|
+
htmlFor: `${N}-hue`,
|
|
165
|
+
children: G.hue
|
|
166
166
|
}),
|
|
167
167
|
/* @__PURE__ */ d("input", {
|
|
168
|
-
id: `${
|
|
168
|
+
id: `${N}-hue`,
|
|
169
169
|
className: e.hue,
|
|
170
170
|
type: "range",
|
|
171
171
|
min: 0,
|
|
172
172
|
max: 360,
|
|
173
173
|
step: 1,
|
|
174
|
-
value: Math.round(
|
|
175
|
-
disabled:
|
|
176
|
-
"aria-label":
|
|
177
|
-
onChange: (e) =>
|
|
174
|
+
value: Math.round(R.h),
|
|
175
|
+
disabled: T,
|
|
176
|
+
"aria-label": G.hue,
|
|
177
|
+
onChange: (e) => z({
|
|
178
178
|
h: Number(e.target.value),
|
|
179
|
-
s:
|
|
180
|
-
l:
|
|
181
|
-
a:
|
|
179
|
+
s: R.s,
|
|
180
|
+
l: R.l,
|
|
181
|
+
a: R.a
|
|
182
182
|
})
|
|
183
183
|
}),
|
|
184
184
|
S && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("label", {
|
|
185
185
|
className: e.srOnly,
|
|
186
|
-
htmlFor: `${
|
|
187
|
-
children:
|
|
186
|
+
htmlFor: `${N}-alpha`,
|
|
187
|
+
children: G.alpha
|
|
188
188
|
}), /* @__PURE__ */ d("input", {
|
|
189
|
-
id: `${
|
|
189
|
+
id: `${N}-alpha`,
|
|
190
190
|
className: e.alpha,
|
|
191
191
|
type: "range",
|
|
192
192
|
min: 0,
|
|
193
193
|
max: 1,
|
|
194
194
|
step: .01,
|
|
195
|
-
value:
|
|
196
|
-
disabled:
|
|
197
|
-
"aria-label":
|
|
198
|
-
style: { "--cascivo-color-picker-solid":
|
|
199
|
-
onChange: (e) =>
|
|
200
|
-
h:
|
|
201
|
-
s:
|
|
202
|
-
l:
|
|
195
|
+
value: R.a,
|
|
196
|
+
disabled: T,
|
|
197
|
+
"aria-label": G.alpha,
|
|
198
|
+
style: { "--cascivo-color-picker-solid": K },
|
|
199
|
+
onChange: (e) => z({
|
|
200
|
+
h: R.h,
|
|
201
|
+
s: R.s,
|
|
202
|
+
l: R.l,
|
|
203
203
|
a: Number(e.target.value)
|
|
204
204
|
})
|
|
205
205
|
})] })
|
|
@@ -208,17 +208,17 @@ function v({ value: v, defaultValue: y, onValueChange: b, presets: x, alpha: S =
|
|
|
208
208
|
x && x.length > 0 && /* @__PURE__ */ d("div", {
|
|
209
209
|
className: e.presets,
|
|
210
210
|
role: "group",
|
|
211
|
-
"aria-label":
|
|
211
|
+
"aria-label": G.colorArea,
|
|
212
212
|
children: x.map((t, n) => /* @__PURE__ */ d("button", {
|
|
213
213
|
type: "button",
|
|
214
214
|
className: e.preset,
|
|
215
215
|
style: { backgroundColor: t },
|
|
216
216
|
"aria-label": t,
|
|
217
|
-
"aria-pressed": t.toLowerCase() ===
|
|
218
|
-
disabled:
|
|
219
|
-
onClick: () =>
|
|
217
|
+
"aria-pressed": t.toLowerCase() === P.value.toLowerCase(),
|
|
218
|
+
disabled: T,
|
|
219
|
+
onClick: () => F(t),
|
|
220
220
|
onKeyDown: (e) => {
|
|
221
|
-
e.key === "ArrowRight" ? (e.preventDefault(),
|
|
221
|
+
e.key === "ArrowRight" ? (e.preventDefault(), H(1, n)) : e.key === "ArrowLeft" && (e.preventDefault(), H(-1, n));
|
|
222
222
|
}
|
|
223
223
|
}, t))
|
|
224
224
|
}),
|
|
@@ -227,23 +227,27 @@ function v({ value: v, defaultValue: y, onValueChange: b, presets: x, alpha: S =
|
|
|
227
227
|
children: [
|
|
228
228
|
/* @__PURE__ */ d("span", {
|
|
229
229
|
className: e.preview,
|
|
230
|
-
style: { backgroundColor:
|
|
230
|
+
style: { backgroundColor: P.value },
|
|
231
231
|
"aria-hidden": "true"
|
|
232
232
|
}),
|
|
233
233
|
/* @__PURE__ */ d("input", {
|
|
234
234
|
className: e.text,
|
|
235
235
|
type: "text",
|
|
236
|
-
value:
|
|
237
|
-
disabled:
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
value: P.value,
|
|
237
|
+
disabled: T,
|
|
238
|
+
id: k,
|
|
239
|
+
"aria-labelledby": A,
|
|
240
|
+
"aria-describedby": j,
|
|
241
|
+
"aria-invalid": M,
|
|
242
|
+
"aria-label": A === void 0 ? w ?? C ?? G.colorArea : void 0,
|
|
243
|
+
onChange: (e) => F(e.target.value)
|
|
240
244
|
}),
|
|
241
|
-
|
|
245
|
+
U && /* @__PURE__ */ d("button", {
|
|
242
246
|
type: "button",
|
|
243
247
|
className: e.eyedropper,
|
|
244
|
-
"aria-label":
|
|
245
|
-
disabled:
|
|
246
|
-
onClick:
|
|
248
|
+
"aria-label": G.eyedropper,
|
|
249
|
+
disabled: T,
|
|
250
|
+
onClick: W,
|
|
247
251
|
children: /* @__PURE__ */ d("svg", {
|
|
248
252
|
width: "16",
|
|
249
253
|
height: "16",
|
|
@@ -2,164 +2,169 @@
|
|
|
2
2
|
|
|
3
3
|
import e from "./combobox.module.js";
|
|
4
4
|
import { useId as t, useRef as n } from "react";
|
|
5
|
-
import { cn as r, createMachine as i, focusElement as
|
|
6
|
-
import { builtin as
|
|
7
|
-
import { jsx as
|
|
5
|
+
import { cn as r, createMachine as i, focusElement as ee, useControllableSignal as a, useMachine as o, useSignal as s, useSignalEffect as c, useSignals as te } from "@cascivo/core";
|
|
6
|
+
import { builtin as l, t as u } from "@cascivo/i18n";
|
|
7
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
8
8
|
//#region ../components/src/combobox/combobox.tsx
|
|
9
|
-
var
|
|
9
|
+
var p = i({
|
|
10
10
|
initial: "closed",
|
|
11
11
|
states: {
|
|
12
12
|
closed: { on: { OPEN: "open" } },
|
|
13
13
|
open: { on: { CLOSE: "closed" } }
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
function m(...e) {
|
|
17
|
+
return e.filter(Boolean).join(" ") || void 0;
|
|
18
|
+
}
|
|
19
|
+
function h({ options: i, value: h, defaultValue: g, onValueChange: ne, clearable: _ = !1, searchable: v = !0, label: y, ariaLabel: b, hint: x, error: S, size: re = "md", disabled: C = !1, labels: w, className: T, id: E, "aria-labelledby": D, "aria-describedby": O, "aria-invalid": k }) {
|
|
20
|
+
te();
|
|
21
|
+
let [A, j] = o(p), M = t(), N = E ?? `cascade-combobox-${M}`, P = `${M}-listbox`, F = n(null), I = w?.placeholder ?? u(l.combobox.placeholder), L = w?.empty ?? u(l.combobox.empty), R = w?.clear ?? u(l.combobox.clear), z = w?.search ?? u(l.combobox.search), [B] = a({
|
|
22
|
+
value: h,
|
|
23
|
+
defaultValue: g
|
|
24
|
+
}), V = s(""), H = s(0), U = A.value === "open", W = i.filter((e) => !v || !V.value ? !0 : e.label.toLowerCase().includes(V.value.toLowerCase())), G = i.find((e) => e.value === B.value);
|
|
25
|
+
c(() => {
|
|
26
|
+
if (!U) return;
|
|
24
27
|
let e = (e) => {
|
|
25
28
|
let t = document.getElementById(`${M}-root`);
|
|
26
29
|
t && !t.contains(e.target) && j("CLOSE");
|
|
27
30
|
};
|
|
28
31
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
29
32
|
});
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
j("CLOSE"),
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
if (
|
|
40
|
-
let t =
|
|
41
|
-
t !== void 0 && (
|
|
42
|
-
},
|
|
43
|
-
(e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && (e.preventDefault(),
|
|
44
|
-
},
|
|
33
|
+
let K = () => {
|
|
34
|
+
C || (V.value = "", H.value = 0, j("OPEN"), setTimeout(() => ee(F.current), 0));
|
|
35
|
+
}, q = () => {
|
|
36
|
+
j("CLOSE"), V.value = "";
|
|
37
|
+
}, J = ne, Y = (e) => {
|
|
38
|
+
h === void 0 && (B.value = e), J?.(e), q();
|
|
39
|
+
}, X = () => {
|
|
40
|
+
h === void 0 && (B.value = void 0), J?.(void 0);
|
|
41
|
+
}, Z = W.flatMap((e, t) => e.disabled ? [] : [t]), Q = (e) => {
|
|
42
|
+
if (Z.length === 0) return;
|
|
43
|
+
let t = Z[(Z.indexOf(H.value) + e + Z.length) % Z.length];
|
|
44
|
+
t !== void 0 && (H.value = t);
|
|
45
|
+
}, ie = (e) => {
|
|
46
|
+
(e.key === "Enter" || e.key === " " || e.key === "ArrowDown") && (e.preventDefault(), K());
|
|
47
|
+
}, ae = (e) => {
|
|
45
48
|
switch (e.key) {
|
|
46
49
|
case "ArrowDown":
|
|
47
|
-
e.preventDefault(),
|
|
50
|
+
e.preventDefault(), Q(1);
|
|
48
51
|
break;
|
|
49
52
|
case "ArrowUp":
|
|
50
|
-
e.preventDefault(),
|
|
53
|
+
e.preventDefault(), Q(-1);
|
|
51
54
|
break;
|
|
52
55
|
case "Enter": {
|
|
53
56
|
e.preventDefault();
|
|
54
|
-
let t =
|
|
55
|
-
t && !t.disabled &&
|
|
57
|
+
let t = W[H.value];
|
|
58
|
+
t && !t.disabled && Y(t.value);
|
|
56
59
|
break;
|
|
57
60
|
}
|
|
58
61
|
case "Escape":
|
|
59
|
-
e.preventDefault(),
|
|
62
|
+
e.preventDefault(), q();
|
|
60
63
|
break;
|
|
61
64
|
case "Tab":
|
|
62
|
-
|
|
65
|
+
q();
|
|
63
66
|
break;
|
|
64
67
|
}
|
|
65
68
|
}, $ = (e) => `${M}-option-${e}`;
|
|
66
|
-
return /* @__PURE__ */
|
|
69
|
+
return /* @__PURE__ */ f("div", {
|
|
67
70
|
id: `${M}-root`,
|
|
68
|
-
className: r(e.wrapper,
|
|
69
|
-
"data-state":
|
|
70
|
-
"data-size":
|
|
71
|
+
className: r(e.wrapper, T),
|
|
72
|
+
"data-state": S ? "error" : A.value,
|
|
73
|
+
"data-size": re,
|
|
71
74
|
children: [
|
|
72
|
-
|
|
75
|
+
y && /* @__PURE__ */ d("label", {
|
|
73
76
|
className: e.label,
|
|
74
77
|
htmlFor: N,
|
|
75
|
-
children:
|
|
78
|
+
children: y
|
|
76
79
|
}),
|
|
77
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ f("div", {
|
|
78
81
|
className: e.field,
|
|
79
|
-
children: [/* @__PURE__ */
|
|
82
|
+
children: [/* @__PURE__ */ f("button", {
|
|
80
83
|
id: N,
|
|
81
84
|
type: "button",
|
|
82
85
|
role: "combobox",
|
|
83
|
-
"aria-expanded":
|
|
86
|
+
"aria-expanded": U,
|
|
84
87
|
"aria-controls": P,
|
|
85
88
|
"aria-haspopup": "listbox",
|
|
86
|
-
"aria-
|
|
87
|
-
"aria-
|
|
88
|
-
"aria-
|
|
89
|
+
"aria-labelledby": D,
|
|
90
|
+
"aria-label": b,
|
|
91
|
+
"aria-activedescendant": U && H.value >= 0 ? $(H.value) : void 0,
|
|
92
|
+
"aria-invalid": S ? !0 : k,
|
|
93
|
+
"aria-describedby": m(S ? `${M}-error` : x ? `${M}-hint` : void 0, O),
|
|
89
94
|
className: e.trigger,
|
|
90
|
-
disabled:
|
|
91
|
-
onKeyDown:
|
|
92
|
-
onClick:
|
|
93
|
-
children: [/* @__PURE__ */
|
|
94
|
-
className: r(e.value,
|
|
95
|
-
children:
|
|
96
|
-
}), /* @__PURE__ */
|
|
95
|
+
disabled: C,
|
|
96
|
+
onKeyDown: ie,
|
|
97
|
+
onClick: U ? q : K,
|
|
98
|
+
children: [/* @__PURE__ */ d("span", {
|
|
99
|
+
className: r(e.value, G ? void 0 : e.placeholder),
|
|
100
|
+
children: G?.label ?? I
|
|
101
|
+
}), /* @__PURE__ */ d("span", {
|
|
97
102
|
className: e.chevron,
|
|
98
103
|
"aria-hidden": "true"
|
|
99
104
|
})]
|
|
100
|
-
}),
|
|
105
|
+
}), _ && B.value !== void 0 && /* @__PURE__ */ d("button", {
|
|
101
106
|
type: "button",
|
|
102
107
|
className: e.clear,
|
|
103
|
-
"aria-label":
|
|
108
|
+
"aria-label": R,
|
|
104
109
|
onClick: (e) => {
|
|
105
|
-
e.stopPropagation(),
|
|
110
|
+
e.stopPropagation(), X();
|
|
106
111
|
},
|
|
107
112
|
children: "✕"
|
|
108
113
|
})]
|
|
109
114
|
}),
|
|
110
|
-
/* @__PURE__ */
|
|
115
|
+
/* @__PURE__ */ f("div", {
|
|
111
116
|
role: "listbox",
|
|
112
117
|
id: P,
|
|
113
118
|
className: e.listbox,
|
|
114
|
-
"data-state":
|
|
115
|
-
"aria-label":
|
|
116
|
-
children: [
|
|
119
|
+
"data-state": U ? "open" : "closed",
|
|
120
|
+
"aria-label": y,
|
|
121
|
+
children: [v && U && /* @__PURE__ */ d("div", {
|
|
117
122
|
className: e.searchWrapper,
|
|
118
|
-
children: /* @__PURE__ */
|
|
123
|
+
children: /* @__PURE__ */ d("input", {
|
|
119
124
|
ref: F,
|
|
120
125
|
type: "text",
|
|
121
126
|
className: e.search,
|
|
122
|
-
value:
|
|
127
|
+
value: V.value,
|
|
123
128
|
onChange: (e) => {
|
|
124
|
-
|
|
129
|
+
V.value = e.target.value, H.value = 0;
|
|
125
130
|
},
|
|
126
|
-
onKeyDown:
|
|
127
|
-
"aria-label":
|
|
131
|
+
onKeyDown: ae,
|
|
132
|
+
"aria-label": z,
|
|
128
133
|
autoComplete: "off"
|
|
129
134
|
})
|
|
130
|
-
}),
|
|
135
|
+
}), W.length === 0 ? /* @__PURE__ */ d("div", {
|
|
131
136
|
className: e.empty,
|
|
132
|
-
children:
|
|
133
|
-
}) :
|
|
137
|
+
children: L
|
|
138
|
+
}) : W.map((t, n) => /* @__PURE__ */ d("div", {
|
|
134
139
|
id: $(n),
|
|
135
140
|
role: "option",
|
|
136
|
-
"aria-selected": t.value ===
|
|
141
|
+
"aria-selected": t.value === B.value,
|
|
137
142
|
"aria-disabled": t.disabled || void 0,
|
|
138
|
-
"data-state": n ===
|
|
143
|
+
"data-state": n === H.value ? "active" : void 0,
|
|
139
144
|
"data-disabled": t.disabled || void 0,
|
|
140
145
|
className: e.option,
|
|
141
146
|
onMouseEnter: () => {
|
|
142
|
-
t.disabled || (
|
|
147
|
+
t.disabled || (H.value = n);
|
|
143
148
|
},
|
|
144
149
|
onClick: () => {
|
|
145
|
-
t.disabled ||
|
|
150
|
+
t.disabled || Y(t.value);
|
|
146
151
|
},
|
|
147
152
|
children: t.label
|
|
148
153
|
}, t.value))]
|
|
149
154
|
}),
|
|
150
|
-
|
|
155
|
+
S && /* @__PURE__ */ d("span", {
|
|
151
156
|
id: `${M}-error`,
|
|
152
157
|
className: e.error,
|
|
153
158
|
role: "alert",
|
|
154
|
-
children:
|
|
159
|
+
children: S
|
|
155
160
|
}),
|
|
156
|
-
!
|
|
161
|
+
!S && x && /* @__PURE__ */ d("span", {
|
|
157
162
|
id: `${M}-hint`,
|
|
158
163
|
className: e.hint,
|
|
159
|
-
children:
|
|
164
|
+
children: x
|
|
160
165
|
})
|
|
161
166
|
]
|
|
162
167
|
});
|
|
163
168
|
}
|
|
164
169
|
//#endregion
|
|
165
|
-
export {
|
|
170
|
+
export { h as Combobox };
|