@telegraph/combobox 0.0.3 → 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,11 +1,11 @@
1
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
- import { Icon as Y, Lucide as j } from "@telegraph/icon";
4
+ import { Icon as K, Lucide as j } from "@telegraph/icon";
5
5
  import * as ye from "react";
6
6
  import p from "react";
7
- import { Text as B } from "@telegraph/typography";
8
- import { useComposedRefs as D } from "@telegraph/compose-refs";
7
+ import { Text as P } from "@telegraph/typography";
8
+ import { useComposedRefs as B } from "@telegraph/compose-refs";
9
9
  import { RefToTgphRef as re } from "@telegraph/helpers";
10
10
  import { Input as fe } from "@telegraph/input";
11
11
  import { Menu as N } from "@telegraph/menu";
@@ -630,7 +630,7 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
630
630
  }, _e = {
631
631
  default: "secondary",
632
632
  "icon-only": "primary"
633
- }, K = p.createContext({
633
+ }, Y = p.createContext({
634
634
  variant: "solid",
635
635
  size: "2",
636
636
  color: "gray",
@@ -659,7 +659,7 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
659
659
  return "default";
660
660
  }, [c == null ? void 0 : c.children]);
661
661
  return /* @__PURE__ */ u(
662
- K.Provider,
662
+ Y.Provider,
663
663
  {
664
664
  value: { variant: t, size: e, color: s, state: d, layout: b, active: r },
665
665
  children: /* @__PURE__ */ u(
@@ -700,13 +700,13 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
700
700
  "aria-hidden": r,
701
701
  ...n
702
702
  }) => {
703
- const l = p.useContext(K), c = {
703
+ const l = p.useContext(Y), c = {
704
704
  size: o ?? Ee[l.size],
705
705
  color: t ?? Oe[l.variant][l.color],
706
706
  variant: e ?? _e[l.layout]
707
707
  };
708
708
  return /* @__PURE__ */ u(
709
- Y,
709
+ K,
710
710
  {
711
711
  icon: a,
712
712
  "data-button-icon": !0,
@@ -723,9 +723,9 @@ const O = ["sm", "md", "lg", "xl", "2xl"], we = (o) => {
723
723
  className: i,
724
724
  ...r
725
725
  }) => {
726
- const n = p.useContext(K);
726
+ const n = p.useContext(Y);
727
727
  return /* @__PURE__ */ u(
728
- B,
728
+ P,
729
729
  {
730
730
  as: o || "span",
731
731
  color: t ?? Te[n.variant][n.color],
@@ -756,7 +756,7 @@ Object.assign(ce, {
756
756
  Icon: H,
757
757
  Text: le
758
758
  });
759
- const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
759
+ const D = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
760
760
  const t = [];
761
761
  let e = null;
762
762
  for (let a = 0; a < _.length; a++) {
@@ -1100,7 +1100,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1100
1100
  tgphRef: e,
1101
1101
  ...a
1102
1102
  }) => {
1103
- const i = o || "div", r = p.useRef(null), n = D(e, r), l = p.useMemo(() => {
1103
+ const i = o || "div", r = p.useRef(null), n = B(e, r), l = p.useMemo(() => {
1104
1104
  const c = { borderColor: !0, ...a };
1105
1105
  return Object.keys(c).reduce(
1106
1106
  (d, s) => (Object.keys(ee).some((b) => b === s) ? d.box[s] = c[s] : d.rest[s] = c[s], d),
@@ -1157,7 +1157,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1157
1157
  tgphRef: t,
1158
1158
  ...e
1159
1159
  }) => {
1160
- const a = p.useRef(null), i = D(t, a), r = p.useMemo(
1160
+ const a = p.useRef(null), i = B(t, a), r = p.useMemo(
1161
1161
  () => Object.keys(e).reduce(
1162
1162
  (n, l) => (Object.keys(te).some((c) => c === l) ? n.stack[l] = e[l] : n.rest[l] = e[l], n),
1163
1163
  { stack: {}, rest: {} }
@@ -1201,13 +1201,13 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1201
1201
  layout: d,
1202
1202
  ...s
1203
1203
  }) => {
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, P] = 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
1208
1208
  }), de = p.useCallback(() => {
1209
- P((ge) => !ge);
1210
- }, [P]);
1209
+ M((ge) => !ge);
1210
+ }, [M]);
1211
1211
  return p.useEffect(() => {
1212
1212
  L || C("");
1213
1213
  }, [L]), /* @__PURE__ */ u(
@@ -1220,7 +1220,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1220
1220
  onValueChange: n,
1221
1221
  placeholder: c,
1222
1222
  open: L,
1223
- setOpen: P,
1223
+ setOpen: M,
1224
1224
  onOpenToggle: de,
1225
1225
  closeOnSelect: t,
1226
1226
  searchQuery: k,
@@ -1235,14 +1235,14 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1235
1235
  N.Root,
1236
1236
  {
1237
1237
  open: L,
1238
- onOpenChange: P,
1238
+ onOpenChange: M,
1239
1239
  modal: o,
1240
1240
  ...s
1241
1241
  }
1242
1242
  )
1243
1243
  }
1244
1244
  );
1245
- }, Me = ({ label: o, value: t, ...e }) => {
1245
+ }, De = ({ label: o, value: t, ...e }) => {
1246
1246
  const a = p.useContext(w);
1247
1247
  return /* @__PURE__ */ T(
1248
1248
  z.Root,
@@ -1279,14 +1279,14 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1279
1279
  ]
1280
1280
  }
1281
1281
  );
1282
- }, Pe = ({
1282
+ }, Me = ({
1283
1283
  size: o = "1"
1284
1284
  }) => {
1285
1285
  var a, i;
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(S, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(M.Text, { color: "gray", children: t.placeholder }) }) : /* @__PURE__ */ 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
1290
  S,
1291
1291
  {
1292
1292
  gap: "1",
@@ -1301,7 +1301,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1301
1301
  children: [
1302
1302
  /* @__PURE__ */ u(F, { initial: !1, mode: "popLayout", children: r.map((d, s) => {
1303
1303
  if (n === "truncate" && s <= 1 || n === "wrap")
1304
- return /* @__PURE__ */ u(re, { children: /* @__PURE__ */ u(Me, { ...d }) }, d.value);
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
1307
  S,
@@ -1321,7 +1321,7 @@ const M = 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__ */ T(B, { 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,8 +1353,8 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1353
1353
  }
1354
1354
  );
1355
1355
  }
1356
- return /* @__PURE__ */ u(S, { h: e, align: "center", my: "1", children: /* @__PURE__ */ u(M.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
- }, Be = ({ size: o = "1", ...t }) => {
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
+ }, Pe = ({ size: o = "1", ...t }) => {
1358
1358
  const e = p.useContext(w), a = p.useCallback(() => {
1359
1359
  var i, r, n;
1360
1360
  return e.value ? q(e.value) ? ((i = e.value) == null ? void 0 : i.label) || ((r = e.value) == null ? void 0 : r.value) || e.placeholder : ((n = e.value) == null ? void 0 : n.map((l) => l.label).join(", ")) || e.placeholder : e.placeholder;
@@ -1384,7 +1384,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1384
1384
  },
1385
1385
  tgphRef: e.triggerRef,
1386
1386
  children: /* @__PURE__ */ u(re, { children: /* @__PURE__ */ T(
1387
- M.Root,
1387
+ D.Root,
1388
1388
  {
1389
1389
  id: e.triggerId,
1390
1390
  bg: "surface-1",
@@ -1401,9 +1401,9 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1401
1401
  "data-tgph-combobox-trigger": !0,
1402
1402
  "data-tgph-comobox-trigger-open": e.open,
1403
1403
  children: [
1404
- /* @__PURE__ */ u(Pe, { size: o }),
1404
+ /* @__PURE__ */ u(Me, { size: o }),
1405
1405
  /* @__PURE__ */ u(
1406
- M.Icon,
1406
+ D.Icon,
1407
1407
  {
1408
1408
  as: E.div,
1409
1409
  icon: j.ChevronDown,
@@ -1417,13 +1417,13 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1417
1417
  ) })
1418
1418
  }
1419
1419
  );
1420
- }, De = ({
1420
+ }, Be = ({
1421
1421
  tgphRef: o,
1422
1422
  style: t,
1423
1423
  children: e,
1424
1424
  ...a
1425
1425
  }) => {
1426
- const i = p.useContext(w), r = p.useRef(!1), n = D(o, i.contentRef), l = p.useRef(null), [c, d] = p.useState(0), [s, b] = p.useState(!1), h = 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
1428
  const y = g.getBoundingClientRect();
1429
1429
  y && d(y.height), s || b(!0);
@@ -1542,6 +1542,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1542
1542
  N.Button,
1543
1543
  {
1544
1544
  onSelect: b,
1545
+ onKeyDown: b,
1545
1546
  selected: e === null ? null : e ?? s,
1546
1547
  onFocus: () => l(!0),
1547
1548
  onBlur: () => l(!1),
@@ -1562,7 +1563,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1562
1563
  ...a
1563
1564
  }) => {
1564
1565
  var l;
1565
- const i = p.useId(), r = p.useContext(w), n = D(e, r.searchRef);
1566
+ const i = p.useId(), r = p.useContext(w), n = B(e, r.searchRef);
1566
1567
  return p.useEffect(() => {
1567
1568
  var s;
1568
1569
  const c = (b) => {
@@ -1574,7 +1575,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1574
1575
  d.removeEventListener("keydown", c);
1575
1576
  };
1576
1577
  }, [r]), /* @__PURE__ */ T(X, { borderBottom: !0, px: "1", pb: "1", children: [
1577
- /* @__PURE__ */ u(he.Root, { children: /* @__PURE__ */ u(B, { as: "label", htmlFor: i, children: o }) }),
1578
+ /* @__PURE__ */ u(he.Root, { children: /* @__PURE__ */ u(P, { as: "label", htmlFor: i, children: o }) }),
1578
1579
  /* @__PURE__ */ u(
1579
1580
  fe,
1580
1581
  {
@@ -1586,9 +1587,9 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1586
1587
  var d;
1587
1588
  (d = r == null ? void 0 : r.setSearchQuery) == null || d.call(r, c.target.value);
1588
1589
  },
1589
- LeadingComponent: /* @__PURE__ */ u(Y, { icon: j.Search, alt: "Search Icon" }),
1590
+ LeadingComponent: /* @__PURE__ */ u(K, { icon: j.Search, alt: "Search Icon" }),
1590
1591
  TrailingComponent: r != null && r.searchQuery && ((l = r == null ? void 0 : r.searchQuery) == null ? void 0 : l.length) > 0 ? /* @__PURE__ */ u(
1591
- M,
1592
+ D,
1592
1593
  {
1593
1594
  as: E.button,
1594
1595
  initial: { opacity: 0 },
@@ -1640,8 +1641,8 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1640
1641
  "data-tgph-combobox-empty": !0,
1641
1642
  ...a,
1642
1643
  children: [
1643
- o === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(Y, { ...o }),
1644
- t === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(B, { as: "span", children: t })
1644
+ o === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(K, { ...o }),
1645
+ t === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(P, { as: "span", children: t })
1645
1646
  ]
1646
1647
  }
1647
1648
  );
@@ -1672,11 +1673,11 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
1672
1673
  ...i
1673
1674
  }
1674
1675
  );
1675
- }, Ye = {};
1676
- Object.assign(Ye, {
1676
+ }, Ke = {};
1677
+ Object.assign(Ke, {
1677
1678
  Root: Qe,
1678
- Trigger: Be,
1679
- Content: De,
1679
+ Trigger: Pe,
1680
+ Content: Be,
1680
1681
  Options: Ne,
1681
1682
  Option: se,
1682
1683
  Search: ze,
@@ -1684,6 +1685,6 @@ Object.assign(Ye, {
1684
1685
  Create: He
1685
1686
  });
1686
1687
  export {
1687
- Ye as Combobox
1688
+ Ke as Combobox
1688
1689
  };
1689
1690
  //# sourceMappingURL=index.mjs.map