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