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