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