@telegraph/combobox 0.0.3 → 0.0.5
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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +42 -40
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/Combobox/Combobox.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -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
|
|
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
|
|
8
|
-
import { useComposedRefs as
|
|
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
|
-
},
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
726
|
+
const n = p.useContext(Y);
|
|
727
727
|
return /* @__PURE__ */ u(
|
|
728
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
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,
|
|
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
|
-
|
|
1210
|
-
}, [
|
|
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:
|
|
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:
|
|
1238
|
+
onOpenChange: M,
|
|
1239
1239
|
modal: o,
|
|
1240
1240
|
...s
|
|
1241
1241
|
}
|
|
1242
1242
|
)
|
|
1243
1243
|
}
|
|
1244
1244
|
);
|
|
1245
|
-
},
|
|
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
|
-
},
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
1357
|
-
},
|
|
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
|
-
|
|
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(
|
|
1404
|
+
/* @__PURE__ */ u(Me, { size: o }),
|
|
1405
1405
|
/* @__PURE__ */ u(
|
|
1406
|
-
|
|
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
|
-
},
|
|
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 =
|
|
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);
|
|
@@ -1541,7 +1541,9 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1541
1541
|
return /* @__PURE__ */ u(
|
|
1542
1542
|
N.Button,
|
|
1543
1543
|
{
|
|
1544
|
+
type: "button",
|
|
1544
1545
|
onSelect: b,
|
|
1546
|
+
onKeyDown: b,
|
|
1545
1547
|
selected: e === null ? null : e ?? s,
|
|
1546
1548
|
onFocus: () => l(!0),
|
|
1547
1549
|
onBlur: () => l(!1),
|
|
@@ -1562,7 +1564,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1562
1564
|
...a
|
|
1563
1565
|
}) => {
|
|
1564
1566
|
var l;
|
|
1565
|
-
const i = p.useId(), r = p.useContext(w), n =
|
|
1567
|
+
const i = p.useId(), r = p.useContext(w), n = B(e, r.searchRef);
|
|
1566
1568
|
return p.useEffect(() => {
|
|
1567
1569
|
var s;
|
|
1568
1570
|
const c = (b) => {
|
|
@@ -1574,7 +1576,7 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1574
1576
|
d.removeEventListener("keydown", c);
|
|
1575
1577
|
};
|
|
1576
1578
|
}, [r]), /* @__PURE__ */ T(X, { borderBottom: !0, px: "1", pb: "1", children: [
|
|
1577
|
-
/* @__PURE__ */ u(he.Root, { children: /* @__PURE__ */ u(
|
|
1579
|
+
/* @__PURE__ */ u(he.Root, { children: /* @__PURE__ */ u(P, { as: "label", htmlFor: i, children: o }) }),
|
|
1578
1580
|
/* @__PURE__ */ u(
|
|
1579
1581
|
fe,
|
|
1580
1582
|
{
|
|
@@ -1586,9 +1588,9 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1586
1588
|
var d;
|
|
1587
1589
|
(d = r == null ? void 0 : r.setSearchQuery) == null || d.call(r, c.target.value);
|
|
1588
1590
|
},
|
|
1589
|
-
LeadingComponent: /* @__PURE__ */ u(
|
|
1591
|
+
LeadingComponent: /* @__PURE__ */ u(K, { icon: j.Search, alt: "Search Icon" }),
|
|
1590
1592
|
TrailingComponent: r != null && r.searchQuery && ((l = r == null ? void 0 : r.searchQuery) == null ? void 0 : l.length) > 0 ? /* @__PURE__ */ u(
|
|
1591
|
-
|
|
1593
|
+
D,
|
|
1592
1594
|
{
|
|
1593
1595
|
as: E.button,
|
|
1594
1596
|
initial: { opacity: 0 },
|
|
@@ -1640,8 +1642,8 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1640
1642
|
"data-tgph-combobox-empty": !0,
|
|
1641
1643
|
...a,
|
|
1642
1644
|
children: [
|
|
1643
|
-
o === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(
|
|
1644
|
-
t === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(
|
|
1645
|
+
o === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(K, { ...o }),
|
|
1646
|
+
t === null ? /* @__PURE__ */ u(W, {}) : /* @__PURE__ */ u(P, { as: "span", children: t })
|
|
1645
1647
|
]
|
|
1646
1648
|
}
|
|
1647
1649
|
);
|
|
@@ -1672,11 +1674,11 @@ const M = ce, _ = ["sm", "md", "lg", "xl", "2xl"], je = (o) => {
|
|
|
1672
1674
|
...i
|
|
1673
1675
|
}
|
|
1674
1676
|
);
|
|
1675
|
-
},
|
|
1676
|
-
Object.assign(
|
|
1677
|
+
}, Ke = {};
|
|
1678
|
+
Object.assign(Ke, {
|
|
1677
1679
|
Root: Qe,
|
|
1678
|
-
Trigger:
|
|
1679
|
-
Content:
|
|
1680
|
+
Trigger: Pe,
|
|
1681
|
+
Content: Be,
|
|
1680
1682
|
Options: Ne,
|
|
1681
1683
|
Option: se,
|
|
1682
1684
|
Search: ze,
|
|
@@ -1684,6 +1686,6 @@ Object.assign(Ye, {
|
|
|
1684
1686
|
Create: He
|
|
1685
1687
|
});
|
|
1686
1688
|
export {
|
|
1687
|
-
|
|
1689
|
+
Ke as Combobox
|
|
1688
1690
|
};
|
|
1689
1691
|
//# sourceMappingURL=index.mjs.map
|