@overdoser/react-toolkit 0.15.0 → 0.17.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/AGENTS.md +2 -0
- package/CHANGELOG.md +87 -0
- package/components/Chart/AreaChart.d.ts +5 -1
- package/components/Chart/AreaChart.js +155 -144
- package/components/Chart/BarChart.js +5 -5
- package/components/Chart/PieChart.js +2 -5
- package/components/Chart/RadarChart.js +2 -5
- package/components/Chart/TradingChart.js +258 -257
- package/components/Drawer/Drawer.js +69 -70
- package/components/Dropdown/Dropdown.js +51 -56
- package/components/Modal/Modal.js +42 -47
- package/components/Popover/Popover.js +52 -55
- package/components/SplitButton/SplitButton.js +50 -55
- package/components/inputs/DatePicker/CalendarPanel.d.ts +40 -0
- package/components/inputs/DatePicker/CalendarPanel.js +287 -0
- package/components/inputs/DatePicker/CalendarPanel.module.scss.js +41 -0
- package/components/inputs/DatePicker/DatePicker.d.ts +3 -1
- package/components/inputs/DatePicker/DatePicker.js +105 -192
- package/components/inputs/DatePicker/DatePicker.module.scss.js +20 -40
- package/components/inputs/DateTimePicker/DateTimePicker.d.ts +141 -0
- package/components/inputs/DateTimePicker/DateTimePicker.js +232 -0
- package/components/inputs/DateTimePicker/DateTimePicker.module.scss.js +37 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.d.ts +48 -0
- package/components/inputs/DateTimePicker/DateTimeSegments.js +252 -0
- package/components/inputs/DateTimePicker/TimeField.d.ts +18 -0
- package/components/inputs/DateTimePicker/TimeField.js +135 -0
- package/components/inputs/DateTimePicker/index.d.ts +3 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.d.ts +44 -0
- package/components/inputs/DateTimePicker/timeZoneUtils.js +102 -0
- package/components/inputs/NumberInput/NumberInput.js +79 -81
- package/components/inputs/Select/Select.d.ts +5 -0
- package/components/inputs/Select/Select.js +340 -285
- package/hooks/useEscapeLayer.d.ts +36 -0
- package/hooks/useEscapeLayer.js +33 -0
- package/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.js +108 -106
- package/index.layered.css +1 -1
- package/llms.txt +29 -4
- package/manifest.json +127 -1
- package/package.json +1 -1
|
@@ -1,376 +1,425 @@
|
|
|
1
|
-
import { jsx as s, jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import
|
|
1
|
+
import { jsx as s, jsxs as R, Fragment as xe } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as ie, useState as X, useRef as N, useId as de, useCallback as M, useMemo as fe, useEffect as B } from "react";
|
|
3
|
+
import { createPortal as me } from "react-dom";
|
|
4
|
+
import h from "clsx";
|
|
5
5
|
import e from "./Select.module.scss.js";
|
|
6
|
-
import { usePortalPosition as
|
|
7
|
-
const
|
|
6
|
+
import { usePortalPosition as he } from "../../../hooks/usePortalPosition.js";
|
|
7
|
+
const pe = ie(
|
|
8
8
|
({
|
|
9
|
-
inputSize:
|
|
10
|
-
error:
|
|
11
|
-
options:
|
|
12
|
-
placeholder:
|
|
13
|
-
classes:
|
|
14
|
-
className:
|
|
15
|
-
style:
|
|
16
|
-
children:
|
|
9
|
+
inputSize: u = "md",
|
|
10
|
+
error: p = !1,
|
|
11
|
+
options: f,
|
|
12
|
+
placeholder: I,
|
|
13
|
+
classes: o,
|
|
14
|
+
className: E,
|
|
15
|
+
style: A,
|
|
16
|
+
children: v,
|
|
17
17
|
searchable: g,
|
|
18
|
-
searchPlaceholder:
|
|
19
|
-
onChange:
|
|
20
|
-
onValueChange:
|
|
21
|
-
...
|
|
22
|
-
},
|
|
23
|
-
const
|
|
24
|
-
|
|
18
|
+
searchPlaceholder: y,
|
|
19
|
+
onChange: z,
|
|
20
|
+
onValueChange: x,
|
|
21
|
+
...O
|
|
22
|
+
}, P) => {
|
|
23
|
+
const G = z || x ? (k) => {
|
|
24
|
+
z?.(k), x?.(k.target.value);
|
|
25
25
|
} : void 0;
|
|
26
|
-
return /* @__PURE__ */
|
|
27
|
-
/* @__PURE__ */
|
|
26
|
+
return /* @__PURE__ */ R("div", { className: h(e.wrapper, e[u], p && e.error, o?.wrapper, E), style: A, children: [
|
|
27
|
+
/* @__PURE__ */ R(
|
|
28
28
|
"select",
|
|
29
29
|
{
|
|
30
|
-
ref:
|
|
31
|
-
className:
|
|
32
|
-
onChange:
|
|
33
|
-
...
|
|
30
|
+
ref: P,
|
|
31
|
+
className: h(e.root, e[u], p && e.error, o?.root),
|
|
32
|
+
onChange: G,
|
|
33
|
+
...O,
|
|
34
34
|
children: [
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
I && /* @__PURE__ */ s("option", { value: "", disabled: !0, children: I }),
|
|
36
|
+
f ? f.map((k) => /* @__PURE__ */ s("option", { value: k.value, disabled: k.disabled, children: k.label }, k.value)) : v
|
|
37
37
|
]
|
|
38
38
|
}
|
|
39
39
|
),
|
|
40
|
-
/* @__PURE__ */ s("span", { className:
|
|
40
|
+
/* @__PURE__ */ s("span", { className: h(e.arrow, o?.arrow) })
|
|
41
41
|
] });
|
|
42
42
|
}
|
|
43
43
|
);
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
pe.displayName = "NativeSelect";
|
|
45
|
+
function ve(u) {
|
|
46
|
+
const { name: p, form: f, required: I, title: o, autoFocus: E, tabIndex: A } = u, v = { title: o, autoFocus: E, tabIndex: A };
|
|
47
|
+
I && (v["aria-required"] = !0);
|
|
48
|
+
for (const y of Object.keys(u))
|
|
49
|
+
(y.startsWith("aria-") || y.startsWith("data-")) && (v[y] = u[y]);
|
|
50
|
+
const g = {};
|
|
51
|
+
for (const y of Object.keys(v))
|
|
52
|
+
y.startsWith("aria-") && (g[y] = v[y]);
|
|
53
|
+
return { hidden: { name: p, form: f }, control: v, aria: g };
|
|
54
|
+
}
|
|
55
|
+
function be(u, p, f) {
|
|
56
|
+
const I = N(!1);
|
|
57
|
+
return {
|
|
58
|
+
onFocus: (o) => {
|
|
59
|
+
I.current || (I.current = !0, u?.(o));
|
|
60
|
+
},
|
|
61
|
+
onBlur: (o) => {
|
|
62
|
+
const E = o.relatedTarget;
|
|
63
|
+
E && f.some((A) => A.current?.contains(E)) || (I.current = !1, p?.(o));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const ge = ie(
|
|
46
68
|
({
|
|
47
|
-
inputSize:
|
|
48
|
-
error:
|
|
49
|
-
options:
|
|
50
|
-
placeholder:
|
|
51
|
-
classes:
|
|
52
|
-
className:
|
|
53
|
-
style:
|
|
54
|
-
value:
|
|
69
|
+
inputSize: u = "md",
|
|
70
|
+
error: p = !1,
|
|
71
|
+
options: f = [],
|
|
72
|
+
placeholder: I = "Select...",
|
|
73
|
+
classes: o,
|
|
74
|
+
className: E,
|
|
75
|
+
style: A,
|
|
76
|
+
value: v,
|
|
55
77
|
disabled: g,
|
|
56
|
-
id:
|
|
57
|
-
searchPlaceholder:
|
|
58
|
-
onChange:
|
|
59
|
-
onValueChange:
|
|
60
|
-
portal:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}, [])
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
id: y,
|
|
79
|
+
searchPlaceholder: z = "Search...",
|
|
80
|
+
onChange: x,
|
|
81
|
+
onValueChange: O,
|
|
82
|
+
portal: P = !0,
|
|
83
|
+
onFocus: G,
|
|
84
|
+
onBlur: k,
|
|
85
|
+
...re
|
|
86
|
+
}, _) => {
|
|
87
|
+
const [b, ne] = X(!1), [U, F] = X(""), [c, d] = X(0), H = N(null), S = N(null), q = N(null), D = N(null), C = N(null), j = de(), K = he(H, b && P), { hidden: J, control: le, aria: Y } = ve(re), ae = be(G, k, [H, D]), T = N(null), oe = (r) => {
|
|
88
|
+
T.current = r, typeof _ == "function" ? _(r) : _ && (_.current = r);
|
|
89
|
+
}, Z = N(!1);
|
|
90
|
+
B(() => {
|
|
91
|
+
Z.current && !b && q.current?.focus(), Z.current = b;
|
|
92
|
+
}, [b]);
|
|
93
|
+
const W = M(() => {
|
|
94
|
+
ne(!1), F(""), d(0);
|
|
95
|
+
}, []), se = M(() => {
|
|
96
|
+
g || (ne(!0), F(""), d(0), setTimeout(() => S.current?.focus(), 0));
|
|
97
|
+
}, [g]), V = M(
|
|
73
98
|
(r) => {
|
|
74
|
-
if (
|
|
99
|
+
if (O?.(r), T.current) {
|
|
75
100
|
Object.getOwnPropertyDescriptor(
|
|
76
101
|
HTMLSelectElement.prototype,
|
|
77
102
|
"value"
|
|
78
|
-
)?.set?.call(
|
|
103
|
+
)?.set?.call(T.current, r);
|
|
79
104
|
const n = new Event("change", { bubbles: !0 });
|
|
80
|
-
|
|
105
|
+
T.current.dispatchEvent(n), x?.(n);
|
|
81
106
|
}
|
|
82
|
-
|
|
107
|
+
W();
|
|
83
108
|
},
|
|
84
|
-
[
|
|
85
|
-
),
|
|
86
|
-
if (!
|
|
87
|
-
const r =
|
|
88
|
-
return
|
|
89
|
-
}, [
|
|
90
|
-
|
|
91
|
-
const r =
|
|
109
|
+
[O, x, T, W]
|
|
110
|
+
), m = fe(() => {
|
|
111
|
+
if (!U) return f;
|
|
112
|
+
const r = U.toLowerCase();
|
|
113
|
+
return f.filter((l) => l.label.toLowerCase().includes(r));
|
|
114
|
+
}, [f, U]);
|
|
115
|
+
B(() => {
|
|
116
|
+
const r = m.findIndex((l) => !l.disabled);
|
|
92
117
|
d(r >= 0 ? r : 0);
|
|
93
|
-
}, [
|
|
94
|
-
if (!
|
|
95
|
-
const r =
|
|
118
|
+
}, [m]), B(() => {
|
|
119
|
+
if (!b) return;
|
|
120
|
+
const r = C.current;
|
|
96
121
|
if (!r) return;
|
|
97
122
|
r.querySelectorAll('[role="option"]')[c]?.scrollIntoView?.({ block: "nearest" });
|
|
98
|
-
}, [c,
|
|
99
|
-
const
|
|
123
|
+
}, [c, b]);
|
|
124
|
+
const ee = M(
|
|
100
125
|
(r) => {
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
126
|
+
const l = m.map((n, w) => n.disabled ? -1 : w).filter((n) => n >= 0);
|
|
127
|
+
if (r.key === "Escape") {
|
|
128
|
+
r.preventDefault(), W();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (l.length !== 0) {
|
|
103
132
|
if (r.key === "ArrowDown")
|
|
104
133
|
r.preventDefault(), d((n) => {
|
|
105
|
-
const
|
|
106
|
-
return
|
|
134
|
+
const w = l.indexOf(n);
|
|
135
|
+
return w < l.length - 1 ? l[w + 1] : l[0];
|
|
107
136
|
});
|
|
108
137
|
else if (r.key === "ArrowUp")
|
|
109
138
|
r.preventDefault(), d((n) => {
|
|
110
|
-
const
|
|
111
|
-
return
|
|
139
|
+
const w = l.indexOf(n);
|
|
140
|
+
return w > 0 ? l[w - 1] : l[l.length - 1];
|
|
112
141
|
});
|
|
113
142
|
else if (r.key === "Enter") {
|
|
114
143
|
r.preventDefault();
|
|
115
|
-
const n =
|
|
116
|
-
n && !n.disabled &&
|
|
117
|
-
}
|
|
144
|
+
const n = m[c];
|
|
145
|
+
n && !n.disabled && V(n.value);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
118
148
|
},
|
|
119
|
-
[
|
|
149
|
+
[m, c, V, W]
|
|
120
150
|
);
|
|
121
|
-
|
|
122
|
-
if (!
|
|
123
|
-
const r = (
|
|
124
|
-
const n =
|
|
125
|
-
|
|
151
|
+
B(() => {
|
|
152
|
+
if (!b) return;
|
|
153
|
+
const r = (l) => {
|
|
154
|
+
const n = l.target;
|
|
155
|
+
H.current?.contains(n) || D.current?.contains(n) || W();
|
|
126
156
|
};
|
|
127
157
|
return document.addEventListener("mousedown", r), () => document.removeEventListener("mousedown", r);
|
|
128
|
-
}, [
|
|
129
|
-
const
|
|
130
|
-
return /* @__PURE__ */
|
|
158
|
+
}, [b, W]);
|
|
159
|
+
const $ = f.find((r) => r.value === v)?.label, ce = m.filter((r) => !r.disabled);
|
|
160
|
+
return /* @__PURE__ */ R(
|
|
131
161
|
"div",
|
|
132
162
|
{
|
|
133
|
-
ref:
|
|
134
|
-
className:
|
|
163
|
+
ref: H,
|
|
164
|
+
className: h(
|
|
135
165
|
e.wrapper,
|
|
136
166
|
e.searchableWrapper,
|
|
137
|
-
e[
|
|
138
|
-
|
|
167
|
+
e[u],
|
|
168
|
+
p && e.error,
|
|
139
169
|
g && e.disabled,
|
|
140
|
-
|
|
141
|
-
|
|
170
|
+
o?.wrapper,
|
|
171
|
+
E
|
|
142
172
|
),
|
|
143
|
-
style:
|
|
173
|
+
style: A,
|
|
174
|
+
...ae,
|
|
144
175
|
children: [
|
|
145
|
-
/* @__PURE__ */
|
|
176
|
+
/* @__PURE__ */ R(
|
|
146
177
|
"select",
|
|
147
178
|
{
|
|
148
|
-
ref:
|
|
179
|
+
ref: oe,
|
|
149
180
|
className: e.hiddenSelect,
|
|
150
|
-
value:
|
|
181
|
+
value: v ?? "",
|
|
151
182
|
disabled: g,
|
|
152
183
|
tabIndex: -1,
|
|
153
184
|
"aria-hidden": "true",
|
|
154
185
|
onChange: () => {
|
|
155
186
|
},
|
|
156
|
-
|
|
187
|
+
...J,
|
|
188
|
+
children: [
|
|
189
|
+
/* @__PURE__ */ s("option", { value: "" }),
|
|
190
|
+
f.map((r) => /* @__PURE__ */ s("option", { value: r.value, children: r.label }, r.value))
|
|
191
|
+
]
|
|
157
192
|
}
|
|
158
193
|
),
|
|
159
|
-
/* @__PURE__ */
|
|
194
|
+
/* @__PURE__ */ R(
|
|
160
195
|
"button",
|
|
161
196
|
{
|
|
162
|
-
ref:
|
|
163
|
-
id:
|
|
197
|
+
ref: q,
|
|
198
|
+
id: b ? void 0 : y,
|
|
164
199
|
type: "button",
|
|
165
|
-
className:
|
|
200
|
+
className: h(
|
|
166
201
|
e.root,
|
|
167
202
|
e.searchableTrigger,
|
|
168
|
-
e[
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
203
|
+
e[u],
|
|
204
|
+
b && e.triggerOpen,
|
|
205
|
+
p && e.error,
|
|
206
|
+
b && e.visuallyHidden,
|
|
207
|
+
o?.root
|
|
173
208
|
),
|
|
174
|
-
onClick:
|
|
209
|
+
onClick: se,
|
|
175
210
|
disabled: g,
|
|
176
|
-
"aria-expanded":
|
|
211
|
+
"aria-expanded": b,
|
|
177
212
|
"aria-haspopup": "listbox",
|
|
178
|
-
"aria-controls":
|
|
213
|
+
"aria-controls": b ? j : void 0,
|
|
214
|
+
...le,
|
|
179
215
|
children: [
|
|
180
|
-
/* @__PURE__ */ s("span", { className:
|
|
181
|
-
/* @__PURE__ */ s("span", { className:
|
|
216
|
+
/* @__PURE__ */ s("span", { className: h(e.triggerLabel, !$ && e.placeholder), children: $ || I }),
|
|
217
|
+
/* @__PURE__ */ s("span", { className: h(e.arrow, e.arrowInline, o?.arrow) })
|
|
182
218
|
]
|
|
183
219
|
}
|
|
184
220
|
),
|
|
185
|
-
|
|
221
|
+
b && /* @__PURE__ */ s(
|
|
186
222
|
"input",
|
|
187
223
|
{
|
|
188
|
-
ref:
|
|
224
|
+
ref: S,
|
|
225
|
+
id: y,
|
|
189
226
|
type: "text",
|
|
190
227
|
role: "combobox",
|
|
191
|
-
className:
|
|
228
|
+
className: h(
|
|
192
229
|
e.root,
|
|
193
230
|
e.searchableTrigger,
|
|
194
|
-
e[
|
|
231
|
+
e[u],
|
|
195
232
|
e.triggerOpen,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
233
|
+
p && e.error,
|
|
234
|
+
o?.root,
|
|
235
|
+
o?.search
|
|
199
236
|
),
|
|
200
|
-
placeholder:
|
|
201
|
-
value:
|
|
202
|
-
onChange: (r) =>
|
|
203
|
-
onKeyDown:
|
|
237
|
+
placeholder: $ || I,
|
|
238
|
+
value: U,
|
|
239
|
+
onChange: (r) => F(r.target.value),
|
|
240
|
+
onKeyDown: ee,
|
|
204
241
|
"aria-expanded": !0,
|
|
205
242
|
"aria-haspopup": "listbox",
|
|
206
|
-
"aria-controls":
|
|
207
|
-
"aria-activedescendant":
|
|
243
|
+
"aria-controls": j,
|
|
244
|
+
"aria-activedescendant": ce.length > 0 ? `select-option-${m[c]?.value}` : void 0,
|
|
245
|
+
"aria-label": Y["aria-labelledby"] || y ? void 0 : z,
|
|
246
|
+
...Y
|
|
208
247
|
}
|
|
209
248
|
),
|
|
210
|
-
|
|
211
|
-
const r =
|
|
249
|
+
b && (() => {
|
|
250
|
+
const r = P ? {
|
|
212
251
|
position: "fixed",
|
|
213
252
|
top: K.top + 4,
|
|
214
253
|
left: K.left,
|
|
215
254
|
right: "auto",
|
|
216
255
|
width: K.width,
|
|
217
256
|
zIndex: "var(--crk-z-floating)"
|
|
218
|
-
} : void 0,
|
|
257
|
+
} : void 0, l = /* @__PURE__ */ s(
|
|
219
258
|
"div",
|
|
220
259
|
{
|
|
221
|
-
id:
|
|
222
|
-
ref:
|
|
223
|
-
className:
|
|
260
|
+
id: j,
|
|
261
|
+
ref: D,
|
|
262
|
+
className: h(e.menu, o?.menu),
|
|
224
263
|
style: r,
|
|
225
264
|
role: "listbox",
|
|
226
|
-
children: /* @__PURE__ */ s("div", { className: e.menuItems, ref:
|
|
265
|
+
children: /* @__PURE__ */ s("div", { className: e.menuItems, ref: C, children: m.length === 0 ? /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }) : m.map((n, w) => /* @__PURE__ */ s(
|
|
227
266
|
"button",
|
|
228
267
|
{
|
|
229
268
|
id: `select-option-${n.value}`,
|
|
230
269
|
type: "button",
|
|
231
270
|
role: "option",
|
|
232
|
-
"aria-selected": n.value ===
|
|
233
|
-
className:
|
|
271
|
+
"aria-selected": n.value === v,
|
|
272
|
+
className: h(
|
|
234
273
|
e.item,
|
|
235
274
|
n.disabled && e.itemDisabled,
|
|
236
|
-
n.value ===
|
|
237
|
-
|
|
238
|
-
|
|
275
|
+
n.value === v && e.itemSelected,
|
|
276
|
+
w === c && e.itemHighlighted,
|
|
277
|
+
o?.item
|
|
239
278
|
),
|
|
240
279
|
disabled: n.disabled,
|
|
241
|
-
onClick: () =>
|
|
242
|
-
onMouseEnter: () => d(
|
|
280
|
+
onClick: () => V(n.value),
|
|
281
|
+
onMouseEnter: () => d(w),
|
|
243
282
|
children: n.content ?? n.label
|
|
244
283
|
},
|
|
245
284
|
n.value
|
|
246
285
|
)) })
|
|
247
286
|
}
|
|
248
287
|
);
|
|
249
|
-
return
|
|
288
|
+
return P && typeof document < "u" ? me(l, document.body) : l;
|
|
250
289
|
})()
|
|
251
290
|
]
|
|
252
291
|
}
|
|
253
292
|
);
|
|
254
293
|
}
|
|
255
294
|
);
|
|
256
|
-
|
|
257
|
-
const
|
|
295
|
+
ge.displayName = "SearchableSelect";
|
|
296
|
+
const ye = ie(
|
|
258
297
|
({
|
|
259
|
-
inputSize:
|
|
260
|
-
error:
|
|
261
|
-
options:
|
|
262
|
-
placeholder:
|
|
263
|
-
classes:
|
|
264
|
-
className:
|
|
265
|
-
style:
|
|
266
|
-
value:
|
|
298
|
+
inputSize: u = "md",
|
|
299
|
+
error: p = !1,
|
|
300
|
+
options: f = [],
|
|
301
|
+
placeholder: I = "Select...",
|
|
302
|
+
classes: o,
|
|
303
|
+
className: E,
|
|
304
|
+
style: A,
|
|
305
|
+
value: v,
|
|
267
306
|
disabled: g,
|
|
268
|
-
id:
|
|
269
|
-
searchPlaceholder:
|
|
270
|
-
onValuesChange:
|
|
271
|
-
clearSearchOnSelect:
|
|
272
|
-
closeOnSelect:
|
|
273
|
-
allowCreate:
|
|
274
|
-
onCreate:
|
|
275
|
-
createLabel:
|
|
276
|
-
portal:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
307
|
+
id: y,
|
|
308
|
+
searchPlaceholder: z,
|
|
309
|
+
onValuesChange: x,
|
|
310
|
+
clearSearchOnSelect: O = !0,
|
|
311
|
+
closeOnSelect: P = !0,
|
|
312
|
+
allowCreate: G = !1,
|
|
313
|
+
onCreate: k,
|
|
314
|
+
createLabel: re,
|
|
315
|
+
portal: _ = !0,
|
|
316
|
+
onFocus: b,
|
|
317
|
+
onBlur: ne,
|
|
318
|
+
...U
|
|
319
|
+
}, F) => {
|
|
320
|
+
const c = Array.isArray(v) ? v : v ? [v] : [], [d, H] = X(!1), [S, q] = X(""), [D, C] = X(0), j = N(null), K = N(null), J = N(null), le = N(null), Y = N(null), ae = de(), T = he(Y, d && _), { hidden: oe, control: Z } = ve(U), W = be(b, ne, [j, J]), se = N(null), V = (t) => {
|
|
321
|
+
se.current = t, typeof F == "function" ? F(t) : F && (F.current = t);
|
|
322
|
+
}, m = M(() => {
|
|
323
|
+
H(!1), q(""), C(0);
|
|
324
|
+
}, []), ee = M(() => {
|
|
325
|
+
g || (H(!0), q(""), C(0), setTimeout(() => K.current?.focus(), 0));
|
|
326
|
+
}, [g]), $ = M(
|
|
285
327
|
(t) => {
|
|
286
|
-
const i = c.includes(t) ? c.filter((
|
|
287
|
-
|
|
328
|
+
const i = c.includes(t) ? c.filter((a) => a !== t) : [...c, t];
|
|
329
|
+
x?.(i), P ? m() : O && q("");
|
|
288
330
|
},
|
|
289
|
-
[c,
|
|
290
|
-
),
|
|
331
|
+
[c, x, P, m, O]
|
|
332
|
+
), ce = M(
|
|
291
333
|
(t, i) => {
|
|
292
|
-
i.stopPropagation(),
|
|
334
|
+
i.stopPropagation(), x?.(c.filter((a) => a !== t));
|
|
293
335
|
},
|
|
294
|
-
[c,
|
|
295
|
-
),
|
|
296
|
-
if (!
|
|
297
|
-
const t =
|
|
298
|
-
return
|
|
299
|
-
}, [
|
|
300
|
-
(t) => t.label.toLowerCase() ===
|
|
301
|
-
) && !c.includes(
|
|
302
|
-
|
|
303
|
-
}, [
|
|
304
|
-
|
|
305
|
-
const t =
|
|
306
|
-
|
|
307
|
-
}, [
|
|
336
|
+
[c, x]
|
|
337
|
+
), r = fe(() => {
|
|
338
|
+
if (!S) return f;
|
|
339
|
+
const t = S.toLowerCase();
|
|
340
|
+
return f.filter((i) => i.label.toLowerCase().includes(t));
|
|
341
|
+
}, [f, S]), l = S.trim(), n = G && l.length > 0 && !f.some(
|
|
342
|
+
(t) => t.label.toLowerCase() === l.toLowerCase() || t.value === l
|
|
343
|
+
) && !c.includes(l), w = M(() => {
|
|
344
|
+
l && (c.includes(l) || (k?.(l), x?.([...c, l]), P ? m() : O && q("")));
|
|
345
|
+
}, [l, c, k, x, P, m, O]);
|
|
346
|
+
B(() => {
|
|
347
|
+
const t = r.findIndex((i) => !i.disabled);
|
|
348
|
+
C(t >= 0 ? t : 0);
|
|
349
|
+
}, [r]), B(() => {
|
|
308
350
|
if (!d) return;
|
|
309
|
-
const t =
|
|
351
|
+
const t = le.current;
|
|
310
352
|
if (!t) return;
|
|
311
|
-
t.querySelectorAll('[role="option"]')[
|
|
312
|
-
}, [
|
|
313
|
-
const
|
|
353
|
+
t.querySelectorAll('[role="option"]')[D]?.scrollIntoView?.({ block: "nearest" });
|
|
354
|
+
}, [D, d]);
|
|
355
|
+
const Q = r.length, we = M(
|
|
314
356
|
(t) => {
|
|
315
|
-
const i =
|
|
316
|
-
if (
|
|
317
|
-
t.preventDefault(),
|
|
357
|
+
const i = r.map((a, L) => a.disabled ? -1 : L).filter((a) => a >= 0);
|
|
358
|
+
if (n && i.push(Q), t.key === "Backspace" && S === "" && c.length > 0) {
|
|
359
|
+
t.preventDefault(), x?.(c.slice(0, -1));
|
|
318
360
|
return;
|
|
319
361
|
}
|
|
320
|
-
if (
|
|
362
|
+
if (t.key === "Escape") {
|
|
363
|
+
if (!d) return;
|
|
364
|
+
t.preventDefault(), m();
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (i.length !== 0) {
|
|
321
368
|
if (t.key === "ArrowDown") {
|
|
322
369
|
if (t.preventDefault(), !d) {
|
|
323
|
-
|
|
370
|
+
ee();
|
|
324
371
|
return;
|
|
325
372
|
}
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
return
|
|
373
|
+
C((a) => {
|
|
374
|
+
const L = i.indexOf(a);
|
|
375
|
+
return L < i.length - 1 ? i[L + 1] : i[0];
|
|
329
376
|
});
|
|
330
377
|
} else if (t.key === "ArrowUp")
|
|
331
|
-
t.preventDefault(),
|
|
332
|
-
const
|
|
333
|
-
return
|
|
378
|
+
t.preventDefault(), C((a) => {
|
|
379
|
+
const L = i.indexOf(a);
|
|
380
|
+
return L > 0 ? i[L - 1] : i[i.length - 1];
|
|
334
381
|
});
|
|
335
382
|
else if (t.key === "Enter") {
|
|
336
|
-
if (t.preventDefault(),
|
|
337
|
-
|
|
383
|
+
if (t.preventDefault(), n && D === Q) {
|
|
384
|
+
w();
|
|
338
385
|
return;
|
|
339
386
|
}
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
}
|
|
387
|
+
const a = r[D];
|
|
388
|
+
a && !a.disabled ? $(a.value) : n && w();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
343
391
|
},
|
|
344
|
-
[
|
|
392
|
+
[r, D, $, m, S, c, x, d, ee, n, w, Q]
|
|
345
393
|
);
|
|
346
|
-
|
|
394
|
+
B(() => {
|
|
347
395
|
if (!d) return;
|
|
348
396
|
const t = (i) => {
|
|
349
|
-
const
|
|
350
|
-
|
|
397
|
+
const a = i.target;
|
|
398
|
+
j.current?.contains(a) || J.current?.contains(a) || m();
|
|
351
399
|
};
|
|
352
400
|
return document.addEventListener("mousedown", t), () => document.removeEventListener("mousedown", t);
|
|
353
|
-
}, [d,
|
|
354
|
-
const
|
|
355
|
-
return /* @__PURE__ */
|
|
401
|
+
}, [d, m]);
|
|
402
|
+
const ue = c.map((t) => f.find((a) => a.value === t) ?? { value: t, label: t });
|
|
403
|
+
return /* @__PURE__ */ R(
|
|
356
404
|
"div",
|
|
357
405
|
{
|
|
358
|
-
ref:
|
|
359
|
-
className:
|
|
406
|
+
ref: j,
|
|
407
|
+
className: h(
|
|
360
408
|
e.wrapper,
|
|
361
409
|
e.searchableWrapper,
|
|
362
|
-
e[
|
|
363
|
-
|
|
410
|
+
e[u],
|
|
411
|
+
p && e.error,
|
|
364
412
|
g && e.disabled,
|
|
365
|
-
|
|
366
|
-
|
|
413
|
+
o?.wrapper,
|
|
414
|
+
E
|
|
367
415
|
),
|
|
368
|
-
style:
|
|
416
|
+
style: A,
|
|
417
|
+
...W,
|
|
369
418
|
children: [
|
|
370
|
-
/* @__PURE__ */
|
|
419
|
+
/* @__PURE__ */ R(
|
|
371
420
|
"select",
|
|
372
421
|
{
|
|
373
|
-
ref:
|
|
422
|
+
ref: V,
|
|
374
423
|
className: e.hiddenSelect,
|
|
375
424
|
multiple: !0,
|
|
376
425
|
value: c,
|
|
@@ -379,37 +428,41 @@ const ue = ne(
|
|
|
379
428
|
"aria-hidden": "true",
|
|
380
429
|
onChange: () => {
|
|
381
430
|
},
|
|
382
|
-
|
|
431
|
+
...oe,
|
|
432
|
+
children: [
|
|
433
|
+
f.map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value)),
|
|
434
|
+
ue.filter((t) => !f.some((i) => i.value === t.value)).map((t) => /* @__PURE__ */ s("option", { value: t.value, children: t.label }, t.value))
|
|
435
|
+
]
|
|
383
436
|
}
|
|
384
437
|
),
|
|
385
|
-
/* @__PURE__ */
|
|
438
|
+
/* @__PURE__ */ R(
|
|
386
439
|
"div",
|
|
387
440
|
{
|
|
388
|
-
ref:
|
|
389
|
-
className:
|
|
441
|
+
ref: Y,
|
|
442
|
+
className: h(
|
|
390
443
|
e.multiTrigger,
|
|
391
|
-
e[
|
|
444
|
+
e[u],
|
|
392
445
|
d && e.triggerOpen,
|
|
393
|
-
|
|
446
|
+
p && e.error,
|
|
394
447
|
g && e.multiTriggerDisabled,
|
|
395
|
-
|
|
448
|
+
o?.root
|
|
396
449
|
),
|
|
397
450
|
onClick: () => {
|
|
398
|
-
d ? K.current?.focus() :
|
|
451
|
+
d ? K.current?.focus() : ee();
|
|
399
452
|
},
|
|
400
453
|
role: "combobox",
|
|
401
454
|
"aria-expanded": d,
|
|
402
455
|
"aria-haspopup": "listbox",
|
|
403
|
-
"aria-controls": d ?
|
|
456
|
+
"aria-controls": d ? ae : void 0,
|
|
404
457
|
children: [
|
|
405
|
-
|
|
458
|
+
ue.map((t) => /* @__PURE__ */ R("span", { className: h(e.chip, o?.chip), children: [
|
|
406
459
|
/* @__PURE__ */ s("span", { className: e.chipLabel, children: t.content ?? t.label }),
|
|
407
460
|
/* @__PURE__ */ s(
|
|
408
461
|
"button",
|
|
409
462
|
{
|
|
410
463
|
type: "button",
|
|
411
|
-
className:
|
|
412
|
-
onClick: (i) =>
|
|
464
|
+
className: h(e.chipRemove, o?.chipRemove),
|
|
465
|
+
onClick: (i) => ce(t.value, i),
|
|
413
466
|
"aria-label": `Remove ${t.label}`,
|
|
414
467
|
tabIndex: -1,
|
|
415
468
|
children: "×"
|
|
@@ -420,85 +473,87 @@ const ue = ne(
|
|
|
420
473
|
"input",
|
|
421
474
|
{
|
|
422
475
|
ref: K,
|
|
423
|
-
id:
|
|
476
|
+
id: y,
|
|
424
477
|
type: "text",
|
|
425
478
|
className: e.multiSearch,
|
|
426
|
-
placeholder: c.length === 0 ?
|
|
427
|
-
value:
|
|
479
|
+
placeholder: c.length === 0 ? I : "",
|
|
480
|
+
value: S,
|
|
428
481
|
onChange: (t) => {
|
|
429
|
-
|
|
482
|
+
q(t.target.value), d || H(!0);
|
|
430
483
|
},
|
|
431
|
-
onKeyDown:
|
|
484
|
+
onKeyDown: we,
|
|
432
485
|
disabled: g,
|
|
433
|
-
"aria-label": "Search options"
|
|
486
|
+
"aria-label": Z["aria-labelledby"] ? void 0 : "Search options",
|
|
487
|
+
...Z
|
|
434
488
|
}
|
|
435
489
|
),
|
|
436
|
-
/* @__PURE__ */ s("span", { className:
|
|
490
|
+
/* @__PURE__ */ s("span", { className: h(e.arrow, e.arrowMulti, o?.arrow) })
|
|
437
491
|
]
|
|
438
492
|
}
|
|
439
493
|
),
|
|
440
494
|
d && (() => {
|
|
441
|
-
const t =
|
|
495
|
+
const t = _ ? {
|
|
442
496
|
position: "fixed",
|
|
443
|
-
top:
|
|
444
|
-
left:
|
|
497
|
+
top: T.top + 4,
|
|
498
|
+
left: T.left,
|
|
445
499
|
right: "auto",
|
|
446
|
-
width:
|
|
500
|
+
width: T.width,
|
|
447
501
|
zIndex: "var(--crk-z-floating)"
|
|
448
502
|
} : void 0, i = /* @__PURE__ */ s(
|
|
449
503
|
"div",
|
|
450
504
|
{
|
|
451
|
-
id:
|
|
452
|
-
ref:
|
|
453
|
-
className:
|
|
505
|
+
id: ae,
|
|
506
|
+
ref: J,
|
|
507
|
+
className: h(e.menu, o?.menu),
|
|
454
508
|
style: t,
|
|
455
509
|
role: "listbox",
|
|
456
510
|
"aria-multiselectable": "true",
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
511
|
+
onMouseDown: (a) => a.preventDefault(),
|
|
512
|
+
children: /* @__PURE__ */ R("div", { className: e.menuItems, ref: le, children: [
|
|
513
|
+
r.length === 0 && !n && /* @__PURE__ */ s("div", { className: e.noResults, children: "No results" }),
|
|
514
|
+
r.map((a, L) => {
|
|
515
|
+
const te = c.includes(a.value);
|
|
516
|
+
return /* @__PURE__ */ R(
|
|
462
517
|
"button",
|
|
463
518
|
{
|
|
464
|
-
id: `select-option-${
|
|
519
|
+
id: `select-option-${a.value}`,
|
|
465
520
|
type: "button",
|
|
466
521
|
role: "option",
|
|
467
|
-
"aria-selected":
|
|
468
|
-
className:
|
|
522
|
+
"aria-selected": te,
|
|
523
|
+
className: h(
|
|
469
524
|
e.item,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
525
|
+
a.disabled && e.itemDisabled,
|
|
526
|
+
te && e.itemSelected,
|
|
527
|
+
L === D && e.itemHighlighted,
|
|
528
|
+
o?.item
|
|
474
529
|
),
|
|
475
|
-
disabled:
|
|
476
|
-
onClick: () =>
|
|
477
|
-
onMouseEnter: () =>
|
|
530
|
+
disabled: a.disabled,
|
|
531
|
+
onClick: () => $(a.value),
|
|
532
|
+
onMouseEnter: () => C(L),
|
|
478
533
|
children: [
|
|
479
|
-
|
|
480
|
-
|
|
534
|
+
te && /* @__PURE__ */ s("span", { className: e.itemCheck, "aria-hidden": "true" }),
|
|
535
|
+
a.content ?? a.label
|
|
481
536
|
]
|
|
482
537
|
},
|
|
483
|
-
|
|
538
|
+
a.value
|
|
484
539
|
);
|
|
485
540
|
}),
|
|
486
|
-
|
|
541
|
+
n && /* @__PURE__ */ s(
|
|
487
542
|
"button",
|
|
488
543
|
{
|
|
489
544
|
type: "button",
|
|
490
545
|
role: "option",
|
|
491
546
|
"aria-selected": !1,
|
|
492
|
-
className:
|
|
547
|
+
className: h(
|
|
493
548
|
e.item,
|
|
494
|
-
|
|
495
|
-
|
|
549
|
+
D === Q && e.itemHighlighted,
|
|
550
|
+
o?.item
|
|
496
551
|
),
|
|
497
|
-
onClick:
|
|
498
|
-
onMouseEnter: () =>
|
|
499
|
-
children:
|
|
552
|
+
onClick: w,
|
|
553
|
+
onMouseEnter: () => C(Q),
|
|
554
|
+
children: re ? re(l) : /* @__PURE__ */ R(xe, { children: [
|
|
500
555
|
"Create “",
|
|
501
|
-
/* @__PURE__ */ s("strong", { children:
|
|
556
|
+
/* @__PURE__ */ s("strong", { children: l }),
|
|
502
557
|
"”"
|
|
503
558
|
] })
|
|
504
559
|
},
|
|
@@ -507,18 +562,18 @@ const ue = ne(
|
|
|
507
562
|
] })
|
|
508
563
|
}
|
|
509
564
|
);
|
|
510
|
-
return
|
|
565
|
+
return _ && typeof document < "u" ? me(i, document.body) : i;
|
|
511
566
|
})()
|
|
512
567
|
]
|
|
513
568
|
}
|
|
514
569
|
);
|
|
515
570
|
}
|
|
516
571
|
);
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
(
|
|
572
|
+
ye.displayName = "MultiSelect";
|
|
573
|
+
const Ne = ie(
|
|
574
|
+
(u, p) => u.multiple ? /* @__PURE__ */ s(ye, { ref: p, ...u }) : u.searchable ? /* @__PURE__ */ s(ge, { ref: p, ...u }) : /* @__PURE__ */ s(pe, { ref: p, ...u })
|
|
520
575
|
);
|
|
521
|
-
|
|
576
|
+
Ne.displayName = "Select";
|
|
522
577
|
export {
|
|
523
|
-
|
|
578
|
+
Ne as Select
|
|
524
579
|
};
|