@telegraph/combobox 0.0.59 → 0.0.60
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 +8 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +187 -177
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/Combobox/Combobox.helpers.d.ts +3 -2
- package/dist/types/Combobox/Combobox.helpers.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { DismissableLayer as
|
|
3
|
-
import * as
|
|
4
|
-
import { useControllableState as
|
|
5
|
-
import * as
|
|
1
|
+
import { jsx as p, jsxs as S, Fragment as K } from "react/jsx-runtime";
|
|
2
|
+
import { DismissableLayer as U } from "@radix-ui/react-dismissable-layer";
|
|
3
|
+
import * as W from "@radix-ui/react-portal";
|
|
4
|
+
import { useControllableState as J } from "@radix-ui/react-use-controllable-state";
|
|
5
|
+
import * as Z from "@radix-ui/react-visually-hidden";
|
|
6
6
|
import { Button as E } from "@telegraph/button";
|
|
7
7
|
import { useComposedRefs as j } from "@telegraph/compose-refs";
|
|
8
|
-
import { RefToTgphRef as
|
|
9
|
-
import { Lucide as R, Icon as
|
|
10
|
-
import { Input as
|
|
11
|
-
import { Stack as I, Box as
|
|
8
|
+
import { RefToTgphRef as ee } from "@telegraph/helpers";
|
|
9
|
+
import { Lucide as R, Icon as N } from "@telegraph/icon";
|
|
10
|
+
import { Input as te } from "@telegraph/input";
|
|
11
|
+
import { Stack as I, Box as _ } from "@telegraph/layout";
|
|
12
12
|
import { Menu as Q } from "@telegraph/menu";
|
|
13
|
-
import { motion as
|
|
13
|
+
import { motion as B, AnimatePresence as P } from "@telegraph/motion";
|
|
14
14
|
import { Tag as L } from "@telegraph/tag";
|
|
15
|
-
import { Tooltip as
|
|
15
|
+
import { Tooltip as oe } from "@telegraph/tooltip";
|
|
16
16
|
import { Text as M } from "@telegraph/typography";
|
|
17
|
-
import
|
|
18
|
-
const
|
|
17
|
+
import i from "react";
|
|
18
|
+
const ne = {
|
|
19
19
|
0: "5",
|
|
20
20
|
1: "6",
|
|
21
21
|
2: "8",
|
|
22
22
|
3: "10"
|
|
23
|
-
}, k = (t) => Array.isArray(t), T = (t) => typeof t == "object" && !Array.isArray(t) || typeof t == "string" || !t,
|
|
24
|
-
const a = (r,
|
|
25
|
-
|
|
26
|
-
}),
|
|
23
|
+
}, k = (t) => Array.isArray(t), T = (t) => typeof t == "object" && !Array.isArray(t) || typeof t == "string" || !t, re = (t) => {
|
|
24
|
+
const a = (r, c = []) => (i.Children.toArray(r).forEach((n) => {
|
|
25
|
+
i.isValidElement(n) && (n.props.value ? c.push(n) : n.props.children && a(n.props.children, c));
|
|
26
|
+
}), c);
|
|
27
27
|
return a(t).map((r) => {
|
|
28
28
|
var o;
|
|
29
|
-
const
|
|
29
|
+
const c = r;
|
|
30
30
|
return {
|
|
31
|
-
value:
|
|
32
|
-
label: ((o =
|
|
31
|
+
value: c.props.value,
|
|
32
|
+
label: ((o = c.props) == null ? void 0 : o.label) || c.props.children || c.props.value
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
}, C = (t, a) => {
|
|
@@ -37,16 +37,26 @@ const oe = {
|
|
|
37
37
|
return a === !0 ? t == null ? void 0 : t.value : t;
|
|
38
38
|
}, F = (t, a, e) => {
|
|
39
39
|
if (!t || !a || a.length === 0) return;
|
|
40
|
-
const
|
|
40
|
+
const l = a.find(
|
|
41
41
|
(r) => r.value === C(t, e)
|
|
42
42
|
);
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
45
|
-
},
|
|
46
|
-
|
|
43
|
+
if (l)
|
|
44
|
+
return l;
|
|
45
|
+
}, ae = ({
|
|
46
|
+
children: t,
|
|
47
47
|
value: a,
|
|
48
48
|
searchQuery: e
|
|
49
|
-
}) =>
|
|
49
|
+
}) => {
|
|
50
|
+
const l = $(t);
|
|
51
|
+
return (a == null ? void 0 : a.toLowerCase().includes(e.toLowerCase())) || l.some(
|
|
52
|
+
(r) => r.toLowerCase().includes(e.toLowerCase())
|
|
53
|
+
);
|
|
54
|
+
}, $ = (t) => {
|
|
55
|
+
const a = i.Children.toArray(t), e = [];
|
|
56
|
+
return a.forEach((l) => {
|
|
57
|
+
typeof l == "string" && e.push(l), i.isValidElement(l) && l.props.children && e.push(...$(l.props.children));
|
|
58
|
+
}), e;
|
|
59
|
+
}, ie = ["ArrowDown", "PageUp", "Home"], ce = ["ArrowUp", "PageDown", "End"], z = ["Enter", " "], x = i.createContext({
|
|
50
60
|
value: void 0,
|
|
51
61
|
onValueChange: () => {
|
|
52
62
|
},
|
|
@@ -61,13 +71,13 @@ const oe = {
|
|
|
61
71
|
disabled: !1,
|
|
62
72
|
options: [],
|
|
63
73
|
legacyBehavior: !1
|
|
64
|
-
}),
|
|
74
|
+
}), se = ({
|
|
65
75
|
modal: t = !0,
|
|
66
76
|
closeOnSelect: a = !0,
|
|
67
77
|
clearable: e = !1,
|
|
68
|
-
disabled:
|
|
78
|
+
disabled: l = !1,
|
|
69
79
|
legacyBehavior: r = !1,
|
|
70
|
-
open:
|
|
80
|
+
open: c,
|
|
71
81
|
onOpenChange: o,
|
|
72
82
|
defaultOpen: n,
|
|
73
83
|
value: s,
|
|
@@ -75,19 +85,19 @@ const oe = {
|
|
|
75
85
|
errored: y,
|
|
76
86
|
placeholder: v,
|
|
77
87
|
layout: d,
|
|
78
|
-
children:
|
|
88
|
+
children: u,
|
|
79
89
|
...g
|
|
80
90
|
}) => {
|
|
81
|
-
const m =
|
|
82
|
-
prop:
|
|
91
|
+
const m = i.useId(), b = i.useId(), h = i.useRef(null), w = i.useRef(null), V = i.useRef(null), D = i.useMemo(() => re(u), [u]), [Y, H] = i.useState(""), [O = !1, A] = J({
|
|
92
|
+
prop: c,
|
|
83
93
|
defaultProp: n,
|
|
84
94
|
onChange: o
|
|
85
|
-
}),
|
|
86
|
-
|
|
87
|
-
}, [
|
|
88
|
-
return
|
|
95
|
+
}), X = i.useCallback(() => {
|
|
96
|
+
A((q) => !q);
|
|
97
|
+
}, [A]);
|
|
98
|
+
return i.useEffect(() => {
|
|
89
99
|
O || H("");
|
|
90
|
-
}, [O]), /* @__PURE__ */
|
|
100
|
+
}, [O]), /* @__PURE__ */ p(
|
|
91
101
|
x.Provider,
|
|
92
102
|
{
|
|
93
103
|
value: {
|
|
@@ -100,35 +110,35 @@ const oe = {
|
|
|
100
110
|
onValueChange: f,
|
|
101
111
|
placeholder: v,
|
|
102
112
|
open: O,
|
|
103
|
-
setOpen:
|
|
104
|
-
onOpenToggle:
|
|
113
|
+
setOpen: A,
|
|
114
|
+
onOpenToggle: X,
|
|
105
115
|
closeOnSelect: a,
|
|
106
116
|
clearable: e,
|
|
107
|
-
disabled:
|
|
117
|
+
disabled: l,
|
|
108
118
|
searchQuery: Y,
|
|
109
119
|
setSearchQuery: H,
|
|
110
120
|
triggerRef: h,
|
|
111
121
|
searchRef: w,
|
|
112
|
-
contentRef:
|
|
122
|
+
contentRef: V,
|
|
113
123
|
errored: y,
|
|
114
124
|
layout: d,
|
|
115
|
-
options:
|
|
125
|
+
options: D,
|
|
116
126
|
legacyBehavior: r
|
|
117
127
|
},
|
|
118
|
-
children: /* @__PURE__ */
|
|
128
|
+
children: /* @__PURE__ */ p(
|
|
119
129
|
Q.Root,
|
|
120
130
|
{
|
|
121
131
|
open: O,
|
|
122
|
-
onOpenChange:
|
|
132
|
+
onOpenChange: A,
|
|
123
133
|
modal: t,
|
|
124
134
|
...g,
|
|
125
|
-
children:
|
|
135
|
+
children: u
|
|
126
136
|
}
|
|
127
137
|
)
|
|
128
138
|
}
|
|
129
139
|
);
|
|
130
|
-
},
|
|
131
|
-
const e =
|
|
140
|
+
}, le = ({ value: t, ...a }) => {
|
|
141
|
+
const e = i.useContext(x), l = i.useMemo(() => {
|
|
132
142
|
const r = e.options.find((n) => n.value === t);
|
|
133
143
|
if (r) return r.label || r.value;
|
|
134
144
|
if (!e.value) return;
|
|
@@ -141,7 +151,7 @@ const oe = {
|
|
|
141
151
|
return /* @__PURE__ */ S(
|
|
142
152
|
L.Root,
|
|
143
153
|
{
|
|
144
|
-
as:
|
|
154
|
+
as: B.span,
|
|
145
155
|
initializeWithAnimation: !1,
|
|
146
156
|
initial: { opacity: 0, scale: 0.5 },
|
|
147
157
|
animate: { opacity: 1, scale: 1 },
|
|
@@ -152,27 +162,27 @@ const oe = {
|
|
|
152
162
|
layout: "position",
|
|
153
163
|
...a,
|
|
154
164
|
children: [
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
/* @__PURE__ */
|
|
165
|
+
/* @__PURE__ */ p(L.Text, { children: l }),
|
|
166
|
+
/* @__PURE__ */ p(
|
|
157
167
|
L.Button,
|
|
158
168
|
{
|
|
159
169
|
icon: { icon: R.X, alt: `Remove ${t}` },
|
|
160
170
|
onClick: (r) => {
|
|
161
171
|
if (!e.onValueChange) return;
|
|
162
|
-
const
|
|
163
|
-
|
|
172
|
+
const c = e.onValueChange, n = e.value.filter((s) => C(s, e.legacyBehavior) !== t);
|
|
173
|
+
c == null || c(n), r.stopPropagation(), r.preventDefault();
|
|
164
174
|
}
|
|
165
175
|
}
|
|
166
176
|
)
|
|
167
177
|
]
|
|
168
178
|
}
|
|
169
179
|
);
|
|
170
|
-
},
|
|
180
|
+
}, ue = () => {
|
|
171
181
|
var a;
|
|
172
|
-
const t =
|
|
182
|
+
const t = i.useContext(x);
|
|
173
183
|
if (t.value && k(t.value)) {
|
|
174
|
-
const e = t.layout || "truncate",
|
|
175
|
-
return t.value.length === 0 ? /* @__PURE__ */
|
|
184
|
+
const e = t.layout || "truncate", l = t.value.length - 2, r = l.toString().split("");
|
|
185
|
+
return t.value.length === 0 ? /* @__PURE__ */ p(E.Text, { color: "gray", children: t.placeholder }) : /* @__PURE__ */ S(
|
|
176
186
|
I,
|
|
177
187
|
{
|
|
178
188
|
gap: "1",
|
|
@@ -184,21 +194,21 @@ const oe = {
|
|
|
184
194
|
flexGrow: 1
|
|
185
195
|
},
|
|
186
196
|
children: [
|
|
187
|
-
/* @__PURE__ */
|
|
197
|
+
/* @__PURE__ */ p(
|
|
188
198
|
P,
|
|
189
199
|
{
|
|
190
|
-
presenceMap: t.value.map((
|
|
191
|
-
"tgph-motion-key": C(
|
|
200
|
+
presenceMap: t.value.map((c) => ({
|
|
201
|
+
"tgph-motion-key": C(c, t.legacyBehavior) || "",
|
|
192
202
|
value: !0
|
|
193
203
|
})),
|
|
194
|
-
children: t.value.map((
|
|
195
|
-
const n = C(
|
|
204
|
+
children: t.value.map((c, o) => {
|
|
205
|
+
const n = C(c, t.legacyBehavior);
|
|
196
206
|
if (n && (e === "truncate" && o <= 1 || e === "wrap"))
|
|
197
|
-
return /* @__PURE__ */
|
|
207
|
+
return /* @__PURE__ */ p(ee, { children: /* @__PURE__ */ p(le, { value: n }) }, n);
|
|
198
208
|
})
|
|
199
209
|
}
|
|
200
210
|
),
|
|
201
|
-
/* @__PURE__ */
|
|
211
|
+
/* @__PURE__ */ p(
|
|
202
212
|
P,
|
|
203
213
|
{
|
|
204
214
|
presenceMap: [
|
|
@@ -207,10 +217,10 @@ const oe = {
|
|
|
207
217
|
value: !0
|
|
208
218
|
}
|
|
209
219
|
],
|
|
210
|
-
children: e === "truncate" && t.value.length > 2 && /* @__PURE__ */
|
|
220
|
+
children: e === "truncate" && t.value.length > 2 && /* @__PURE__ */ p(
|
|
211
221
|
I,
|
|
212
222
|
{
|
|
213
|
-
as:
|
|
223
|
+
as: B.div,
|
|
214
224
|
initial: { opacity: 0 },
|
|
215
225
|
animate: { opacity: 1 },
|
|
216
226
|
exit: { opacity: 0 },
|
|
@@ -219,7 +229,7 @@ const oe = {
|
|
|
219
229
|
pr: "1",
|
|
220
230
|
pl: "8",
|
|
221
231
|
align: "center",
|
|
222
|
-
"aria-label": `${
|
|
232
|
+
"aria-label": `${l} more selected`,
|
|
223
233
|
position: "absolute",
|
|
224
234
|
right: "0",
|
|
225
235
|
style: {
|
|
@@ -230,25 +240,25 @@ const oe = {
|
|
|
230
240
|
/* @__PURE__ */ S(
|
|
231
241
|
P,
|
|
232
242
|
{
|
|
233
|
-
presenceMap: r.map((
|
|
234
|
-
"tgph-motion-key":
|
|
243
|
+
presenceMap: r.map((c) => ({
|
|
244
|
+
"tgph-motion-key": c,
|
|
235
245
|
value: !0
|
|
236
246
|
})),
|
|
237
247
|
children: [
|
|
238
|
-
r.map((
|
|
239
|
-
|
|
248
|
+
r.map((c) => /* @__PURE__ */ p(
|
|
249
|
+
_,
|
|
240
250
|
{
|
|
241
|
-
as:
|
|
251
|
+
as: B.span,
|
|
242
252
|
initial: { opacity: 0 },
|
|
243
253
|
animate: { opacity: 1 },
|
|
244
254
|
exit: { opacity: 0 },
|
|
245
255
|
transition: { duration: 100, type: "spring" },
|
|
246
256
|
w: "2",
|
|
247
257
|
display: "inline-block",
|
|
248
|
-
"tgph-motion-key":
|
|
249
|
-
children:
|
|
258
|
+
"tgph-motion-key": c,
|
|
259
|
+
children: c
|
|
250
260
|
},
|
|
251
|
-
|
|
261
|
+
c
|
|
252
262
|
)),
|
|
253
263
|
" "
|
|
254
264
|
]
|
|
@@ -269,19 +279,19 @@ const oe = {
|
|
|
269
279
|
t.value,
|
|
270
280
|
t.options,
|
|
271
281
|
t.legacyBehavior
|
|
272
|
-
),
|
|
273
|
-
return /* @__PURE__ */
|
|
282
|
+
), l = (e == null ? void 0 : e.label) || (e == null ? void 0 : e.value) || t.placeholder, r = t.legacyBehavior && ((a = t == null ? void 0 : t.value) == null ? void 0 : a.label);
|
|
283
|
+
return /* @__PURE__ */ p(
|
|
274
284
|
E.Text,
|
|
275
285
|
{
|
|
276
286
|
color: t.value ? "default" : "gray",
|
|
277
287
|
textOverflow: "ellipsis",
|
|
278
288
|
overflow: "hidden",
|
|
279
|
-
children: r ||
|
|
289
|
+
children: r || l
|
|
280
290
|
}
|
|
281
291
|
);
|
|
282
292
|
}
|
|
283
|
-
},
|
|
284
|
-
const e =
|
|
293
|
+
}, pe = ({ size: t = "2", ...a }) => {
|
|
294
|
+
const e = i.useContext(x), l = i.useCallback(() => {
|
|
285
295
|
var o;
|
|
286
296
|
if (!e.value) return e.placeholder;
|
|
287
297
|
if (T(e.value)) {
|
|
@@ -306,13 +316,13 @@ const oe = {
|
|
|
306
316
|
e.placeholder,
|
|
307
317
|
e.options,
|
|
308
318
|
e.legacyBehavior
|
|
309
|
-
]), r =
|
|
319
|
+
]), r = i.useMemo(() => {
|
|
310
320
|
var o;
|
|
311
321
|
if (T(e.value))
|
|
312
322
|
return e.clearable && e.value;
|
|
313
323
|
if (k(e.value))
|
|
314
324
|
return e.clearable && ((o = e.value) == null ? void 0 : o.length) > 0;
|
|
315
|
-
}, [e.clearable, e.value]),
|
|
325
|
+
}, [e.clearable, e.value]), c = () => {
|
|
316
326
|
var o, n;
|
|
317
327
|
if (k(e.value)) {
|
|
318
328
|
const s = e.onValueChange;
|
|
@@ -324,7 +334,7 @@ const oe = {
|
|
|
324
334
|
}
|
|
325
335
|
(n = (o = e.triggerRef) == null ? void 0 : o.current) == null || n.focus();
|
|
326
336
|
};
|
|
327
|
-
return /* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ p(
|
|
328
338
|
Q.Trigger,
|
|
329
339
|
{
|
|
330
340
|
...a,
|
|
@@ -356,7 +366,7 @@ const oe = {
|
|
|
356
366
|
bg: "surface-1",
|
|
357
367
|
variant: "outline",
|
|
358
368
|
align: "center",
|
|
359
|
-
minH:
|
|
369
|
+
minH: ne[t],
|
|
360
370
|
h: "full",
|
|
361
371
|
w: "full",
|
|
362
372
|
py: "1",
|
|
@@ -364,7 +374,7 @@ const oe = {
|
|
|
364
374
|
color: e.errored ? "red" : "gray",
|
|
365
375
|
justify: "space-between",
|
|
366
376
|
role: "combobox",
|
|
367
|
-
"aria-label":
|
|
377
|
+
"aria-label": l(),
|
|
368
378
|
"aria-controls": e.contentId,
|
|
369
379
|
"aria-expanded": e.open,
|
|
370
380
|
"aria-haspopup": "listbox",
|
|
@@ -372,9 +382,9 @@ const oe = {
|
|
|
372
382
|
"data-tgph-combobox-trigger-open": e.open,
|
|
373
383
|
disabled: e.disabled,
|
|
374
384
|
children: [
|
|
375
|
-
/* @__PURE__ */
|
|
385
|
+
/* @__PURE__ */ p(ue, {}),
|
|
376
386
|
/* @__PURE__ */ S(I, { align: "center", gap: "1", children: [
|
|
377
|
-
r && /* @__PURE__ */
|
|
387
|
+
r && /* @__PURE__ */ p(oe, { label: "Clear field", children: /* @__PURE__ */ p(
|
|
378
388
|
E,
|
|
379
389
|
{
|
|
380
390
|
type: "button",
|
|
@@ -382,10 +392,10 @@ const oe = {
|
|
|
382
392
|
size: "1",
|
|
383
393
|
variant: "ghost",
|
|
384
394
|
onClick: (o) => {
|
|
385
|
-
e.value && (o.stopPropagation(),
|
|
395
|
+
e.value && (o.stopPropagation(), c());
|
|
386
396
|
},
|
|
387
397
|
onKeyDown: (o) => {
|
|
388
|
-
(o.key === "Enter" || o.key === " ") && (o.stopPropagation(),
|
|
398
|
+
(o.key === "Enter" || o.key === " ") && (o.stopPropagation(), c());
|
|
389
399
|
},
|
|
390
400
|
"data-tgph-combobox-clear": !0,
|
|
391
401
|
style: {
|
|
@@ -396,10 +406,10 @@ const oe = {
|
|
|
396
406
|
}
|
|
397
407
|
}
|
|
398
408
|
) }),
|
|
399
|
-
/* @__PURE__ */
|
|
409
|
+
/* @__PURE__ */ p(
|
|
400
410
|
E.Icon,
|
|
401
411
|
{
|
|
402
|
-
as:
|
|
412
|
+
as: B.span,
|
|
403
413
|
animate: { rotate: e.open ? 180 : 0 },
|
|
404
414
|
transition: { duration: 150, type: "spring" },
|
|
405
415
|
icon: R.ChevronDown,
|
|
@@ -412,48 +422,48 @@ const oe = {
|
|
|
412
422
|
)
|
|
413
423
|
}
|
|
414
424
|
);
|
|
415
|
-
},
|
|
425
|
+
}, fe = ({
|
|
416
426
|
style: t,
|
|
417
427
|
children: a,
|
|
418
428
|
tgphRef: e,
|
|
419
|
-
...
|
|
429
|
+
...l
|
|
420
430
|
}) => {
|
|
421
|
-
const r =
|
|
422
|
-
(
|
|
423
|
-
const g =
|
|
431
|
+
const r = i.useContext(x), c = i.useRef(!1), o = j(e, r.contentRef), n = i.useRef(null), [s, f] = i.useState(0), [y, v] = i.useState(!1), d = i.useCallback(
|
|
432
|
+
(u) => {
|
|
433
|
+
const g = u == null ? void 0 : u.getBoundingClientRect();
|
|
424
434
|
g && f(g.height), y || v(!0);
|
|
425
435
|
},
|
|
426
436
|
[y]
|
|
427
437
|
);
|
|
428
|
-
return
|
|
429
|
-
const
|
|
438
|
+
return i.useEffect(() => {
|
|
439
|
+
const u = new ResizeObserver((g) => {
|
|
430
440
|
for (const m of g) {
|
|
431
441
|
const b = m.target;
|
|
432
442
|
d(b);
|
|
433
443
|
}
|
|
434
444
|
});
|
|
435
|
-
return n.current && y &&
|
|
436
|
-
}, [y, d]),
|
|
445
|
+
return n.current && y && u.observe(n.current), () => u.disconnect();
|
|
446
|
+
}, [y, d]), i.useEffect(() => {
|
|
437
447
|
y === !0 && r.open === !1 && v(!1);
|
|
438
|
-
}, [r.open, y]),
|
|
439
|
-
let
|
|
440
|
-
return r.open && (
|
|
448
|
+
}, [r.open, y]), i.useEffect(() => {
|
|
449
|
+
let u;
|
|
450
|
+
return r.open && (u = setTimeout(() => {
|
|
441
451
|
d(n.current);
|
|
442
|
-
}, 10)), () =>
|
|
443
|
-
}, [r.open, d]), /* @__PURE__ */
|
|
444
|
-
|
|
452
|
+
}, 10)), () => u && clearTimeout(u);
|
|
453
|
+
}, [r.open, d]), /* @__PURE__ */ p(W.Root, { asChild: !0, children: /* @__PURE__ */ p(
|
|
454
|
+
U,
|
|
445
455
|
{
|
|
446
|
-
onEscapeKeyDown: (
|
|
447
|
-
r.open && (
|
|
456
|
+
onEscapeKeyDown: (u) => {
|
|
457
|
+
r.open && (u.stopPropagation(), u.preventDefault(), r.setOpen(!1));
|
|
448
458
|
},
|
|
449
|
-
children: /* @__PURE__ */
|
|
459
|
+
children: /* @__PURE__ */ p(
|
|
450
460
|
Q.Content,
|
|
451
461
|
{
|
|
452
462
|
className: "tgph",
|
|
453
463
|
mt: "1",
|
|
454
|
-
onCloseAutoFocus: (
|
|
464
|
+
onCloseAutoFocus: (u) => {
|
|
455
465
|
var g, m;
|
|
456
|
-
|
|
466
|
+
c.current || (m = (g = r.triggerRef) == null ? void 0 : g.current) == null || m.focus(), c.current = !1, u.preventDefault();
|
|
457
467
|
},
|
|
458
468
|
bg: "surface-1",
|
|
459
469
|
style: {
|
|
@@ -467,28 +477,28 @@ const oe = {
|
|
|
467
477
|
"--tgph-combobox-trigger-width": "var(--radix-popper-anchor-width)",
|
|
468
478
|
"--tgph-combobox-trigger-height": "var(--radix-popper-anchor-height)"
|
|
469
479
|
},
|
|
470
|
-
...
|
|
480
|
+
...l,
|
|
471
481
|
tgphRef: o,
|
|
472
482
|
"data-tgph-combobox-content": !0,
|
|
473
483
|
"data-tgph-combobox-content-open": r.open,
|
|
474
484
|
role: void 0,
|
|
475
485
|
"aria-orientation": void 0,
|
|
476
|
-
onKeyDown: (
|
|
486
|
+
onKeyDown: (u) => {
|
|
477
487
|
var m, b, h, w;
|
|
478
|
-
|
|
488
|
+
u.stopPropagation();
|
|
479
489
|
const g = (b = (m = r.contentRef) == null ? void 0 : m.current) == null ? void 0 : b.querySelectorAll(
|
|
480
490
|
"[data-tgph-combobox-option]"
|
|
481
491
|
);
|
|
482
|
-
document.activeElement === (g == null ? void 0 : g[0]) &&
|
|
492
|
+
document.activeElement === (g == null ? void 0 : g[0]) && ce.includes(u.key) && ((w = (h = r.searchRef) == null ? void 0 : h.current) == null || w.focus());
|
|
483
493
|
},
|
|
484
|
-
children: /* @__PURE__ */
|
|
494
|
+
children: /* @__PURE__ */ p(I, { direction: "column", gap: "1", tgphRef: n, children: a })
|
|
485
495
|
}
|
|
486
496
|
)
|
|
487
497
|
}
|
|
488
498
|
) });
|
|
489
|
-
},
|
|
490
|
-
const a =
|
|
491
|
-
return /* @__PURE__ */
|
|
499
|
+
}, ge = ({ ...t }) => {
|
|
500
|
+
const a = i.useContext(x);
|
|
501
|
+
return /* @__PURE__ */ p(
|
|
492
502
|
I,
|
|
493
503
|
{
|
|
494
504
|
id: a.contentId,
|
|
@@ -496,8 +506,8 @@ const oe = {
|
|
|
496
506
|
gap: "1",
|
|
497
507
|
style: {
|
|
498
508
|
overflowY: "auto",
|
|
499
|
-
//
|
|
500
|
-
maxHeight: "calc(var(--tgph-combobox-content-available-height) - var(--tgph-spacing-12))"
|
|
509
|
+
// maxHeight defaults to available height - padding from edge of screen
|
|
510
|
+
"--max-height": t.maxHeight ? void 0 : "calc(var(--tgph-combobox-content-available-height) - var(--tgph-spacing-12))"
|
|
501
511
|
},
|
|
502
512
|
role: "listbox",
|
|
503
513
|
...t
|
|
@@ -507,41 +517,41 @@ const oe = {
|
|
|
507
517
|
value: t,
|
|
508
518
|
label: a,
|
|
509
519
|
selected: e,
|
|
510
|
-
onSelect:
|
|
520
|
+
onSelect: l,
|
|
511
521
|
children: r,
|
|
512
|
-
...
|
|
522
|
+
...c
|
|
513
523
|
}) => {
|
|
514
|
-
const o =
|
|
515
|
-
|
|
524
|
+
const o = i.useContext(x), [n, s] = i.useState(!1), f = o.value, y = !o.searchQuery || ae({
|
|
525
|
+
children: a || r,
|
|
516
526
|
value: t,
|
|
517
527
|
searchQuery: o.searchQuery
|
|
518
528
|
}), v = k(f) ? f.some(
|
|
519
|
-
(
|
|
520
|
-
) : C(f, o.legacyBehavior) === t, d = (
|
|
529
|
+
(u) => C(u, o.legacyBehavior) === t
|
|
530
|
+
) : C(f, o.legacyBehavior) === t, d = (u) => {
|
|
521
531
|
var m, b;
|
|
522
|
-
|
|
523
|
-
const g =
|
|
532
|
+
u.stopPropagation();
|
|
533
|
+
const g = u;
|
|
524
534
|
if (!(g.key && !z.includes(g.key))) {
|
|
525
|
-
if (
|
|
526
|
-
return
|
|
535
|
+
if (u.preventDefault(), o.closeOnSelect === !0 && o.setOpen(!1), l)
|
|
536
|
+
return l(u);
|
|
527
537
|
if (T(f)) {
|
|
528
538
|
const h = o.onValueChange;
|
|
529
539
|
o.legacyBehavior === !0 ? h == null || h({ value: t, label: a }) : h == null || h(t);
|
|
530
540
|
} else if (k(f)) {
|
|
531
|
-
const h = o.onValueChange, w = o.value,
|
|
532
|
-
(
|
|
541
|
+
const h = o.onValueChange, w = o.value, V = v ? w.filter(
|
|
542
|
+
(D) => C(D, o.legacyBehavior) !== t
|
|
533
543
|
) : [
|
|
534
544
|
...w,
|
|
535
545
|
// TODO: Remove this once { value, label } option is deprecated
|
|
536
546
|
o.legacyBehavior === !0 ? { value: t, label: a } : t
|
|
537
547
|
];
|
|
538
|
-
h == null || h(
|
|
548
|
+
h == null || h(V);
|
|
539
549
|
}
|
|
540
550
|
(b = (m = o.triggerRef) == null ? void 0 : m.current) == null || b.focus();
|
|
541
551
|
}
|
|
542
552
|
};
|
|
543
553
|
if (y)
|
|
544
|
-
return /* @__PURE__ */
|
|
554
|
+
return /* @__PURE__ */ p(
|
|
545
555
|
Q.Button,
|
|
546
556
|
{
|
|
547
557
|
type: "button",
|
|
@@ -556,34 +566,34 @@ const oe = {
|
|
|
556
566
|
"data-tgph-combobox-option-focused": n,
|
|
557
567
|
"data-tgph-combobox-option-value": t,
|
|
558
568
|
"data-tgph-combobox-option-label": a,
|
|
559
|
-
...
|
|
569
|
+
...c,
|
|
560
570
|
children: a || r || t
|
|
561
571
|
}
|
|
562
572
|
);
|
|
563
|
-
},
|
|
573
|
+
}, he = ({
|
|
564
574
|
label: t = "Search",
|
|
565
575
|
placeholder: a = "Search",
|
|
566
576
|
tgphRef: e,
|
|
567
|
-
value:
|
|
577
|
+
value: l,
|
|
568
578
|
onValueChange: r,
|
|
569
|
-
...
|
|
579
|
+
...c
|
|
570
580
|
}) => {
|
|
571
581
|
var v;
|
|
572
|
-
const o =
|
|
573
|
-
return
|
|
582
|
+
const o = i.useId(), n = i.useContext(x), s = j(e, n.searchRef), f = l ?? n.searchQuery, y = r ?? n.setSearchQuery;
|
|
583
|
+
return i.useEffect(() => {
|
|
574
584
|
var g;
|
|
575
585
|
const d = (m) => {
|
|
576
586
|
var b, h;
|
|
577
|
-
|
|
578
|
-
},
|
|
579
|
-
if (
|
|
580
|
-
return
|
|
581
|
-
|
|
587
|
+
ie.includes(m.key) && ((h = (b = n.contentRef) == null ? void 0 : b.current) == null || h.focus({ preventScroll: !0 })), m.key === "Escape" && n.setOpen(!1), m.stopPropagation();
|
|
588
|
+
}, u = (g = n.searchRef) == null ? void 0 : g.current;
|
|
589
|
+
if (u)
|
|
590
|
+
return u.addEventListener("keydown", d), () => {
|
|
591
|
+
u.removeEventListener("keydown", d);
|
|
582
592
|
};
|
|
583
|
-
}, [n]), /* @__PURE__ */ S(
|
|
584
|
-
/* @__PURE__ */
|
|
585
|
-
/* @__PURE__ */
|
|
586
|
-
|
|
593
|
+
}, [n]), /* @__PURE__ */ S(_, { borderBottom: "px", px: "1", pb: "1", children: [
|
|
594
|
+
/* @__PURE__ */ p(Z.Root, { children: /* @__PURE__ */ p(M, { as: "label", htmlFor: o, children: t }) }),
|
|
595
|
+
/* @__PURE__ */ p(
|
|
596
|
+
te,
|
|
587
597
|
{
|
|
588
598
|
id: o,
|
|
589
599
|
variant: "ghost",
|
|
@@ -592,8 +602,8 @@ const oe = {
|
|
|
592
602
|
onChange: (d) => {
|
|
593
603
|
y(d.target.value);
|
|
594
604
|
},
|
|
595
|
-
LeadingComponent: /* @__PURE__ */
|
|
596
|
-
TrailingComponent: n != null && n.searchQuery && ((v = n == null ? void 0 : n.searchQuery) == null ? void 0 : v.length) > 0 ? /* @__PURE__ */
|
|
605
|
+
LeadingComponent: /* @__PURE__ */ p(N, { icon: R.Search, alt: "Search Icon" }),
|
|
606
|
+
TrailingComponent: n != null && n.searchQuery && ((v = n == null ? void 0 : n.searchQuery) == null ? void 0 : v.length) > 0 ? /* @__PURE__ */ p(
|
|
597
607
|
E,
|
|
598
608
|
{
|
|
599
609
|
variant: "ghost",
|
|
@@ -608,25 +618,25 @@ const oe = {
|
|
|
608
618
|
autoFocus: !0,
|
|
609
619
|
"data-tgph-combobox-search": !0,
|
|
610
620
|
"aria-controls": n.contentId,
|
|
611
|
-
...
|
|
621
|
+
...c,
|
|
612
622
|
tgphRef: s
|
|
613
623
|
}
|
|
614
624
|
)
|
|
615
625
|
] });
|
|
616
|
-
},
|
|
626
|
+
}, de = ({
|
|
617
627
|
icon: t = { icon: R.Search, alt: "Search Icon" },
|
|
618
628
|
message: a = "No results found",
|
|
619
629
|
children: e,
|
|
620
|
-
...
|
|
630
|
+
...l
|
|
621
631
|
}) => {
|
|
622
|
-
const r =
|
|
623
|
-
if (
|
|
632
|
+
const r = i.useContext(x), [c, o] = i.useState(!1);
|
|
633
|
+
if (i.useEffect(() => {
|
|
624
634
|
var s, f;
|
|
625
635
|
const n = (f = (s = r.contentRef) == null ? void 0 : s.current) == null ? void 0 : f.querySelectorAll(
|
|
626
636
|
"[data-tgph-combobox-option]"
|
|
627
637
|
);
|
|
628
638
|
(n == null ? void 0 : n.length) === 0 ? o(!0) : o(!1);
|
|
629
|
-
}, [r.searchQuery, r.contentRef, e]),
|
|
639
|
+
}, [r.searchQuery, r.contentRef, e]), c)
|
|
630
640
|
return /* @__PURE__ */ S(
|
|
631
641
|
I,
|
|
632
642
|
{
|
|
@@ -636,36 +646,36 @@ const oe = {
|
|
|
636
646
|
w: "full",
|
|
637
647
|
my: "8",
|
|
638
648
|
"data-tgph-combobox-empty": !0,
|
|
639
|
-
...
|
|
649
|
+
...l,
|
|
640
650
|
children: [
|
|
641
|
-
t === null ? /* @__PURE__ */
|
|
642
|
-
a === null ? /* @__PURE__ */
|
|
651
|
+
t === null ? /* @__PURE__ */ p(K, {}) : /* @__PURE__ */ p(N, { ...t }),
|
|
652
|
+
a === null ? /* @__PURE__ */ p(K, {}) : /* @__PURE__ */ p(M, { as: "span", children: a })
|
|
643
653
|
]
|
|
644
654
|
}
|
|
645
655
|
);
|
|
646
|
-
},
|
|
656
|
+
}, me = ({
|
|
647
657
|
leadingText: t = "Create",
|
|
648
658
|
values: a,
|
|
649
659
|
onCreate: e,
|
|
650
|
-
selected:
|
|
660
|
+
selected: l = null,
|
|
651
661
|
legacyBehavior: r = !1,
|
|
652
|
-
...
|
|
662
|
+
...c
|
|
653
663
|
}) => {
|
|
654
|
-
const o =
|
|
664
|
+
const o = i.useContext(x), n = i.useCallback(
|
|
655
665
|
(s) => !a || (a == null ? void 0 : a.length) === 0 ? !1 : a.some(
|
|
656
666
|
(f) => C(f, r) === s
|
|
657
667
|
),
|
|
658
668
|
[a, r]
|
|
659
669
|
);
|
|
660
670
|
if (o.searchQuery && !n(o.searchQuery))
|
|
661
|
-
return /* @__PURE__ */
|
|
671
|
+
return /* @__PURE__ */ p(
|
|
662
672
|
G,
|
|
663
673
|
{
|
|
664
674
|
leadingIcon: { icon: R.Plus, "aria-hidden": !0 },
|
|
665
675
|
mx: "1",
|
|
666
676
|
value: o.searchQuery,
|
|
667
677
|
label: `${t} "${o.searchQuery}"`,
|
|
668
|
-
selected:
|
|
678
|
+
selected: l,
|
|
669
679
|
onSelect: () => {
|
|
670
680
|
var s;
|
|
671
681
|
if (e && o.value && o.searchQuery) {
|
|
@@ -673,21 +683,21 @@ const oe = {
|
|
|
673
683
|
e(f), (s = o.setSearchQuery) == null || s.call(o, "");
|
|
674
684
|
}
|
|
675
685
|
},
|
|
676
|
-
...
|
|
686
|
+
...c
|
|
677
687
|
}
|
|
678
688
|
);
|
|
679
|
-
},
|
|
680
|
-
Object.assign(
|
|
681
|
-
Root:
|
|
682
|
-
Trigger:
|
|
683
|
-
Content:
|
|
684
|
-
Options:
|
|
689
|
+
}, ye = {};
|
|
690
|
+
Object.assign(ye, {
|
|
691
|
+
Root: se,
|
|
692
|
+
Trigger: pe,
|
|
693
|
+
Content: fe,
|
|
694
|
+
Options: ge,
|
|
685
695
|
Option: G,
|
|
686
|
-
Search:
|
|
687
|
-
Empty:
|
|
688
|
-
Create:
|
|
696
|
+
Search: he,
|
|
697
|
+
Empty: de,
|
|
698
|
+
Create: me
|
|
689
699
|
});
|
|
690
700
|
export {
|
|
691
|
-
|
|
701
|
+
ye as Combobox
|
|
692
702
|
};
|
|
693
703
|
//# sourceMappingURL=index.mjs.map
|