@telegraph/combobox 0.0.28 → 0.0.30

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