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