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