@telegraph/combobox 0.0.75 → 0.0.77

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