@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.
@@ -1,25 +1,24 @@
1
- import { jsx as i, jsxs as S, Fragment as F } from "react/jsx-runtime";
2
- import { DismissableLayer as M } from "@radix-ui/react-dismissable-layer";
3
- import { useControllableState as Y } from "@radix-ui/react-use-controllable-state";
4
- import * as z from "@radix-ui/react-visually-hidden";
5
- import { Button as E } from "@telegraph/button";
6
- import { useComposedRefs as H } from "@telegraph/compose-refs";
7
- import { RefToTgphRef as X } from "@telegraph/helpers";
8
- import { Lucide as v, Icon as K } from "@telegraph/icon";
9
- import { Input as q } from "@telegraph/input";
10
- import { Stack as T, Box as B } from "@telegraph/layout";
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 N } from "@telegraph/tooltip";
14
- import { Text as P } from "@telegraph/typography";
15
- import { motion as I, AnimatePresence as L } from "framer-motion";
16
- import c from "react";
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
- }, R = (t) => Array.isArray(t), k = (t) => typeof t == "object" && !Array.isArray(t) || !t, J = ["ArrowDown", "PageUp", "Home"], W = ["ArrowUp", "PageDown", "End"], j = ["Enter", " "], x = c.createContext({
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
- }), Z = ({
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: r,
42
- defaultOpen: n,
43
- value: o,
44
- onValueChange: a,
45
- errored: b,
46
- placeholder: d,
47
- layout: y,
48
- ...g
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 p = c.useId(), f = c.useId(), m = c.useRef(null), h = c.useRef(null), C = c.useRef(null), [w, V] = c.useState(""), [Q = !1, A] = Y({
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: n,
53
- onChange: r
54
- }), $ = c.useCallback(() => {
55
- A((G) => !G);
56
- }, [A]);
57
- return c.useEffect(() => {
58
- Q || V("");
59
- }, [Q]), /* @__PURE__ */ i(
60
- x.Provider,
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: p,
64
- triggerId: f,
65
- value: o,
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: a,
70
- placeholder: d,
71
- open: Q,
72
- setOpen: A,
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: w,
78
- setSearchQuery: V,
79
- triggerRef: m,
80
- searchRef: h,
81
- contentRef: C,
82
- errored: b,
83
- layout: y
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__ */ i(
84
+ children: /* @__PURE__ */ c(
86
85
  D.Root,
87
86
  {
88
- open: Q,
89
- onOpenChange: A,
87
+ open: E,
88
+ onOpenChange: Q,
90
89
  modal: t,
91
- ...g
90
+ ...p
92
91
  }
93
92
  )
94
93
  }
95
94
  );
96
- }, ee = ({ label: t, value: l, ...e }) => {
97
- const u = c.useContext(x);
98
- return /* @__PURE__ */ S(
99
- O.Root,
100
- {
101
- size: "1",
102
- as: I.span,
103
- initial: { opacity: 0, transform: "scale(0.8)" },
104
- animate: { opacity: 1, transform: "scale(1)" },
105
- exit: { opacity: 0, transform: "scale(0.5)" },
106
- layout: "position",
107
- transition: {
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
- ...e,
118
- children: [
119
- /* @__PURE__ */ i(O.Text, { children: t || l }),
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 = c.useContext(x);
137
- if (t.value && R(t.value)) {
138
- const u = t.layout || "truncate", s = t.value.length - 2, r = s.toString().split("");
139
- return t.value.length === 0 ? /* @__PURE__ */ i(E.Text, { color: "gray", children: t.placeholder }) : /* @__PURE__ */ S(
140
- T,
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
- /* @__PURE__ */ i(L, { initial: !1, mode: "popLayout", children: t.value.map((n, o) => {
152
- if (n != null && n.value && (u === "truncate" && o <= 1 || u === "wrap"))
153
- return /* @__PURE__ */ i(X, { children: /* @__PURE__ */ i(ee, { ...n }) }, n.value);
154
- }) }),
155
- /* @__PURE__ */ i(L, { children: u === "truncate" && t.value.length > 2 && /* @__PURE__ */ i(
156
- T,
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__ */ S(P, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
145
+ children: /* @__PURE__ */ w(L, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
174
146
  "+",
175
- /* @__PURE__ */ i(L, { mode: "wait", initial: !1, children: r.map((n) => /* @__PURE__ */ i(
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
- "truncated text"
200
- ) })
151
+ }
152
+ )
201
153
  ]
202
154
  }
203
155
  );
204
156
  }
205
- return /* @__PURE__ */ i(E.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 });
206
- }, oe = ({ size: t = "2", ...l }) => {
207
- const e = c.useContext(x), u = c.useCallback(() => {
208
- var n, o, a;
209
- return e.value ? k(e.value) ? ((n = e.value) == null ? void 0 : n.label) || ((o = e.value) == null ? void 0 : o.value) || e.placeholder : ((a = e.value) == null ? void 0 : a.map((b) => b == null ? void 0 : b.label).join(", ")) || e.placeholder : e.placeholder;
210
- }, [e.value, e.placeholder]), s = c.useMemo(() => {
211
- var n;
212
- if (R(e.value))
213
- return e.clearable && ((n = e.value) == null ? void 0 : n.length) > 0;
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]), r = () => {
217
- var n, o;
218
- if (R(e.value)) {
219
- const a = e.onValueChange;
220
- a == null || a([]);
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 a = e.onValueChange;
224
- a == null || a(void 0);
175
+ const r = e.onValueChange;
176
+ r == null || r(void 0);
225
177
  }
226
- (o = (n = e.triggerRef) == null ? void 0 : n.current) == null || o.focus();
178
+ (n = (o = e.triggerRef) == null ? void 0 : o.current) == null || n.focus();
227
179
  };
228
- return /* @__PURE__ */ i(
180
+ return /* @__PURE__ */ c(
229
181
  D.Trigger,
230
182
  {
231
183
  ...l,
232
184
  asChild: !0,
233
- onClick: (n) => {
234
- var o, a;
235
- n.preventDefault(), e.onOpenToggle(), (a = (o = e.triggerRef) == null ? void 0 : o.current) == null || a.focus();
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: (n) => {
238
- if (n.key === "Tab") {
239
- n.stopPropagation();
189
+ onKeyDown: (o) => {
190
+ if (o.key === "Tab") {
191
+ o.stopPropagation();
240
192
  return;
241
193
  }
242
- if (j.includes(n.key)) {
243
- n.preventDefault();
194
+ if (j.includes(o.key)) {
195
+ o.preventDefault();
244
196
  return;
245
197
  }
246
- if (n.key === "ArrowDown") {
247
- n.stopPropagation(), n.preventDefault(), e.onOpenToggle();
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__ */ S(
253
- E.Root,
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: U[t],
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__ */ i(te, {}),
277
- /* @__PURE__ */ S(T, { align: "center", gap: "1", children: [
278
- s && /* @__PURE__ */ i(N, { label: "Clear field", children: /* @__PURE__ */ i(
279
- E,
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: v.X, alt: "Clear field" },
234
+ icon: { icon: R.X, alt: "Clear field" },
283
235
  size: "1",
284
236
  variant: "ghost",
285
- onClick: (n) => {
286
- e.value && (n.stopPropagation(), r());
237
+ onClick: (o) => {
238
+ e.value && (o.stopPropagation(), a());
287
239
  },
288
- onKeyDown: (n) => {
289
- (n.key === "Enter" || n.key === " ") && (n.stopPropagation(), r());
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__ */ i(
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
- }, ne = ({
259
+ }, te = ({
317
260
  tgphRef: t,
318
261
  style: l,
319
262
  children: e,
320
263
  ...u
321
264
  }) => {
322
- const s = c.useContext(x), r = c.useRef(!1), n = H(t, s.contentRef), o = c.useRef(null), [a, b] = c.useState(0), [d, y] = c.useState(!1), g = c.useCallback(
323
- (p) => {
324
- const f = p.getBoundingClientRect();
325
- f && b(f.height), d || y(!0);
326
- },
327
- [d]
328
- );
329
- return c.useEffect(() => {
330
- const p = new ResizeObserver((f) => {
331
- for (const m of f) {
332
- const h = m.target;
333
- g(h);
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
- }, re = ({ ...t }) => {
406
- const l = c.useContext(x);
407
- return /* @__PURE__ */ i(
408
- T,
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 r = c.useContext(x), [n, o] = c.useState(!1), a = r.value, b = (R(a), !r.searchQuery || t.toLowerCase().includes(r.searchQuery.toLowerCase())), d = R(a) ? a.some((g) => (g == null ? void 0 : g.value) === t) : (a == null ? void 0 : a.value) === t, y = (g) => {
430
- var f, m;
431
- g.stopPropagation();
432
- const p = g;
433
- if (!(p.key && !j.includes(p.key))) {
434
- if (g.preventDefault(), r.closeOnSelect === !0 && r.setOpen(!1), u)
435
- return u(g);
436
- if (k(a)) {
437
- const h = r.onValueChange;
438
- h == null || h({ value: t, label: l });
439
- } else if (R(a)) {
440
- const h = r.onValueChange, C = d ? a.filter((w) => (w == null ? void 0 : w.value) !== t) : [...a, { value: t, label: l }];
441
- h == null || h(C);
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
- (m = (f = r.triggerRef) == null ? void 0 : f.current) == null || m.focus();
351
+ (y = (x = a.triggerRef) == null ? void 0 : x.current) == null || y.focus();
444
352
  }
445
353
  };
446
- if (b)
447
- return /* @__PURE__ */ i(
354
+ if (g)
355
+ return /* @__PURE__ */ c(
448
356
  D.Button,
449
357
  {
450
358
  type: "button",
451
- onSelect: y,
452
- onKeyDown: y,
453
- selected: e === null ? null : e ?? d,
454
- onFocus: () => o(!0),
455
- onBlur: () => o(!1),
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": d ? "true" : "false",
365
+ "aria-selected": h ? "true" : "false",
458
366
  "data-tgph-combobox-option": !0,
459
- "data-tgph-combobox-option-focused": n,
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
- }, ae = ({
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
- ...r
380
+ ...a
473
381
  }) => {
474
- var y;
475
- const n = c.useId(), o = c.useContext(x), a = H(e, o.searchRef), b = u ?? o.searchQuery, d = s ?? o.setSearchQuery;
476
- return c.useEffect(() => {
477
- var f;
478
- const g = (m) => {
479
- var h, C;
480
- J.includes(m.key) && ((C = (h = o.contentRef) == null ? void 0 : h.current) == null || C.focus({ preventScroll: !0 })), m.key === "Escape" && o.setOpen(!1), m.stopPropagation();
481
- }, p = (f = o.searchRef) == null ? void 0 : f.current;
482
- if (p)
483
- return p.addEventListener("keydown", g), () => {
484
- p.removeEventListener("keydown", g);
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
- }, [o]), /* @__PURE__ */ S(B, { borderBottom: "px", px: "1", pb: "1", children: [
487
- /* @__PURE__ */ i(z.Root, { children: /* @__PURE__ */ i(P, { as: "label", htmlFor: n, children: t }) }),
488
- /* @__PURE__ */ i(
489
- q,
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: n,
399
+ id: o,
492
400
  variant: "ghost",
493
401
  placeholder: l,
494
- value: b,
495
- onChange: (g) => {
496
- d(g.target.value);
402
+ value: g,
403
+ onChange: (p) => {
404
+ h(p.target.value);
497
405
  },
498
- LeadingComponent: /* @__PURE__ */ i(K, { icon: v.Search, alt: "Search Icon" }),
499
- TrailingComponent: o != null && o.searchQuery && ((y = o == null ? void 0 : o.searchQuery) == null ? void 0 : y.length) > 0 ? /* @__PURE__ */ i(
500
- E,
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: v.X, alt: "Clear Search Query" },
412
+ icon: { icon: R.X, alt: "Clear Search Query" },
509
413
  onClick: () => {
510
- var g;
511
- return (g = o.setSearchQuery) == null ? void 0 : g.call(o, "");
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": o.contentId,
518
- ...r,
519
- tgphRef: a
421
+ "aria-controls": n.contentId,
422
+ ...a,
423
+ tgphRef: r
520
424
  }
521
425
  )
522
426
  ] });
523
- }, ie = ({
524
- icon: t = { icon: v.Search, alt: "Search 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 = c.useContext(x), [r, n] = c.useState(!1);
530
- if (c.useEffect(() => {
531
- var a, b;
532
- const o = (b = (a = s.contentRef) == null ? void 0 : a.current) == null ? void 0 : b.querySelectorAll(
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
- (o == null ? void 0 : o.length) === 0 ? n(!0) : n(!1);
536
- }, [s.searchQuery, s.contentRef, e]), r)
537
- return /* @__PURE__ */ S(
538
- T,
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__ */ i(F, {}) : /* @__PURE__ */ i(K, { ...t }),
553
- l === null ? /* @__PURE__ */ i(F, {}) : /* @__PURE__ */ i(P, { as: "span", children: l })
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
- }, ce = ({
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 r = c.useContext(x), n = c.useCallback(
565
- (o) => !l || (l == null ? void 0 : l.length) === 0 ? !1 : l.some((a) => (a == null ? void 0 : a.value) === o),
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 (r.searchQuery && !n(r.searchQuery))
569
- return /* @__PURE__ */ i(
570
- _,
468
+ if (a.searchQuery && !o(a.searchQuery))
469
+ return /* @__PURE__ */ c(
470
+ B,
571
471
  {
572
- leadingIcon: { icon: v.Plus, "aria-hidden": !0 },
472
+ leadingIcon: { icon: R.Plus, "aria-hidden": !0 },
573
473
  mx: "1",
574
- value: r.searchQuery,
575
- label: `${t} "${r.searchQuery}"`,
474
+ value: a.searchQuery,
475
+ label: `${t} "${a.searchQuery}"`,
576
476
  selected: u,
577
477
  onSelect: () => {
578
- var o;
579
- e && r.value && r.searchQuery && (k(r.value) && e({ value: r.searchQuery }), R(r.value) && e({ value: r.searchQuery }), (o = r.setSearchQuery) == null || o.call(r, ""));
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: Z,
587
- Trigger: oe,
588
- Content: ne,
589
- Options: re,
590
- Option: _,
591
- Search: ae,
592
- Empty: ie,
593
- Create: ce
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