@telegraph/combobox 0.0.59 → 0.0.60

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