@telegraph/combobox 0.0.2 → 0.0.4

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,4 +1,4 @@
1
- import { jsx as u, jsxs as S, Fragment as W } from "react/jsx-runtime";
1
+ import { jsx as u, jsxs as T, Fragment as W } from "react/jsx-runtime";
2
2
  import { useControllableState as be } from "@radix-ui/react-use-controllable-state";
3
3
  import * as he from "@radix-ui/react-visually-hidden";
4
4
  import { Icon as K, Lucide as j } from "@telegraph/icon";
@@ -537,11 +537,11 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
537
537
  px: "0"
538
538
  }
539
539
  }
540
- }, Te = {
540
+ }, Se = {
541
541
  1: "1",
542
542
  2: "2",
543
543
  3: "3"
544
- }, Se = {
544
+ }, Te = {
545
545
  solid: {
546
546
  gray: "white",
547
547
  red: "white",
@@ -649,11 +649,11 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
649
649
  ...c
650
650
  }) => {
651
651
  const d = n ? "disabled" : i, s = d === "disabled" ? "disabled" : a, b = p.useMemo(() => {
652
- var y;
652
+ var h;
653
653
  const g = p.Children.toArray(c == null ? void 0 : c.children);
654
654
  if ((g == null ? void 0 : g.length) === 1 && p.isValidElement(g[0])) {
655
- const h = g[0];
656
- if ((y = h == null ? void 0 : h.props) != null && y.icon)
655
+ const y = g[0];
656
+ if ((h = y == null ? void 0 : y.props) != null && h.icon)
657
657
  return "icon-only";
658
658
  }
659
659
  return "default";
@@ -728,8 +728,8 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
728
728
  P,
729
729
  {
730
730
  as: o || "span",
731
- color: t ?? Se[n.variant][n.color],
732
- size: e ?? Te[n.size],
731
+ color: t ?? Te[n.variant][n.color],
732
+ size: e ?? Se[n.size],
733
733
  weight: a,
734
734
  className: $("no-underline whitespace-nowrap", i),
735
735
  internal_optionalAs: !0,
@@ -745,7 +745,7 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
745
745
  ...i
746
746
  }) => {
747
747
  const r = o || e;
748
- return /* @__PURE__ */ S(ie, { ...i, children: [
748
+ return /* @__PURE__ */ T(ie, { ...i, children: [
749
749
  r && /* @__PURE__ */ u(H, { ...r }),
750
750
  a && /* @__PURE__ */ u(le, { children: a }),
751
751
  t && /* @__PURE__ */ u(H, { ...t })
@@ -1152,7 +1152,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1152
1152
  type: "spacing",
1153
1153
  valueType: "variable"
1154
1154
  }
1155
- }, T = ({
1155
+ }, S = ({
1156
1156
  className: o,
1157
1157
  tgphRef: t,
1158
1158
  ...e
@@ -1201,7 +1201,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1201
1201
  layout: d,
1202
1202
  ...s
1203
1203
  }) => {
1204
- const b = p.useId(), y = p.useId(), g = p.useRef(null), h = p.useRef(null), v = p.useRef(null), [k, C] = p.useState(""), [L = !1, M] = be({
1204
+ const b = p.useId(), h = p.useId(), g = p.useRef(null), y = p.useRef(null), v = p.useRef(null), [k, C] = p.useState(""), [L = !1, M] = be({
1205
1205
  prop: e,
1206
1206
  defaultProp: i,
1207
1207
  onChange: a
@@ -1215,7 +1215,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1215
1215
  {
1216
1216
  value: {
1217
1217
  contentId: b,
1218
- triggerId: y,
1218
+ triggerId: h,
1219
1219
  value: r,
1220
1220
  onValueChange: n,
1221
1221
  placeholder: c,
@@ -1226,7 +1226,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1226
1226
  searchQuery: k,
1227
1227
  setSearchQuery: C,
1228
1228
  triggerRef: g,
1229
- searchRef: h,
1229
+ searchRef: y,
1230
1230
  contentRef: v,
1231
1231
  errored: l,
1232
1232
  layout: d
@@ -1244,7 +1244,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1244
1244
  );
1245
1245
  }, De = ({ label: o, value: t, ...e }) => {
1246
1246
  const a = p.useContext(w);
1247
- return /* @__PURE__ */ S(
1247
+ return /* @__PURE__ */ T(
1248
1248
  z.Root,
1249
1249
  {
1250
1250
  size: "1",
@@ -1286,8 +1286,8 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1286
1286
  const t = p.useContext(w), e = o === "1" ? "6" : o === "2" ? "8" : "10";
1287
1287
  if (t.value && Q(t.value)) {
1288
1288
  const r = t.value, n = t.layout || "truncate", l = r.length - 2, c = l.toString().split("");
1289
- return r.length === 0 ? /* @__PURE__ */ u(T, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(D.Text, { color: "gray", children: t.placeholder }) }) : /* @__PURE__ */ S(
1290
- T,
1289
+ return r.length === 0 ? /* @__PURE__ */ u(S, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(D.Text, { color: "gray", children: t.placeholder }) }) : /* @__PURE__ */ T(
1290
+ S,
1291
1291
  {
1292
1292
  gap: "1",
1293
1293
  w: "full",
@@ -1304,7 +1304,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1304
1304
  return /* @__PURE__ */ u(re, { children: /* @__PURE__ */ u(De, { ...d }) }, d.value);
1305
1305
  }) }),
1306
1306
  /* @__PURE__ */ u(F, { children: n === "truncate" && r.length > 2 && /* @__PURE__ */ u(
1307
- T,
1307
+ S,
1308
1308
  {
1309
1309
  as: E.div,
1310
1310
  initial: { opacity: 0 },
@@ -1321,7 +1321,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1321
1321
  right: 0,
1322
1322
  backgroundImage: "linear-gradient(to left, var(--tgph-surface-1) 0 60%, transparent 90% 100%)"
1323
1323
  },
1324
- children: /* @__PURE__ */ S(P, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
1324
+ children: /* @__PURE__ */ T(P, { as: "span", size: "1", style: { whiteSpace: "nowrap" }, children: [
1325
1325
  "+",
1326
1326
  /* @__PURE__ */ u(F, { mode: "wait", initial: !1, children: c.map((d) => /* @__PURE__ */ u(
1327
1327
  X,
@@ -1353,7 +1353,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1353
1353
  }
1354
1354
  );
1355
1355
  }
1356
- return /* @__PURE__ */ u(T, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(D.Text, { color: t.value ? "default" : "gray", children: ((a = t == null ? void 0 : t.value) == null ? void 0 : a.label) || ((i = t == null ? void 0 : t.value) == null ? void 0 : i.value) || t.placeholder }) });
1356
+ return /* @__PURE__ */ u(S, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(D.Text, { color: t.value ? "default" : "gray", children: ((a = t == null ? void 0 : t.value) == null ? void 0 : a.label) || ((i = t == null ? void 0 : t.value) == null ? void 0 : i.value) || t.placeholder }) });
1357
1357
  }, Pe = ({ size: o = "1", ...t }) => {
1358
1358
  const e = p.useContext(w), a = p.useCallback(() => {
1359
1359
  var i, r, n;
@@ -1383,7 +1383,7 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1383
1383
  }
1384
1384
  },
1385
1385
  tgphRef: e.triggerRef,
1386
- children: /* @__PURE__ */ u(re, { children: /* @__PURE__ */ S(
1386
+ children: /* @__PURE__ */ u(re, { children: /* @__PURE__ */ T(
1387
1387
  D.Root,
1388
1388
  {
1389
1389
  id: e.triggerId,
@@ -1423,22 +1423,22 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1423
1423
  children: e,
1424
1424
  ...a
1425
1425
  }) => {
1426
- const i = p.useContext(w), r = p.useRef(!1), n = B(o, i.contentRef), l = p.useRef(null), [c, d] = p.useState(0), [s, b] = p.useState(!1), y = p.useCallback(
1426
+ const i = p.useContext(w), r = p.useRef(!1), n = B(o, i.contentRef), l = p.useRef(null), [c, d] = p.useState(0), [s, b] = p.useState(!1), h = p.useCallback(
1427
1427
  (g) => {
1428
- const h = g.getBoundingClientRect();
1429
- h && d(h.height), s || b(!0);
1428
+ const y = g.getBoundingClientRect();
1429
+ y && d(y.height), s || b(!0);
1430
1430
  },
1431
1431
  [s]
1432
1432
  );
1433
1433
  return p.useEffect(() => {
1434
- const g = new ResizeObserver((h) => {
1435
- for (const v of h) {
1434
+ const g = new ResizeObserver((y) => {
1435
+ for (const v of y) {
1436
1436
  const k = v.target;
1437
- y(k);
1437
+ h(k);
1438
1438
  }
1439
1439
  });
1440
1440
  return l.current && s && g.observe(l.current), () => g.disconnect();
1441
- }, [s, y]), p.useEffect(() => {
1441
+ }, [s, h]), p.useEffect(() => {
1442
1442
  s === !0 && i.open === !1 && b(!1);
1443
1443
  }, [i.open, s]), /* @__PURE__ */ u(
1444
1444
  N.Content,
@@ -1465,19 +1465,19 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1465
1465
  onAnimationComplete: () => {
1466
1466
  if (!s && l) {
1467
1467
  const g = l.current;
1468
- y(g);
1468
+ h(g);
1469
1469
  }
1470
1470
  },
1471
1471
  onCloseAutoFocus: (g) => {
1472
- var h, v;
1473
- r.current || (v = (h = i.triggerRef) == null ? void 0 : h.current) == null || v.focus(), r.current = !1, g.preventDefault();
1472
+ var y, v;
1473
+ r.current || (v = (y = i.triggerRef) == null ? void 0 : y.current) == null || v.focus(), r.current = !1, g.preventDefault();
1474
1474
  },
1475
1475
  onKeyDown: (g) => {
1476
1476
  var v, k, C, L;
1477
- const h = (k = (v = i.contentRef) == null ? void 0 : v.current) == null ? void 0 : k.querySelectorAll(
1477
+ const y = (k = (v = i.contentRef) == null ? void 0 : v.current) == null ? void 0 : k.querySelectorAll(
1478
1478
  "[data-tgph-combobox-option]"
1479
1479
  );
1480
- document.activeElement === (h == null ? void 0 : h[0]) && Ae.includes(g.key) && ((L = (C = i.searchRef) == null ? void 0 : C.current) == null || L.focus()), g.key === "Escape" && i.setOpen(!1), g.stopPropagation();
1480
+ document.activeElement === (y == null ? void 0 : y[0]) && Ae.includes(g.key) && ((L = (C = i.searchRef) == null ? void 0 : C.current) == null || L.focus()), g.key === "Escape" && i.setOpen(!1), g.stopPropagation();
1481
1481
  },
1482
1482
  bg: "surface-1",
1483
1483
  style: {
@@ -1495,13 +1495,13 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1495
1495
  "data-tgph-combobox-content-open": s,
1496
1496
  role: void 0,
1497
1497
  "aria-orientation": void 0,
1498
- children: /* @__PURE__ */ u(T, { direction: "column", gap: "1", tgphRef: l, children: e })
1498
+ children: /* @__PURE__ */ u(S, { direction: "column", gap: "1", tgphRef: l, children: e })
1499
1499
  }
1500
1500
  );
1501
1501
  }, Ne = ({ ...o }) => {
1502
1502
  const t = p.useContext(w);
1503
1503
  return /* @__PURE__ */ u(
1504
- T,
1504
+ S,
1505
1505
  {
1506
1506
  id: t.contentId,
1507
1507
  direction: "column",
@@ -1522,11 +1522,11 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1522
1522
  onSelect: a,
1523
1523
  ...i
1524
1524
  }) => {
1525
- const r = p.useContext(w), [n, l] = p.useState(!1), c = r.value ?? [], d = (Q(c), !r.searchQuery || o.toLowerCase().includes(r.searchQuery.toLowerCase())), s = Q(c) ? c.some((y) => y.value === o) : c.value === o, b = (y) => {
1526
- var g, h;
1527
- if (ue.includes(y.key)) {
1528
- if (y.stopPropagation(), y.preventDefault(), r.closeOnSelect === !0 && r.setOpen(!1), a)
1529
- return a(y);
1525
+ const r = p.useContext(w), [n, l] = p.useState(!1), c = r.value ?? [], d = (Q(c), !r.searchQuery || o.toLowerCase().includes(r.searchQuery.toLowerCase())), s = Q(c) ? c.some((h) => h.value === o) : c.value === o, b = (h) => {
1526
+ var g, y;
1527
+ if (!(h.key && !ue.includes(h.key))) {
1528
+ if (h.stopPropagation(), h.preventDefault(), r.closeOnSelect === !0 && r.setOpen(!1), a)
1529
+ return a(h);
1530
1530
  if (Q(c)) {
1531
1531
  const v = r.onValueChange, k = s ? c.filter((C) => C.value !== o) : [...c, { value: o, label: t }];
1532
1532
  v(k);
@@ -1534,13 +1534,14 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1534
1534
  const v = r.onValueChange;
1535
1535
  v({ value: o, label: t });
1536
1536
  }
1537
- (h = (g = r.triggerRef) == null ? void 0 : g.current) == null || h.focus();
1537
+ (y = (g = r.triggerRef) == null ? void 0 : g.current) == null || y.focus();
1538
1538
  }
1539
1539
  };
1540
1540
  if (d)
1541
1541
  return /* @__PURE__ */ u(
1542
1542
  N.Button,
1543
1543
  {
1544
+ onSelect: b,
1544
1545
  onKeyDown: b,
1545
1546
  selected: e === null ? null : e ?? s,
1546
1547
  onFocus: () => l(!0),
@@ -1566,14 +1567,14 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1566
1567
  return p.useEffect(() => {
1567
1568
  var s;
1568
1569
  const c = (b) => {
1569
- var y, g;
1570
- Ve.includes(b.key) && ((g = (y = r.contentRef) == null ? void 0 : y.current) == null || g.focus({ preventScroll: !0 })), b.key === "Escape" && r.setOpen(!1), b.stopPropagation();
1570
+ var h, g;
1571
+ Ve.includes(b.key) && ((g = (h = r.contentRef) == null ? void 0 : h.current) == null || g.focus({ preventScroll: !0 })), b.key === "Escape" && r.setOpen(!1), b.stopPropagation();
1571
1572
  }, d = (s = r.searchRef) == null ? void 0 : s.current;
1572
1573
  if (d)
1573
1574
  return d.addEventListener("keydown", c), () => {
1574
1575
  d.removeEventListener("keydown", c);
1575
1576
  };
1576
- }, [r]), /* @__PURE__ */ S(X, { borderBottom: !0, px: "1", pb: "1", children: [
1577
+ }, [r]), /* @__PURE__ */ T(X, { borderBottom: !0, px: "1", pb: "1", children: [
1577
1578
  /* @__PURE__ */ u(he.Root, { children: /* @__PURE__ */ u(P, { as: "label", htmlFor: i, children: o }) }),
1578
1579
  /* @__PURE__ */ u(
1579
1580
  fe,
@@ -1625,8 +1626,8 @@ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1625
1626
  );
1626
1627
  (l == null ? void 0 : l.length) === 0 ? n(!0) : n(!1);
1627
1628
  }, [i.searchQuery, i.contentRef, e]), r)
1628
- return /* @__PURE__ */ S(
1629
- T,
1629
+ return /* @__PURE__ */ T(
1630
+ S,
1630
1631
  {
1631
1632
  as: E.div,
1632
1633
  initial: { opacity: 0, scale: 0.8 },