@telegraph/combobox 0.0.38 → 0.0.40
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/CHANGELOG.md +12 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +207 -188
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/Combobox/Combobox.d.ts +9 -20
- package/dist/types/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/Combobox/Combobox.helpers.d.ts +1 -1
- package/dist/types/Combobox/Combobox.helpers.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import { jsx as i, jsxs as S, Fragment as F } from "react/jsx-runtime";
|
|
2
|
+
import { DismissableLayer as M } from "@radix-ui/react-dismissable-layer";
|
|
3
|
+
import { useControllableState as Y } from "@radix-ui/react-use-controllable-state";
|
|
4
|
+
import * as z from "@radix-ui/react-visually-hidden";
|
|
5
|
+
import { Button as E } from "@telegraph/button";
|
|
6
|
+
import { useComposedRefs as H } from "@telegraph/compose-refs";
|
|
7
|
+
import { RefToTgphRef as X } from "@telegraph/helpers";
|
|
8
|
+
import { Lucide as v, Icon as K } from "@telegraph/icon";
|
|
9
|
+
import { Input as q } from "@telegraph/input";
|
|
10
|
+
import { Stack as T, Box as B } from "@telegraph/layout";
|
|
10
11
|
import { Menu as O } from "@telegraph/menu";
|
|
11
12
|
import { Tag as D } from "@telegraph/tag";
|
|
12
|
-
import { Tooltip as
|
|
13
|
+
import { Tooltip as N } from "@telegraph/tooltip";
|
|
13
14
|
import { Text as P } from "@telegraph/typography";
|
|
14
15
|
import { motion as I, AnimatePresence as L } from "framer-motion";
|
|
15
|
-
import
|
|
16
|
-
const
|
|
16
|
+
import c from "react";
|
|
17
|
+
const U = {
|
|
17
18
|
0: "5",
|
|
18
19
|
1: "6",
|
|
19
20
|
2: "8",
|
|
20
21
|
3: "10"
|
|
21
|
-
}, R = (t) => Array.isArray(t),
|
|
22
|
+
}, R = (t) => Array.isArray(t), k = (t) => typeof t == "object" && !Array.isArray(t) || !t, J = ["ArrowDown", "PageUp", "Home"], W = ["ArrowUp", "PageDown", "End"], j = ["Enter", " "], x = c.createContext({
|
|
23
|
+
value: void 0,
|
|
22
24
|
onValueChange: () => {
|
|
23
25
|
},
|
|
24
26
|
contentId: "",
|
|
@@ -28,65 +30,71 @@ const q = {
|
|
|
28
30
|
},
|
|
29
31
|
onOpenToggle: () => {
|
|
30
32
|
},
|
|
31
|
-
clearable: !1
|
|
32
|
-
|
|
33
|
+
clearable: !1,
|
|
34
|
+
disabled: !1
|
|
35
|
+
}), Z = ({
|
|
33
36
|
modal: t = !0,
|
|
34
37
|
closeOnSelect: l = !0,
|
|
35
38
|
clearable: e = !1,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
disabled: u = !1,
|
|
40
|
+
open: s,
|
|
41
|
+
onOpenChange: r,
|
|
42
|
+
defaultOpen: n,
|
|
43
|
+
value: o,
|
|
44
|
+
onValueChange: a,
|
|
45
|
+
errored: b,
|
|
46
|
+
placeholder: d,
|
|
47
|
+
layout: y,
|
|
48
|
+
...p
|
|
45
49
|
}) => {
|
|
46
|
-
const
|
|
47
|
-
prop:
|
|
48
|
-
defaultProp:
|
|
49
|
-
onChange:
|
|
50
|
-
}),
|
|
51
|
-
A((
|
|
50
|
+
const g = c.useId(), f = c.useId(), m = c.useRef(null), h = c.useRef(null), C = c.useRef(null), [w, V] = c.useState(""), [Q = !1, A] = Y({
|
|
51
|
+
prop: s,
|
|
52
|
+
defaultProp: n,
|
|
53
|
+
onChange: r
|
|
54
|
+
}), $ = c.useCallback(() => {
|
|
55
|
+
A((G) => !G);
|
|
52
56
|
}, [A]);
|
|
53
|
-
return
|
|
54
|
-
Q ||
|
|
55
|
-
}, [Q]), /* @__PURE__ */
|
|
57
|
+
return c.useEffect(() => {
|
|
58
|
+
Q || V("");
|
|
59
|
+
}, [Q]), /* @__PURE__ */ i(
|
|
56
60
|
x.Provider,
|
|
57
61
|
{
|
|
58
62
|
value: {
|
|
59
|
-
contentId:
|
|
60
|
-
triggerId:
|
|
61
|
-
value:
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
contentId: g,
|
|
64
|
+
triggerId: f,
|
|
65
|
+
value: o,
|
|
66
|
+
// Need to cast this to avoid type errors
|
|
67
|
+
// because the type of onValueChange is not
|
|
68
|
+
// consistent with the value type
|
|
69
|
+
onValueChange: a,
|
|
70
|
+
placeholder: d,
|
|
64
71
|
open: Q,
|
|
65
72
|
setOpen: A,
|
|
66
|
-
onOpenToggle:
|
|
73
|
+
onOpenToggle: $,
|
|
67
74
|
closeOnSelect: l,
|
|
68
75
|
clearable: e,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
disabled: u,
|
|
77
|
+
searchQuery: w,
|
|
78
|
+
setSearchQuery: V,
|
|
79
|
+
triggerRef: m,
|
|
80
|
+
searchRef: h,
|
|
81
|
+
contentRef: C,
|
|
82
|
+
errored: b,
|
|
83
|
+
layout: y
|
|
76
84
|
},
|
|
77
|
-
children: /* @__PURE__ */
|
|
85
|
+
children: /* @__PURE__ */ i(
|
|
78
86
|
O.Root,
|
|
79
87
|
{
|
|
80
88
|
open: Q,
|
|
81
89
|
onOpenChange: A,
|
|
82
90
|
modal: t,
|
|
83
|
-
...
|
|
91
|
+
...p
|
|
84
92
|
}
|
|
85
93
|
)
|
|
86
94
|
}
|
|
87
95
|
);
|
|
88
|
-
},
|
|
89
|
-
const u =
|
|
96
|
+
}, ee = ({ label: t, value: l, ...e }) => {
|
|
97
|
+
const u = c.useContext(x);
|
|
90
98
|
return /* @__PURE__ */ S(
|
|
91
99
|
D.Root,
|
|
92
100
|
{
|
|
@@ -108,8 +116,8 @@ const q = {
|
|
|
108
116
|
},
|
|
109
117
|
...e,
|
|
110
118
|
children: [
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
/* @__PURE__ */
|
|
119
|
+
/* @__PURE__ */ i(D.Text, { children: t || l }),
|
|
120
|
+
/* @__PURE__ */ i(
|
|
113
121
|
D.Button,
|
|
114
122
|
{
|
|
115
123
|
icon: { icon: v.X, alt: `Remove ${l}` },
|
|
@@ -123,13 +131,13 @@ const q = {
|
|
|
123
131
|
]
|
|
124
132
|
}
|
|
125
133
|
);
|
|
126
|
-
},
|
|
134
|
+
}, te = () => {
|
|
127
135
|
var l, e;
|
|
128
|
-
const t =
|
|
136
|
+
const t = c.useContext(x);
|
|
129
137
|
if (t.value && R(t.value)) {
|
|
130
138
|
const u = t.layout || "truncate", s = t.value.length - 2, r = s.toString().split("");
|
|
131
|
-
return t.value.length === 0 ? /* @__PURE__ */
|
|
132
|
-
|
|
139
|
+
return t.value.length === 0 ? /* @__PURE__ */ i(E.Text, { color: "gray", children: t.placeholder }) : /* @__PURE__ */ S(
|
|
140
|
+
T,
|
|
133
141
|
{
|
|
134
142
|
gap: "1",
|
|
135
143
|
w: "full",
|
|
@@ -140,12 +148,12 @@ const q = {
|
|
|
140
148
|
flexGrow: 1
|
|
141
149
|
},
|
|
142
150
|
children: [
|
|
143
|
-
/* @__PURE__ */
|
|
151
|
+
/* @__PURE__ */ i(L, { initial: !1, mode: "popLayout", children: t.value.map((n, o) => {
|
|
144
152
|
if (n != null && n.value && (u === "truncate" && o <= 1 || u === "wrap"))
|
|
145
|
-
return /* @__PURE__ */
|
|
153
|
+
return /* @__PURE__ */ i(X, { children: /* @__PURE__ */ i(ee, { ...n }) }, n.value);
|
|
146
154
|
}) }),
|
|
147
|
-
/* @__PURE__ */
|
|
148
|
-
|
|
155
|
+
/* @__PURE__ */ i(L, { children: u === "truncate" && t.value.length > 2 && /* @__PURE__ */ i(
|
|
156
|
+
T,
|
|
149
157
|
{
|
|
150
158
|
as: I.div,
|
|
151
159
|
initial: { opacity: 0 },
|
|
@@ -164,7 +172,7 @@ const q = {
|
|
|
164
172
|
},
|
|
165
173
|
children: /* @__PURE__ */ S(P, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
|
|
166
174
|
"+",
|
|
167
|
-
/* @__PURE__ */
|
|
175
|
+
/* @__PURE__ */ i(L, { mode: "wait", initial: !1, children: r.map((n) => /* @__PURE__ */ i(
|
|
168
176
|
B,
|
|
169
177
|
{
|
|
170
178
|
as: I.span,
|
|
@@ -194,16 +202,16 @@ const q = {
|
|
|
194
202
|
}
|
|
195
203
|
);
|
|
196
204
|
}
|
|
197
|
-
return /* @__PURE__ */
|
|
198
|
-
},
|
|
199
|
-
const e =
|
|
205
|
+
return /* @__PURE__ */ i(E.Text, { color: t.value ? "default" : "gray", children: ((l = t == null ? void 0 : t.value) == null ? void 0 : l.label) || ((e = t == null ? void 0 : t.value) == null ? void 0 : e.value) || t.placeholder });
|
|
206
|
+
}, oe = ({ size: t = "2", ...l }) => {
|
|
207
|
+
const e = c.useContext(x), u = c.useCallback(() => {
|
|
200
208
|
var n, o, a;
|
|
201
|
-
return e.value ?
|
|
202
|
-
}, [e.value, e.placeholder]), s =
|
|
209
|
+
return e.value ? k(e.value) ? ((n = e.value) == null ? void 0 : n.label) || ((o = e.value) == null ? void 0 : o.value) || e.placeholder : ((a = e.value) == null ? void 0 : a.map((b) => b == null ? void 0 : b.label).join(", ")) || e.placeholder : e.placeholder;
|
|
210
|
+
}, [e.value, e.placeholder]), s = c.useMemo(() => {
|
|
203
211
|
var n;
|
|
204
212
|
if (R(e.value))
|
|
205
213
|
return e.clearable && ((n = e.value) == null ? void 0 : n.length) > 0;
|
|
206
|
-
if (
|
|
214
|
+
if (k(e.value))
|
|
207
215
|
return e.clearable && e.value;
|
|
208
216
|
}, [e.clearable, e.value]), r = () => {
|
|
209
217
|
var n, o;
|
|
@@ -211,13 +219,13 @@ const q = {
|
|
|
211
219
|
const a = e.onValueChange;
|
|
212
220
|
a == null || a([]);
|
|
213
221
|
}
|
|
214
|
-
if (
|
|
222
|
+
if (k(e.value)) {
|
|
215
223
|
const a = e.onValueChange;
|
|
216
224
|
a == null || a(void 0);
|
|
217
225
|
}
|
|
218
226
|
(o = (n = e.triggerRef) == null ? void 0 : n.current) == null || o.focus();
|
|
219
227
|
};
|
|
220
|
-
return /* @__PURE__ */
|
|
228
|
+
return /* @__PURE__ */ i(
|
|
221
229
|
O.Trigger,
|
|
222
230
|
{
|
|
223
231
|
...l,
|
|
@@ -231,7 +239,7 @@ const q = {
|
|
|
231
239
|
n.stopPropagation();
|
|
232
240
|
return;
|
|
233
241
|
}
|
|
234
|
-
if (
|
|
242
|
+
if (j.includes(n.key)) {
|
|
235
243
|
n.preventDefault();
|
|
236
244
|
return;
|
|
237
245
|
}
|
|
@@ -242,14 +250,14 @@ const q = {
|
|
|
242
250
|
},
|
|
243
251
|
tgphRef: e.triggerRef,
|
|
244
252
|
children: /* @__PURE__ */ S(
|
|
245
|
-
|
|
253
|
+
E.Root,
|
|
246
254
|
{
|
|
247
255
|
id: e.triggerId,
|
|
248
256
|
type: "button",
|
|
249
257
|
bg: "surface-1",
|
|
250
258
|
variant: "outline",
|
|
251
259
|
align: "center",
|
|
252
|
-
minH:
|
|
260
|
+
minH: U[t],
|
|
253
261
|
h: "full",
|
|
254
262
|
w: "full",
|
|
255
263
|
py: "1",
|
|
@@ -263,11 +271,12 @@ const q = {
|
|
|
263
271
|
"aria-haspopup": "listbox",
|
|
264
272
|
"data-tgph-combobox-trigger": !0,
|
|
265
273
|
"data-tgph-comobox-trigger-open": e.open,
|
|
274
|
+
disabled: e.disabled,
|
|
266
275
|
children: [
|
|
267
|
-
/* @__PURE__ */
|
|
268
|
-
/* @__PURE__ */ S(
|
|
269
|
-
s && /* @__PURE__ */
|
|
270
|
-
|
|
276
|
+
/* @__PURE__ */ i(te, {}),
|
|
277
|
+
/* @__PURE__ */ S(T, { align: "center", gap: "1", children: [
|
|
278
|
+
s && /* @__PURE__ */ i(N, { label: "Clear field", children: /* @__PURE__ */ i(
|
|
279
|
+
E,
|
|
271
280
|
{
|
|
272
281
|
type: "button",
|
|
273
282
|
icon: { icon: v.X, alt: "Clear field" },
|
|
@@ -288,8 +297,8 @@ const q = {
|
|
|
288
297
|
}
|
|
289
298
|
}
|
|
290
299
|
) }),
|
|
291
|
-
/* @__PURE__ */
|
|
292
|
-
|
|
300
|
+
/* @__PURE__ */ i(
|
|
301
|
+
E.Icon,
|
|
293
302
|
{
|
|
294
303
|
as: I.div,
|
|
295
304
|
icon: v.ChevronDown,
|
|
@@ -304,88 +313,98 @@ const q = {
|
|
|
304
313
|
)
|
|
305
314
|
}
|
|
306
315
|
);
|
|
307
|
-
},
|
|
316
|
+
}, ne = ({
|
|
308
317
|
tgphRef: t,
|
|
309
318
|
style: l,
|
|
310
319
|
children: e,
|
|
311
320
|
...u
|
|
312
321
|
}) => {
|
|
313
|
-
const s =
|
|
322
|
+
const s = c.useContext(x), r = c.useRef(!1), n = H(t, s.contentRef), o = c.useRef(null), [a, b] = c.useState(0), [d, y] = c.useState(!1), p = c.useCallback(
|
|
314
323
|
(g) => {
|
|
315
|
-
const
|
|
316
|
-
|
|
324
|
+
const f = g.getBoundingClientRect();
|
|
325
|
+
f && b(f.height), d || y(!0);
|
|
317
326
|
},
|
|
318
327
|
[d]
|
|
319
328
|
);
|
|
320
|
-
return
|
|
321
|
-
const g = new ResizeObserver((
|
|
322
|
-
for (const m of
|
|
323
|
-
const
|
|
324
|
-
p(
|
|
329
|
+
return c.useEffect(() => {
|
|
330
|
+
const g = new ResizeObserver((f) => {
|
|
331
|
+
for (const m of f) {
|
|
332
|
+
const h = m.target;
|
|
333
|
+
p(h);
|
|
325
334
|
}
|
|
326
335
|
});
|
|
327
336
|
return o.current && d && g.observe(o.current), () => g.disconnect();
|
|
328
|
-
}, [d, p]),
|
|
337
|
+
}, [d, p]), c.useEffect(() => {
|
|
329
338
|
d === !0 && s.open === !1 && y(!1);
|
|
330
|
-
}, [s.open, d]),
|
|
331
|
-
|
|
339
|
+
}, [s.open, d]), // We add radix's dismissable layer here so that we can swallow any escape key
|
|
340
|
+
// presses to prevent cases like a modal closing when we close the combobox
|
|
341
|
+
/* @__PURE__ */ i(
|
|
342
|
+
M,
|
|
332
343
|
{
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
initial: {
|
|
336
|
-
opacity: 0,
|
|
337
|
-
scale: 0.8,
|
|
338
|
-
height: "auto"
|
|
339
|
-
},
|
|
340
|
-
animate: {
|
|
341
|
-
opacity: 1,
|
|
342
|
-
scale: 1,
|
|
343
|
-
// Set height based on the internalContentRef so that
|
|
344
|
-
// we get smooth animations when the content changes
|
|
345
|
-
minHeight: a ? `${a}px` : "0"
|
|
344
|
+
onEscapeKeyDown: (g) => {
|
|
345
|
+
s.open && (g.preventDefault(), s.setOpen(!1));
|
|
346
346
|
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
347
|
+
children: /* @__PURE__ */ i(
|
|
348
|
+
O.Content,
|
|
349
|
+
{
|
|
350
|
+
as: I.div,
|
|
351
|
+
mt: "1",
|
|
352
|
+
initial: {
|
|
353
|
+
opacity: 0,
|
|
354
|
+
scale: 0.8,
|
|
355
|
+
height: "auto"
|
|
356
|
+
},
|
|
357
|
+
animate: {
|
|
358
|
+
opacity: 1,
|
|
359
|
+
scale: 1,
|
|
360
|
+
// Set height based on the internalContentRef so that
|
|
361
|
+
// we get smooth animations when the content changes
|
|
362
|
+
minHeight: a ? `${a}px` : "0"
|
|
363
|
+
},
|
|
364
|
+
exit: { opacity: 0, scale: 0 },
|
|
365
|
+
transition: { duration: 0.2, type: "spring", bounce: 0 },
|
|
366
|
+
onAnimationComplete: () => {
|
|
367
|
+
if (!d && o) {
|
|
368
|
+
const g = o.current;
|
|
369
|
+
p(g);
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
onCloseAutoFocus: (g) => {
|
|
373
|
+
var f, m;
|
|
374
|
+
r.current || (m = (f = s.triggerRef) == null ? void 0 : f.current) == null || m.focus(), r.current = !1, g.preventDefault();
|
|
375
|
+
},
|
|
376
|
+
onKeyDown: (g) => {
|
|
377
|
+
var m, h, C, w;
|
|
378
|
+
const f = (h = (m = s.contentRef) == null ? void 0 : m.current) == null ? void 0 : h.querySelectorAll(
|
|
379
|
+
"[data-tgph-combobox-option]"
|
|
380
|
+
);
|
|
381
|
+
document.activeElement === (f == null ? void 0 : f[0]) && W.includes(g.key) && ((w = (C = s.searchRef) == null ? void 0 : C.current) == null || w.focus());
|
|
382
|
+
},
|
|
383
|
+
bg: "surface-1",
|
|
384
|
+
style: {
|
|
385
|
+
width: "var(--tgph-comobobox-trigger-width)",
|
|
386
|
+
...l,
|
|
387
|
+
"--tgph-comobobox-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
388
|
+
"--tgph-combobox-content-available-width": "var(--radix-popper-available-width)",
|
|
389
|
+
"--tgph-combobox-content-available-height": "calc(var(--radix-popper-available-height) - var(--tgph-spacing-8))",
|
|
390
|
+
"--tgph-comobobox-trigger-width": "var(--radix-popper-anchor-width)",
|
|
391
|
+
"--tgph-combobox-trigger-height": "var(--radix-popper-anchor-height)"
|
|
392
|
+
},
|
|
393
|
+
...u,
|
|
394
|
+
tgphRef: n,
|
|
395
|
+
"data-tgph-combobox-content": !0,
|
|
396
|
+
"data-tgph-combobox-content-open": d,
|
|
397
|
+
role: void 0,
|
|
398
|
+
"aria-orientation": void 0,
|
|
399
|
+
children: /* @__PURE__ */ i(T, { direction: "column", gap: "1", tgphRef: o, children: e })
|
|
353
400
|
}
|
|
354
|
-
|
|
355
|
-
onCloseAutoFocus: (g) => {
|
|
356
|
-
var h, m;
|
|
357
|
-
r.current || (m = (h = s.triggerRef) == null ? void 0 : h.current) == null || m.focus(), r.current = !1, g.preventDefault();
|
|
358
|
-
},
|
|
359
|
-
onKeyDown: (g) => {
|
|
360
|
-
var m, f, C, w;
|
|
361
|
-
const h = (f = (m = s.contentRef) == null ? void 0 : m.current) == null ? void 0 : f.querySelectorAll(
|
|
362
|
-
"[data-tgph-combobox-option]"
|
|
363
|
-
);
|
|
364
|
-
document.activeElement === (h == null ? void 0 : h[0]) && U.includes(g.key) && ((w = (C = s.searchRef) == null ? void 0 : C.current) == null || w.focus()), g.key === "Escape" && s.setOpen(!1), g.stopPropagation();
|
|
365
|
-
},
|
|
366
|
-
bg: "surface-1",
|
|
367
|
-
style: {
|
|
368
|
-
width: "var(--tgph-comobobox-trigger-width)",
|
|
369
|
-
...l,
|
|
370
|
-
"--tgph-comobobox-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
371
|
-
"--tgph-combobox-content-available-width": "var(--radix-popper-available-width)",
|
|
372
|
-
"--tgph-combobox-content-available-height": "calc(var(--radix-popper-available-height) - var(--tgph-spacing-8))",
|
|
373
|
-
"--tgph-comobobox-trigger-width": "var(--radix-popper-anchor-width)",
|
|
374
|
-
"--tgph-combobox-trigger-height": "var(--radix-popper-anchor-height)"
|
|
375
|
-
},
|
|
376
|
-
...u,
|
|
377
|
-
tgphRef: n,
|
|
378
|
-
"data-tgph-combobox-content": !0,
|
|
379
|
-
"data-tgph-combobox-content-open": d,
|
|
380
|
-
role: void 0,
|
|
381
|
-
"aria-orientation": void 0,
|
|
382
|
-
children: /* @__PURE__ */ c(E, { direction: "column", gap: "1", tgphRef: o, children: e })
|
|
401
|
+
)
|
|
383
402
|
}
|
|
384
403
|
);
|
|
385
|
-
},
|
|
386
|
-
const l =
|
|
387
|
-
return /* @__PURE__ */
|
|
388
|
-
|
|
404
|
+
}, re = ({ ...t }) => {
|
|
405
|
+
const l = c.useContext(x);
|
|
406
|
+
return /* @__PURE__ */ i(
|
|
407
|
+
T,
|
|
389
408
|
{
|
|
390
409
|
id: l.contentId,
|
|
391
410
|
direction: "column",
|
|
@@ -399,31 +418,31 @@ const q = {
|
|
|
399
418
|
...t
|
|
400
419
|
}
|
|
401
420
|
);
|
|
402
|
-
},
|
|
421
|
+
}, _ = ({
|
|
403
422
|
value: t,
|
|
404
423
|
label: l,
|
|
405
424
|
selected: e,
|
|
406
425
|
onSelect: u,
|
|
407
426
|
...s
|
|
408
427
|
}) => {
|
|
409
|
-
const r =
|
|
410
|
-
var
|
|
428
|
+
const r = c.useContext(x), [n, o] = c.useState(!1), a = r.value, b = (R(a), !r.searchQuery || t.toLowerCase().includes(r.searchQuery.toLowerCase())), d = R(a) ? a.some((p) => (p == null ? void 0 : p.value) === t) : (a == null ? void 0 : a.value) === t, y = (p) => {
|
|
429
|
+
var f, m;
|
|
411
430
|
const g = p;
|
|
412
|
-
if (!(g.key && !
|
|
431
|
+
if (!(g.key && !j.includes(g.key))) {
|
|
413
432
|
if (p.stopPropagation(), p.preventDefault(), r.closeOnSelect === !0 && r.setOpen(!1), u)
|
|
414
433
|
return u(p);
|
|
415
|
-
if (
|
|
416
|
-
const
|
|
417
|
-
|
|
434
|
+
if (k(a)) {
|
|
435
|
+
const h = r.onValueChange;
|
|
436
|
+
h == null || h({ value: t, label: l });
|
|
418
437
|
} else if (R(a)) {
|
|
419
|
-
const
|
|
420
|
-
|
|
438
|
+
const h = r.onValueChange, C = d ? a.filter((w) => (w == null ? void 0 : w.value) !== t) : [...a, { value: t, label: l }];
|
|
439
|
+
h == null || h(C);
|
|
421
440
|
}
|
|
422
|
-
(m = (
|
|
441
|
+
(m = (f = r.triggerRef) == null ? void 0 : f.current) == null || m.focus();
|
|
423
442
|
}
|
|
424
443
|
};
|
|
425
444
|
if (b)
|
|
426
|
-
return /* @__PURE__ */
|
|
445
|
+
return /* @__PURE__ */ i(
|
|
427
446
|
O.Button,
|
|
428
447
|
{
|
|
429
448
|
type: "button",
|
|
@@ -442,7 +461,7 @@ const q = {
|
|
|
442
461
|
children: l || t
|
|
443
462
|
}
|
|
444
463
|
);
|
|
445
|
-
},
|
|
464
|
+
}, ae = ({
|
|
446
465
|
label: t = "Search",
|
|
447
466
|
placeholder: l = "Search",
|
|
448
467
|
tgphRef: e,
|
|
@@ -451,21 +470,21 @@ const q = {
|
|
|
451
470
|
...r
|
|
452
471
|
}) => {
|
|
453
472
|
var y;
|
|
454
|
-
const n =
|
|
455
|
-
return
|
|
456
|
-
var
|
|
473
|
+
const n = c.useId(), o = c.useContext(x), a = H(e, o.searchRef), b = u ?? o.searchQuery, d = s ?? o.setSearchQuery;
|
|
474
|
+
return c.useEffect(() => {
|
|
475
|
+
var f;
|
|
457
476
|
const p = (m) => {
|
|
458
|
-
var
|
|
459
|
-
|
|
460
|
-
}, g = (
|
|
477
|
+
var h, C;
|
|
478
|
+
J.includes(m.key) && ((C = (h = o.contentRef) == null ? void 0 : h.current) == null || C.focus({ preventScroll: !0 })), m.key === "Escape" && o.setOpen(!1), m.stopPropagation();
|
|
479
|
+
}, g = (f = o.searchRef) == null ? void 0 : f.current;
|
|
461
480
|
if (g)
|
|
462
481
|
return g.addEventListener("keydown", p), () => {
|
|
463
482
|
g.removeEventListener("keydown", p);
|
|
464
483
|
};
|
|
465
484
|
}, [o]), /* @__PURE__ */ S(B, { borderBottom: "px", px: "1", pb: "1", children: [
|
|
466
|
-
/* @__PURE__ */
|
|
467
|
-
/* @__PURE__ */
|
|
468
|
-
|
|
485
|
+
/* @__PURE__ */ i(z.Root, { children: /* @__PURE__ */ i(P, { as: "label", htmlFor: n, children: t }) }),
|
|
486
|
+
/* @__PURE__ */ i(
|
|
487
|
+
q,
|
|
469
488
|
{
|
|
470
489
|
id: n,
|
|
471
490
|
variant: "ghost",
|
|
@@ -474,9 +493,9 @@ const q = {
|
|
|
474
493
|
onChange: (p) => {
|
|
475
494
|
d(p.target.value);
|
|
476
495
|
},
|
|
477
|
-
LeadingComponent: /* @__PURE__ */
|
|
478
|
-
TrailingComponent: o != null && o.searchQuery && ((y = o == null ? void 0 : o.searchQuery) == null ? void 0 : y.length) > 0 ? /* @__PURE__ */
|
|
479
|
-
|
|
496
|
+
LeadingComponent: /* @__PURE__ */ i(K, { icon: v.Search, alt: "Search Icon" }),
|
|
497
|
+
TrailingComponent: o != null && o.searchQuery && ((y = o == null ? void 0 : o.searchQuery) == null ? void 0 : y.length) > 0 ? /* @__PURE__ */ i(
|
|
498
|
+
E,
|
|
480
499
|
{
|
|
481
500
|
as: I.button,
|
|
482
501
|
initial: { opacity: 0 },
|
|
@@ -499,14 +518,14 @@ const q = {
|
|
|
499
518
|
}
|
|
500
519
|
)
|
|
501
520
|
] });
|
|
502
|
-
},
|
|
521
|
+
}, ie = ({
|
|
503
522
|
icon: t = { icon: v.Search, alt: "Search Icon" },
|
|
504
523
|
message: l = "No results found",
|
|
505
524
|
children: e,
|
|
506
525
|
...u
|
|
507
526
|
}) => {
|
|
508
|
-
const s =
|
|
509
|
-
if (
|
|
527
|
+
const s = c.useContext(x), [r, n] = c.useState(!1);
|
|
528
|
+
if (c.useEffect(() => {
|
|
510
529
|
var a, b;
|
|
511
530
|
const o = (b = (a = s.contentRef) == null ? void 0 : a.current) == null ? void 0 : b.querySelectorAll(
|
|
512
531
|
"[data-tgph-combobox-option]"
|
|
@@ -514,7 +533,7 @@ const q = {
|
|
|
514
533
|
(o == null ? void 0 : o.length) === 0 ? n(!0) : n(!1);
|
|
515
534
|
}, [s.searchQuery, s.contentRef, e]), r)
|
|
516
535
|
return /* @__PURE__ */ S(
|
|
517
|
-
|
|
536
|
+
T,
|
|
518
537
|
{
|
|
519
538
|
as: I.div,
|
|
520
539
|
initial: { opacity: 0, scale: 0.8 },
|
|
@@ -528,25 +547,25 @@ const q = {
|
|
|
528
547
|
"data-tgph-combobox-empty": !0,
|
|
529
548
|
...u,
|
|
530
549
|
children: [
|
|
531
|
-
t === null ? /* @__PURE__ */
|
|
532
|
-
l === null ? /* @__PURE__ */
|
|
550
|
+
t === null ? /* @__PURE__ */ i(F, {}) : /* @__PURE__ */ i(K, { ...t }),
|
|
551
|
+
l === null ? /* @__PURE__ */ i(F, {}) : /* @__PURE__ */ i(P, { as: "span", children: l })
|
|
533
552
|
]
|
|
534
553
|
}
|
|
535
554
|
);
|
|
536
|
-
},
|
|
555
|
+
}, ce = ({
|
|
537
556
|
leadingText: t = "Create",
|
|
538
557
|
values: l,
|
|
539
558
|
onCreate: e,
|
|
540
559
|
selected: u = null,
|
|
541
560
|
...s
|
|
542
561
|
}) => {
|
|
543
|
-
const r =
|
|
562
|
+
const r = c.useContext(x), n = c.useCallback(
|
|
544
563
|
(o) => !l || (l == null ? void 0 : l.length) === 0 ? !1 : l.some((a) => (a == null ? void 0 : a.value) === o),
|
|
545
564
|
[l]
|
|
546
565
|
);
|
|
547
566
|
if (r.searchQuery && !n(r.searchQuery))
|
|
548
|
-
return /* @__PURE__ */
|
|
549
|
-
|
|
567
|
+
return /* @__PURE__ */ i(
|
|
568
|
+
_,
|
|
550
569
|
{
|
|
551
570
|
leadingIcon: { icon: v.Plus, "aria-hidden": !0 },
|
|
552
571
|
mx: "1",
|
|
@@ -555,23 +574,23 @@ const q = {
|
|
|
555
574
|
selected: u,
|
|
556
575
|
onSelect: () => {
|
|
557
576
|
var o;
|
|
558
|
-
e && r.value && r.searchQuery && (
|
|
577
|
+
e && r.value && r.searchQuery && (k(r.value) && e({ value: r.searchQuery }), R(r.value) && e({ value: r.searchQuery }), (o = r.setSearchQuery) == null || o.call(r, ""));
|
|
559
578
|
},
|
|
560
579
|
...s
|
|
561
580
|
}
|
|
562
581
|
);
|
|
563
|
-
},
|
|
564
|
-
Object.assign(
|
|
565
|
-
Root:
|
|
566
|
-
Trigger:
|
|
567
|
-
Content:
|
|
568
|
-
Options:
|
|
569
|
-
Option:
|
|
570
|
-
Search:
|
|
571
|
-
Empty:
|
|
572
|
-
Create:
|
|
582
|
+
}, le = {};
|
|
583
|
+
Object.assign(le, {
|
|
584
|
+
Root: Z,
|
|
585
|
+
Trigger: oe,
|
|
586
|
+
Content: ne,
|
|
587
|
+
Options: re,
|
|
588
|
+
Option: _,
|
|
589
|
+
Search: ae,
|
|
590
|
+
Empty: ie,
|
|
591
|
+
Create: ce
|
|
573
592
|
});
|
|
574
593
|
export {
|
|
575
|
-
|
|
594
|
+
le as Combobox
|
|
576
595
|
};
|
|
577
596
|
//# sourceMappingURL=index.mjs.map
|