@component-labs/ui 0.0.1

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.
Files changed (114) hide show
  1. package/dist/HMKTUWOU-DlOdK4rt.js +25 -0
  2. package/dist/HMKTUWOU-DlOdK4rt.js.map +1 -0
  3. package/dist/HOITXJDS-DBccNHOl.js +48 -0
  4. package/dist/HOITXJDS-DBccNHOl.js.map +1 -0
  5. package/dist/I7KWAPMF-CcAk8kiH.js +86 -0
  6. package/dist/I7KWAPMF-CcAk8kiH.js.map +1 -0
  7. package/dist/IQYAUKXT-CoP_Jrsi.js +546 -0
  8. package/dist/IQYAUKXT-CoP_Jrsi.js.map +1 -0
  9. package/dist/PZ3OL7I2-h7WHitqi.js +61 -0
  10. package/dist/PZ3OL7I2-h7WHitqi.js.map +1 -0
  11. package/dist/Provider.d.ts +8 -0
  12. package/dist/Provider.d.ts.map +1 -0
  13. package/dist/Q5W46E73-DjlVG3LH.js +353 -0
  14. package/dist/Q5W46E73-DjlVG3LH.js.map +1 -0
  15. package/dist/U6HHPQDW-BkT6kvCd.js +888 -0
  16. package/dist/U6HHPQDW-BkT6kvCd.js.map +1 -0
  17. package/dist/X6LNAU2F-DroCIVyL.js +1692 -0
  18. package/dist/X6LNAU2F-DroCIVyL.js.map +1 -0
  19. package/dist/Z32PU2LQ-CPSDShGU.js +1116 -0
  20. package/dist/Z32PU2LQ-CPSDShGU.js.map +1 -0
  21. package/dist/button.d.ts +4 -0
  22. package/dist/button.d.ts.map +1 -0
  23. package/dist/button.js +252 -0
  24. package/dist/button.js.map +1 -0
  25. package/dist/checkbox.d.ts +4 -0
  26. package/dist/checkbox.d.ts.map +1 -0
  27. package/dist/checkbox.js +210 -0
  28. package/dist/checkbox.js.map +1 -0
  29. package/dist/combobox.d.ts +4 -0
  30. package/dist/combobox.d.ts.map +1 -0
  31. package/dist/combobox.js +948 -0
  32. package/dist/combobox.js.map +1 -0
  33. package/dist/components/button/Button.d.ts +26 -0
  34. package/dist/components/button/Button.d.ts.map +1 -0
  35. package/dist/components/button/Button.docs.d.ts +4 -0
  36. package/dist/components/button/Button.docs.d.ts.map +1 -0
  37. package/dist/components/button/Button.showcase.d.ts +40 -0
  38. package/dist/components/button/Button.showcase.d.ts.map +1 -0
  39. package/dist/components/checkbox/Checkbox.d.ts +19 -0
  40. package/dist/components/checkbox/Checkbox.d.ts.map +1 -0
  41. package/dist/components/checkbox/Checkbox.docs.d.ts +4 -0
  42. package/dist/components/checkbox/Checkbox.docs.d.ts.map +1 -0
  43. package/dist/components/checkbox/Checkbox.showcase.d.ts +35 -0
  44. package/dist/components/checkbox/Checkbox.showcase.d.ts.map +1 -0
  45. package/dist/components/combobox/Combobox.d.ts +36 -0
  46. package/dist/components/combobox/Combobox.d.ts.map +1 -0
  47. package/dist/components/combobox/Combobox.docs.d.ts +4 -0
  48. package/dist/components/combobox/Combobox.docs.d.ts.map +1 -0
  49. package/dist/components/combobox/Combobox.showcase.d.ts +43 -0
  50. package/dist/components/combobox/Combobox.showcase.d.ts.map +1 -0
  51. package/dist/components/data-table/DataTable.d.ts +86 -0
  52. package/dist/components/data-table/DataTable.d.ts.map +1 -0
  53. package/dist/components/data-table/DataTable.docs.d.ts +4 -0
  54. package/dist/components/data-table/DataTable.docs.d.ts.map +1 -0
  55. package/dist/components/data-table/DataTable.showcase.d.ts +36 -0
  56. package/dist/components/data-table/DataTable.showcase.d.ts.map +1 -0
  57. package/dist/components/date-picker/date-picker.d.ts +1 -0
  58. package/dist/components/date-picker/date-picker.d.ts.map +1 -0
  59. package/dist/components/dialog/Dialog.d.ts +56 -0
  60. package/dist/components/dialog/Dialog.d.ts.map +1 -0
  61. package/dist/components/dialog/Dialog.docs.d.ts +4 -0
  62. package/dist/components/dialog/Dialog.docs.d.ts.map +1 -0
  63. package/dist/components/input/Input.d.ts +22 -0
  64. package/dist/components/input/Input.d.ts.map +1 -0
  65. package/dist/components/input/Input.docs.d.ts +4 -0
  66. package/dist/components/input/Input.docs.d.ts.map +1 -0
  67. package/dist/components/menu/Menu.d.ts +41 -0
  68. package/dist/components/menu/Menu.d.ts.map +1 -0
  69. package/dist/components/menu/Menu.docs.d.ts +4 -0
  70. package/dist/components/menu/Menu.docs.d.ts.map +1 -0
  71. package/dist/components/menu/Menu.showcase.d.ts +43 -0
  72. package/dist/components/menu/Menu.showcase.d.ts.map +1 -0
  73. package/dist/components/slider/date-picker.d.ts +1 -0
  74. package/dist/components/slider/date-picker.d.ts.map +1 -0
  75. package/dist/components/sub-menu/date-picker.d.ts +1 -0
  76. package/dist/components/sub-menu/date-picker.d.ts.map +1 -0
  77. package/dist/components/switch/Switch.d.ts +17 -0
  78. package/dist/components/switch/Switch.d.ts.map +1 -0
  79. package/dist/components/switch/Switch.docs.d.ts +4 -0
  80. package/dist/components/switch/Switch.docs.d.ts.map +1 -0
  81. package/dist/components/toast/date-picker.d.ts +1 -0
  82. package/dist/components/toast/date-picker.d.ts.map +1 -0
  83. package/dist/data-table.d.ts +4 -0
  84. package/dist/data-table.d.ts.map +1 -0
  85. package/dist/data-table.js +298 -0
  86. package/dist/data-table.js.map +1 -0
  87. package/dist/dialog.d.ts +4 -0
  88. package/dist/dialog.d.ts.map +1 -0
  89. package/dist/dialog.js +323 -0
  90. package/dist/dialog.js.map +1 -0
  91. package/dist/index.d.ts +27 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/input.d.ts +4 -0
  94. package/dist/input.d.ts.map +1 -0
  95. package/dist/input.js +230 -0
  96. package/dist/input.js.map +1 -0
  97. package/dist/lib/IntersectionObserver.d.ts +30 -0
  98. package/dist/lib/IntersectionObserver.d.ts.map +1 -0
  99. package/dist/lib/utils.d.ts +7 -0
  100. package/dist/lib/utils.d.ts.map +1 -0
  101. package/dist/menu.d.ts +4 -0
  102. package/dist/menu.d.ts.map +1 -0
  103. package/dist/menu.js +1335 -0
  104. package/dist/menu.js.map +1 -0
  105. package/dist/switch.d.ts +4 -0
  106. package/dist/switch.d.ts.map +1 -0
  107. package/dist/switch.js +194 -0
  108. package/dist/switch.js.map +1 -0
  109. package/dist/types/docs.d.ts +24 -0
  110. package/dist/types/docs.d.ts.map +1 -0
  111. package/dist/utils-BZvHF7th.js +2806 -0
  112. package/dist/utils-BZvHF7th.js.map +1 -0
  113. package/package.json +98 -0
  114. package/src/styles.css +91 -0
@@ -0,0 +1,948 @@
1
+ import { jsxs as re, jsx as V } from "react/jsx-runtime";
2
+ import { u as $e, C as Ge, a as Je, c as Qe, b as Xe, d as Ye } from "./IQYAUKXT-CoP_Jrsi.js";
3
+ import { u as te, a as Ze, b as Se, C as he, c as et, d as tt, e as nt, f as ot, g as rt, h as at, i as it, j as lt, k as ut, l as st } from "./X6LNAU2F-DroCIVyL.js";
4
+ import { f as J, c as Q, a as X, i as Y, u as ct, b as dt, g as ge, s as oe, n as mt, d as R, e as ft, h as ae, j as Ee, k as B, l as Pe, m as Ve, o as bt, p as we, q as ie, r as vt, t as xt, v as gt, w as le, x as pt, y as Ct, z as yt, A as St, B as ht, C as Et, D as Pt, E as Vt, F as T, G as wt, H as It, I as kt } from "./U6HHPQDW-BkT6kvCd.js";
5
+ import { s as z, u as At, a as Ot, m as Lt, p as Nt, t as Ft, c as Tt, b as $, d as Bt, e as Dt, f as ee } from "./Q5W46E73-DjlVG3LH.js";
6
+ import { useRef as H, useState as ue, useEffect as G, useMemo as Ie, Fragment as Rt, useCallback as Kt, useContext as Mt, createContext as ke, forwardRef as _t, startTransition as Ht } from "react";
7
+ import { u as jt } from "./HMKTUWOU-DlOdK4rt.js";
8
+ import { i as Ut, c as qt } from "./Z32PU2LQ-CPSDShGU.js";
9
+ import { c as pe, a as Ae } from "./utils-BZvHF7th.js";
10
+ var zt = "input";
11
+ function Ce(n, e, o) {
12
+ if (!o) return !1;
13
+ const i = n.find((r) => !r.disabled && r.value);
14
+ return (i == null ? void 0 : i.value) === e;
15
+ }
16
+ function ye(n, e) {
17
+ return !e || n == null ? !1 : (n = xt(n), e.length > n.length && e.toLowerCase().indexOf(n.toLowerCase()) === 0);
18
+ }
19
+ function Wt(n) {
20
+ return n.type === "input";
21
+ }
22
+ function $t(n) {
23
+ return n === "inline" || n === "list" || n === "both" || n === "none";
24
+ }
25
+ function Gt(n) {
26
+ const e = n.find((o) => {
27
+ var i;
28
+ return o.disabled ? !1 : ((i = o.element) == null ? void 0 : i.getAttribute("role")) !== "tab";
29
+ });
30
+ return e == null ? void 0 : e.id;
31
+ }
32
+ var Jt = Q(
33
+ function({
34
+ store: e,
35
+ focusable: o = !0,
36
+ autoSelect: i = !1,
37
+ getAutoSelectId: r,
38
+ setValueOnChange: y,
39
+ showMinLength: g = 0,
40
+ showOnChange: v,
41
+ showOnMouseDown: h,
42
+ showOnClick: f = h,
43
+ showOnKeyDown: s,
44
+ showOnKeyPress: O = s,
45
+ blurActiveItemOnClick: a,
46
+ setValueOnClick: u = !0,
47
+ moveOnKeyPress: x = !0,
48
+ autoComplete: m = "list",
49
+ ...b
50
+ }) {
51
+ const w = te();
52
+ e = e || w, Y(
53
+ e,
54
+ process.env.NODE_ENV !== "production" && "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
55
+ );
56
+ const d = H(null), [F, I] = ct(), E = H(!1), K = H(!1), L = e.useState(
57
+ (t) => t.virtualFocus && i
58
+ ), A = m === "inline" || m === "both", [j, W] = ue(A);
59
+ dt(() => {
60
+ A && W(!0);
61
+ }, [A]);
62
+ const l = e.useState("value"), S = H(void 0);
63
+ G(() => z(e, ["selectedValue", "activeId"], (t, c) => {
64
+ S.current = c.selectedValue;
65
+ }), []);
66
+ const P = e.useState((t) => {
67
+ var c;
68
+ if (A && j && !(t.activeValue && Array.isArray(t.selectedValue) && (t.selectedValue.includes(t.activeValue) || (c = S.current) != null && c.includes(t.activeValue))))
69
+ return t.activeValue;
70
+ }), U = e.useState("renderedItems"), M = e.useState("open"), _ = e.useState("contentElement"), Z = Ie(() => {
71
+ if (!A || !j) return l;
72
+ if (Ce(
73
+ U,
74
+ P,
75
+ L
76
+ )) {
77
+ if (ye(l, P)) {
78
+ const c = (P == null ? void 0 : P.slice(l.length)) || "";
79
+ return l + c;
80
+ }
81
+ return l;
82
+ }
83
+ return P || l;
84
+ }, [A, j, U, P, L, l]);
85
+ G(() => {
86
+ const t = d.current;
87
+ if (!t) return;
88
+ const c = () => W(!0);
89
+ return t.addEventListener("combobox-item-move", c), () => {
90
+ t.removeEventListener("combobox-item-move", c);
91
+ };
92
+ }, []), G(() => {
93
+ if (!A || !j || !P || !Ce(
94
+ U,
95
+ P,
96
+ L
97
+ ) || !ye(l, P)) return;
98
+ let c = mt;
99
+ return queueMicrotask(() => {
100
+ const p = d.current;
101
+ if (!p) return;
102
+ const { start: C, end: N } = ge(p), D = l.length, k = P.length;
103
+ oe(p, D, k), c = () => {
104
+ if (!ie(p)) return;
105
+ const { start: q, end: We } = ge(p);
106
+ q === D && We === k && oe(p, C, N);
107
+ };
108
+ }), () => c();
109
+ }, [
110
+ F,
111
+ A,
112
+ j,
113
+ P,
114
+ U,
115
+ L,
116
+ l
117
+ ]);
118
+ const Le = H(null), se = R(r), ce = H(null);
119
+ G(() => {
120
+ if (!M || !_) return;
121
+ const t = ft(_);
122
+ if (!t) return;
123
+ Le.current = t;
124
+ const c = () => {
125
+ E.current = !1;
126
+ }, p = () => {
127
+ if (!e || !E.current) return;
128
+ const { activeId: N } = e.getState();
129
+ N !== null && N !== ce.current && (E.current = !1);
130
+ }, C = { passive: !0, capture: !0 };
131
+ return t.addEventListener("wheel", c, C), t.addEventListener("touchmove", c, C), t.addEventListener("scroll", p, C), () => {
132
+ t.removeEventListener("wheel", c, !0), t.removeEventListener("touchmove", c, !0), t.removeEventListener("scroll", p, !0);
133
+ };
134
+ }, [M, _, e]), ae(() => {
135
+ l && (K.current || (E.current = !0));
136
+ }, [l]), ae(() => {
137
+ L !== "always" && M || (E.current = M);
138
+ }, [L, M]);
139
+ const de = e.useState("resetValueOnSelect");
140
+ Ee(() => {
141
+ var t, c;
142
+ const p = E.current;
143
+ if (!e || !M || !p && !de) return;
144
+ const { baseElement: C, contentElement: N, activeId: D } = e.getState();
145
+ if (!(C && !ie(C))) {
146
+ if (N != null && N.hasAttribute("data-placing")) {
147
+ const k = new MutationObserver(I);
148
+ return k.observe(N, { attributeFilter: ["data-placing"] }), () => k.disconnect();
149
+ }
150
+ if (L && p) {
151
+ const k = se(U), q = k !== void 0 ? k : (t = Gt(U)) != null ? t : e.first();
152
+ ce.current = q, e.move(q ?? null);
153
+ } else {
154
+ const k = (c = e.item(D || e.first())) == null ? void 0 : c.element;
155
+ k && "scrollIntoView" in k && k.scrollIntoView({ block: "nearest", inline: "nearest" });
156
+ }
157
+ }
158
+ }, [
159
+ e,
160
+ M,
161
+ F,
162
+ l,
163
+ L,
164
+ de,
165
+ se,
166
+ U
167
+ ]), G(() => {
168
+ if (!A) return;
169
+ const t = d.current;
170
+ if (!t) return;
171
+ const c = [t, _].filter(
172
+ (C) => !!C
173
+ ), p = (C) => {
174
+ c.every((N) => vt(C, N)) && (e == null || e.setValue(Z));
175
+ };
176
+ for (const C of c)
177
+ C.addEventListener("focusout", p);
178
+ return () => {
179
+ for (const C of c)
180
+ C.removeEventListener("focusout", p);
181
+ };
182
+ }, [A, _, e, Z]);
183
+ const ne = (t) => t.currentTarget.value.length >= g, me = b.onChange, Ne = B(v ?? ne), Fe = B(
184
+ // If the combobox is combined with tags, the value will be set by the tag
185
+ // input component.
186
+ y ?? !e.tag
187
+ ), Te = R((t) => {
188
+ if (me == null || me(t), t.defaultPrevented || !e) return;
189
+ const c = t.currentTarget, { value: p, selectionStart: C, selectionEnd: N } = c, D = t.nativeEvent;
190
+ if (E.current = !0, Wt(D) && (D.isComposing && (E.current = !1, K.current = !0), A)) {
191
+ const k = D.inputType === "insertText" || D.inputType === "insertCompositionText", q = C === p.length;
192
+ W(k && q);
193
+ }
194
+ if (Fe(t)) {
195
+ const k = p === e.getState().value;
196
+ e.setValue(p), queueMicrotask(() => {
197
+ oe(c, C, N);
198
+ }), A && L && k && I();
199
+ }
200
+ Ne(t) && e.show(), (!L || !E.current) && e.setActiveId(null);
201
+ }), fe = b.onCompositionEnd, Be = R((t) => {
202
+ E.current = !0, K.current = !1, fe == null || fe(t), !t.defaultPrevented && L && I();
203
+ }), be = b.onMouseDown, De = B(
204
+ a ?? (() => !!(e != null && e.getState().includesBaseElement))
205
+ ), Re = B(u), Ke = B(f ?? ne), Me = R((t) => {
206
+ be == null || be(t), !t.defaultPrevented && (t.button || t.ctrlKey || e && (De(t) && e.setActiveId(null), Re(t) && e.setValue(Z), Ke(t) && gt(t.currentTarget, "mouseup", e.show)));
207
+ }), ve = b.onKeyDown, _e = B(O ?? ne), He = R((t) => {
208
+ if (ve == null || ve(t), t.repeat || (E.current = !1), t.defaultPrevented || t.ctrlKey || t.altKey || t.shiftKey || t.metaKey || !e) return;
209
+ const { open: c } = e.getState();
210
+ c || (t.key === "ArrowUp" || t.key === "ArrowDown") && _e(t) && (t.preventDefault(), e.show());
211
+ }), xe = b.onBlur, je = R((t) => {
212
+ E.current = !1, xe == null || xe(t), t.defaultPrevented;
213
+ }), Ue = Pe(b.id), qe = $t(m) ? m : void 0, ze = e.useState((t) => t.activeId === null);
214
+ return b = {
215
+ id: Ue,
216
+ role: "combobox",
217
+ "aria-autocomplete": qe,
218
+ "aria-haspopup": bt(_, "listbox"),
219
+ "aria-expanded": M,
220
+ "aria-controls": _ == null ? void 0 : _.id,
221
+ "data-active-item": ze || void 0,
222
+ value: Z,
223
+ ...b,
224
+ ref: Ve(d, b.ref),
225
+ onChange: Te,
226
+ onCompositionEnd: Be,
227
+ onMouseDown: Me,
228
+ onKeyDown: He,
229
+ onBlur: je
230
+ }, b = $e({
231
+ store: e,
232
+ focusable: o,
233
+ ...b,
234
+ // Enable inline autocomplete when the user moves from the combobox input
235
+ // to an item.
236
+ moveOnKeyPress: (t) => we(x, t) ? !1 : (A && W(!0), !0)
237
+ }), b = Ze({ store: e, ...b }), { autoComplete: "off", ...b };
238
+ }
239
+ ), Qt = J(function(e) {
240
+ const o = Jt(e);
241
+ return X(zt, o);
242
+ }), Xt = "button", Yt = /* @__PURE__ */ re(
243
+ "svg",
244
+ {
245
+ "aria-hidden": "true",
246
+ display: "block",
247
+ viewBox: "0 0 16 16",
248
+ fill: "none",
249
+ stroke: "currentColor",
250
+ strokeLinecap: "round",
251
+ strokeLinejoin: "round",
252
+ strokeWidth: 1.5,
253
+ width: "1em",
254
+ height: "1em",
255
+ pointerEvents: "none",
256
+ children: [
257
+ /* @__PURE__ */ V("line", { x1: "5", y1: "5", x2: "11", y2: "11" }),
258
+ /* @__PURE__ */ V("line", { x1: "5", y1: "11", x2: "11", y2: "5" })
259
+ ]
260
+ }
261
+ ), Zt = Q(
262
+ function({ store: e, hideWhenEmpty: o, ...i }) {
263
+ const r = te();
264
+ e = e || r, Y(
265
+ e,
266
+ process.env.NODE_ENV !== "production" && "ComboboxCancel must receive a `store` prop or be wrapped in a ComboboxProvider component."
267
+ );
268
+ const y = i.onClick, g = R((f) => {
269
+ y == null || y(f), !f.defaultPrevented && (e == null || e.setValue(""), e == null || e.move(null));
270
+ }), v = e.useState((f) => {
271
+ var s;
272
+ return (s = f.baseElement) == null ? void 0 : s.id;
273
+ }), h = e.useState((f) => f.value === "");
274
+ return i = le(
275
+ i,
276
+ (f) => o && h ? /* @__PURE__ */ V(Rt, {}) : f,
277
+ [o, h]
278
+ ), i = {
279
+ children: Yt,
280
+ "aria-label": "Clear input",
281
+ // This aria-controls will ensure the combobox popup remains visible when
282
+ // this element gets focused. This logic is done in the ComboboxPopover
283
+ // component.
284
+ "aria-controls": v,
285
+ ...i,
286
+ onClick: g
287
+ }, i = jt(i), i;
288
+ }
289
+ ), en = J(function(e) {
290
+ const o = Zt(e);
291
+ return X(Xt, o);
292
+ }), tn = "div";
293
+ function nn(n, e) {
294
+ if (e != null)
295
+ return n == null ? !1 : Array.isArray(n) ? n.includes(e) : n === e;
296
+ }
297
+ function on(n) {
298
+ var e;
299
+ return (e = {
300
+ menu: "menuitem",
301
+ listbox: "option",
302
+ tree: "treeitem"
303
+ }[n]) != null ? e : "option";
304
+ }
305
+ var rn = Q(
306
+ function({
307
+ store: e,
308
+ value: o,
309
+ hideOnClick: i,
310
+ setValueOnClick: r,
311
+ selectValueOnClick: y = !0,
312
+ resetValueOnSelect: g,
313
+ focusOnHover: v = !1,
314
+ moveOnKeyPress: h = !0,
315
+ getItem: f,
316
+ ...s
317
+ }) {
318
+ var O;
319
+ const a = Se();
320
+ e = e || a, Y(
321
+ e,
322
+ process.env.NODE_ENV !== "production" && "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
323
+ );
324
+ const { resetValueOnSelectState: u, multiSelectable: x, selected: m } = At(e, {
325
+ resetValueOnSelectState: "resetValueOnSelect",
326
+ multiSelectable(l) {
327
+ return Array.isArray(l.selectedValue);
328
+ },
329
+ selected(l) {
330
+ return nn(l.selectedValue, o);
331
+ }
332
+ }), b = Kt(
333
+ (l) => {
334
+ const S = { ...l, value: o };
335
+ return f ? f(S) : S;
336
+ },
337
+ [o, f]
338
+ );
339
+ r = r ?? !x, i = i ?? (o != null && !x);
340
+ const w = s.onClick, d = B(r), F = B(y), I = B(
341
+ (O = g ?? u) != null ? O : x
342
+ ), E = B(i), K = R((l) => {
343
+ w == null || w(l), !l.defaultPrevented && (yt(l) || St(l) || (o != null && (F(l) && (I(l) && (e == null || e.resetValue()), e == null || e.setSelectedValue((S) => Array.isArray(S) ? S.includes(o) ? S.filter((P) => P !== o) : [...S, o] : o)), d(l) && (e == null || e.setValue(o))), E(l) && (e == null || e.hide())));
344
+ }), L = s.onKeyDown, A = R((l) => {
345
+ if (L == null || L(l), l.defaultPrevented) return;
346
+ const S = e == null ? void 0 : e.getState().baseElement;
347
+ if (!S || ie(S)) return;
348
+ (l.key.length === 1 || l.key === "Backspace" || l.key === "Delete") && (queueMicrotask(() => S.focus()), Ct(S) && (e == null || e.setValue(S.value)));
349
+ });
350
+ x && m != null && (s = {
351
+ "aria-selected": m,
352
+ ...s
353
+ }), s = le(
354
+ s,
355
+ (l) => /* @__PURE__ */ V(nt.Provider, { value: o, children: /* @__PURE__ */ V(ot.Provider, { value: m ?? !1, children: l }) }),
356
+ [o, m]
357
+ );
358
+ const j = Mt(he);
359
+ s = {
360
+ role: on(j),
361
+ children: o,
362
+ ...s,
363
+ onClick: K,
364
+ onKeyDown: A
365
+ };
366
+ const W = B(h);
367
+ return s = et({
368
+ store: e,
369
+ ...s,
370
+ getItem: b,
371
+ // Dispatch a custom event on the combobox input when moving to an item
372
+ // with the keyboard so the Combobox component can enable inline
373
+ // autocompletion.
374
+ moveOnKeyPress: (l) => {
375
+ if (!W(l)) return !1;
376
+ const S = new Event("combobox-item-move"), P = e == null ? void 0 : e.getState().baseElement;
377
+ return P == null || P.dispatchEvent(S), !0;
378
+ }
379
+ }), s = tt({ store: e, focusOnHover: v, ...s }), s;
380
+ }
381
+ ), an = pt(
382
+ J(function(e) {
383
+ const o = rn(e);
384
+ return X(tn, o);
385
+ })
386
+ ), ln = "div", Oe = Q(
387
+ function({ store: e, alwaysVisible: o, ...i }) {
388
+ const r = Se(!0), y = rt();
389
+ e = e || y;
390
+ const g = !!e && e === r;
391
+ Y(
392
+ e,
393
+ process.env.NODE_ENV !== "production" && "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
394
+ );
395
+ const v = H(null), h = Pe(i.id), f = e.useState("mounted"), s = Ut(f, i.hidden, o), O = s ? { ...i.style, display: "none" } : i.style, a = e.useState(
396
+ (I) => Array.isArray(I.selectedValue)
397
+ ), u = ht(v, "role", i.role), m = (u === "listbox" || u === "tree" || u === "grid") && a || void 0, [b, w] = ue(!1), d = e.useState("contentElement");
398
+ ae(() => {
399
+ if (!f) return;
400
+ const I = v.current;
401
+ if (!I || d !== I) return;
402
+ const E = () => {
403
+ w(!!I.querySelector("[role='listbox']"));
404
+ }, K = new MutationObserver(E);
405
+ return K.observe(I, {
406
+ subtree: !0,
407
+ childList: !0,
408
+ attributeFilter: ["role"]
409
+ }), E(), () => K.disconnect();
410
+ }, [f, d]), b || (i = {
411
+ role: "listbox",
412
+ "aria-multiselectable": m,
413
+ ...i
414
+ }), i = le(
415
+ i,
416
+ (I) => /* @__PURE__ */ V(at, { value: e, children: /* @__PURE__ */ V(he.Provider, { value: u, children: I }) }),
417
+ [e, u]
418
+ );
419
+ const F = h && (!r || !g) ? e.setContentElement : null;
420
+ return i = {
421
+ id: h,
422
+ hidden: s,
423
+ ...i,
424
+ ref: Ve(F, v, i.ref),
425
+ style: O
426
+ }, Et(i);
427
+ }
428
+ );
429
+ J(function(e) {
430
+ const o = Oe(e);
431
+ return X(ln, o);
432
+ });
433
+ var un = "div";
434
+ function sn(n, ...e) {
435
+ if (!n) return !1;
436
+ if ("id" in n) {
437
+ const o = e.filter(Boolean).map((i) => `[aria-controls~="${i}"]`).join(", ");
438
+ return o ? n.matches(o) : !1;
439
+ }
440
+ return !1;
441
+ }
442
+ var cn = Q(
443
+ function({
444
+ store: e,
445
+ modal: o,
446
+ tabIndex: i,
447
+ alwaysVisible: r,
448
+ autoFocusOnHide: y = !0,
449
+ hideOnInteractOutside: g = !0,
450
+ ...v
451
+ }) {
452
+ const h = te();
453
+ e = e || h, Y(
454
+ e,
455
+ process.env.NODE_ENV !== "production" && "ComboboxPopover must receive a `store` prop or be wrapped in a ComboboxProvider component."
456
+ );
457
+ const f = e.useState("baseElement"), s = H(!1), O = Ot(
458
+ e.tag,
459
+ (a) => a == null ? void 0 : a.renderedItems.length
460
+ );
461
+ return v = Oe({ store: e, alwaysVisible: r, ...v }), v = it({
462
+ store: e,
463
+ modal: o,
464
+ alwaysVisible: r,
465
+ backdrop: !1,
466
+ autoFocusOnShow: !1,
467
+ finalFocus: f,
468
+ preserveTabOrderAnchor: null,
469
+ unstable_treeSnapshotKey: O,
470
+ ...v,
471
+ // When the combobox popover is modal, we make sure to include the
472
+ // combobox input and all the combobox controls (cancel, disclosure) in
473
+ // the list of persistent elements so they make part of the modal context,
474
+ // allowing users to tab through them.
475
+ getPersistentElements() {
476
+ var a;
477
+ const u = ((a = v.getPersistentElements) == null ? void 0 : a.call(v)) || [];
478
+ if (!o || !e) return u;
479
+ const { contentElement: x, baseElement: m } = e.getState();
480
+ if (!m) return u;
481
+ const b = Pt(m), w = [];
482
+ if (x != null && x.id && w.push(`[aria-controls~="${x.id}"]`), m != null && m.id && w.push(`[aria-controls~="${m.id}"]`), !w.length) return [...u, m];
483
+ const d = w.join(","), F = b.querySelectorAll(d);
484
+ return [...u, ...F];
485
+ },
486
+ // The combobox popover should focus on the combobox input when it hides,
487
+ // unless the event was triggered by a click outside the popover, in which
488
+ // case the input shouldn't be re-focused.
489
+ autoFocusOnHide(a) {
490
+ return we(y, a) ? !1 : s.current ? (s.current = !1, !1) : !0;
491
+ },
492
+ // Make sure we don't hide the popover when the user interacts with the
493
+ // combobox cancel or the combobox disclosure buttons. They will have the
494
+ // aria-controls attribute pointing to either the combobox input or the
495
+ // combobox popover elements.
496
+ hideOnInteractOutside(a) {
497
+ var u, x;
498
+ const m = e == null ? void 0 : e.getState(), b = (u = m == null ? void 0 : m.contentElement) == null ? void 0 : u.id, w = (x = m == null ? void 0 : m.baseElement) == null ? void 0 : x.id;
499
+ if (sn(a.target, b, w)) return !1;
500
+ const d = typeof g == "function" ? g(a) : g;
501
+ return d && (s.current = a.type === "click"), d;
502
+ }
503
+ }), v;
504
+ }
505
+ ), dn = qt(
506
+ J(function(e) {
507
+ const o = cn(e);
508
+ return X(un, o);
509
+ }),
510
+ te
511
+ );
512
+ ke(null);
513
+ ke(
514
+ null
515
+ );
516
+ var mn = Vt(
517
+ [Je],
518
+ [Ge]
519
+ ), fn = mn.useContext, bn = It() && kt();
520
+ function vn({
521
+ tag: n,
522
+ ...e
523
+ } = {}) {
524
+ const o = Lt(e.store, Nt(n, ["value", "rtl"]));
525
+ Ft(e, o);
526
+ const i = n == null ? void 0 : n.getState(), r = o == null ? void 0 : o.getState(), y = T(
527
+ e.activeId,
528
+ r == null ? void 0 : r.activeId,
529
+ e.defaultActiveId,
530
+ null
531
+ ), g = Qe({
532
+ ...e,
533
+ activeId: y,
534
+ includesBaseElement: T(
535
+ e.includesBaseElement,
536
+ r == null ? void 0 : r.includesBaseElement,
537
+ !0
538
+ ),
539
+ orientation: T(
540
+ e.orientation,
541
+ r == null ? void 0 : r.orientation,
542
+ "vertical"
543
+ ),
544
+ focusLoop: T(e.focusLoop, r == null ? void 0 : r.focusLoop, !0),
545
+ focusWrap: T(e.focusWrap, r == null ? void 0 : r.focusWrap, !0),
546
+ virtualFocus: T(
547
+ e.virtualFocus,
548
+ r == null ? void 0 : r.virtualFocus,
549
+ !0
550
+ )
551
+ }), v = lt({
552
+ ...e,
553
+ placement: T(
554
+ e.placement,
555
+ r == null ? void 0 : r.placement,
556
+ "bottom-start"
557
+ )
558
+ }), h = T(
559
+ e.value,
560
+ r == null ? void 0 : r.value,
561
+ e.defaultValue,
562
+ ""
563
+ ), f = T(
564
+ e.selectedValue,
565
+ r == null ? void 0 : r.selectedValue,
566
+ i == null ? void 0 : i.values,
567
+ e.defaultSelectedValue,
568
+ ""
569
+ ), s = Array.isArray(f), O = {
570
+ ...g.getState(),
571
+ ...v.getState(),
572
+ value: h,
573
+ selectedValue: f,
574
+ resetValueOnSelect: T(
575
+ e.resetValueOnSelect,
576
+ r == null ? void 0 : r.resetValueOnSelect,
577
+ s
578
+ ),
579
+ resetValueOnHide: T(
580
+ e.resetValueOnHide,
581
+ r == null ? void 0 : r.resetValueOnHide,
582
+ s && !n
583
+ ),
584
+ activeValue: r == null ? void 0 : r.activeValue
585
+ }, a = Tt(O, g, v, o);
586
+ return bn && $(
587
+ a,
588
+ () => z(a, ["virtualFocus"], () => {
589
+ a.setState("virtualFocus", !1);
590
+ })
591
+ ), $(a, () => {
592
+ if (n)
593
+ return wt(
594
+ z(a, ["selectedValue"], (u) => {
595
+ Array.isArray(u.selectedValue) && n.setValues(u.selectedValue);
596
+ }),
597
+ z(n, ["values"], (u) => {
598
+ a.setState("selectedValue", u.values);
599
+ })
600
+ );
601
+ }), $(
602
+ a,
603
+ () => z(a, ["resetValueOnHide", "mounted"], (u) => {
604
+ u.resetValueOnHide && (u.mounted || a.setState("value", h));
605
+ })
606
+ ), $(
607
+ a,
608
+ () => z(a, ["open"], (u) => {
609
+ u.open || (a.setState("activeId", y), a.setState("moves", 0));
610
+ })
611
+ ), $(
612
+ a,
613
+ () => z(a, ["moves", "activeId"], (u, x) => {
614
+ u.moves === x.moves && a.setState("activeValue", void 0);
615
+ })
616
+ ), $(
617
+ a,
618
+ () => Bt(a, ["moves", "renderedItems"], (u, x) => {
619
+ if (u.moves === x.moves) return;
620
+ const { activeId: m } = a.getState(), b = g.item(m);
621
+ a.setState("activeValue", b == null ? void 0 : b.value);
622
+ })
623
+ ), {
624
+ ...v,
625
+ ...g,
626
+ ...a,
627
+ tag: n,
628
+ setValue: (u) => a.setState("value", u),
629
+ resetValue: () => a.setState("value", O.value),
630
+ setSelectedValue: (u) => a.setState("selectedValue", u)
631
+ };
632
+ }
633
+ function xn(n) {
634
+ const e = fn();
635
+ return n = {
636
+ ...n,
637
+ tag: n.tag !== void 0 ? n.tag : e
638
+ }, Xe(n);
639
+ }
640
+ function gn(n, e, o) {
641
+ return Ee(e, [o.tag]), ee(n, o, "value", "setValue"), ee(n, o, "selectedValue", "setSelectedValue"), ee(n, o, "resetValueOnHide"), ee(n, o, "resetValueOnSelect"), Object.assign(
642
+ Ye(
643
+ ut(n, e, o),
644
+ e,
645
+ o
646
+ ),
647
+ { tag: o.tag }
648
+ );
649
+ }
650
+ function pn(n = {}) {
651
+ n = xn(n);
652
+ const [e, o] = Dt(vn, n);
653
+ return gn(e, o, n);
654
+ }
655
+ function Cn(n = {}) {
656
+ const e = pn(n);
657
+ return /* @__PURE__ */ V(st, { value: e, children: n.children });
658
+ }
659
+ const yn = Ae(
660
+ [
661
+ "w-full max-w-md rounded-lg border px-3 py-2",
662
+ "text-sm font-medium",
663
+ "transition-all duration-200",
664
+ "focus:outline-none focus:ring-2 focus:ring-primary-600 focus:ring-offset-2",
665
+ "disabled:cursor-not-allowed disabled:opacity-50",
666
+ "placeholder:text-gray-400 dark:placeholder:text-gray-500"
667
+ ],
668
+ {
669
+ variants: {
670
+ variant: {
671
+ default: [
672
+ "bg-white dark:bg-gray-900",
673
+ "border-gray-300 dark:border-gray-700",
674
+ "text-gray-900 dark:text-gray-100",
675
+ "hover:border-gray-400 dark:hover:border-gray-600"
676
+ ],
677
+ outline: [
678
+ "bg-transparent",
679
+ "border-primary-600 dark:border-primary-500",
680
+ "text-gray-900 dark:text-gray-100",
681
+ "hover:bg-primary-50 dark:hover:bg-primary-950"
682
+ ]
683
+ },
684
+ size: {
685
+ sm: "h-9 text-sm",
686
+ md: "h-10 text-base",
687
+ lg: "h-11 text-lg"
688
+ }
689
+ },
690
+ defaultVariants: {
691
+ variant: "default",
692
+ size: "md"
693
+ }
694
+ }
695
+ ), Sn = Ae(
696
+ [
697
+ "flex items-center gap-2 px-3 py-2 rounded-md",
698
+ "text-sm cursor-pointer",
699
+ "transition-colors duration-150",
700
+ "outline-none"
701
+ ],
702
+ {
703
+ variants: {
704
+ variant: {
705
+ default: [
706
+ "text-gray-900 dark:text-gray-100",
707
+ "hover:bg-gray-100 dark:hover:bg-gray-800",
708
+ "data-[active-item]:bg-primary-100 dark:data-[active-item]:bg-primary-900",
709
+ "data-[active-item]:text-primary-900 dark:data-[active-item]:text-primary-100"
710
+ ]
711
+ }
712
+ },
713
+ defaultVariants: {
714
+ variant: "default"
715
+ }
716
+ }
717
+ ), hn = _t(
718
+ ({
719
+ label: n,
720
+ options: e = [],
721
+ placeholder: o,
722
+ showClear: i = !0,
723
+ filterFn: r,
724
+ onValueChange: y,
725
+ onSelectOption: g,
726
+ emptyMessage: v = "No results found",
727
+ renderItem: h,
728
+ variant: f,
729
+ size: s,
730
+ className: O,
731
+ ...a
732
+ }, u) => {
733
+ const [x, m] = ue(""), b = (d, F) => F ? d.filter(
734
+ (I) => I.value.toLowerCase().includes(F.toLowerCase())
735
+ ) : d, w = Ie(() => (r || b)(e, x), [e, x, r]);
736
+ return /* @__PURE__ */ V(
737
+ Cn,
738
+ {
739
+ setValue: (d) => {
740
+ Ht(() => {
741
+ m(d), y == null || y(d);
742
+ });
743
+ },
744
+ children: /* @__PURE__ */ re("div", { className: "w-full space-y-2", children: [
745
+ n && /* @__PURE__ */ V("label", { className: "text-sm font-medium text-gray-900 dark:text-gray-100", children: n }),
746
+ /* @__PURE__ */ re("div", { className: "relative", children: [
747
+ /* @__PURE__ */ V(
748
+ Qt,
749
+ {
750
+ ref: u,
751
+ placeholder: o,
752
+ className: pe(yn({ variant: f, size: s, className: O })),
753
+ ...a
754
+ }
755
+ ),
756
+ i && x && /* @__PURE__ */ V(en, { className: "absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center rounded-md p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors", children: /* @__PURE__ */ V(
757
+ "svg",
758
+ {
759
+ width: "12",
760
+ height: "12",
761
+ viewBox: "0 0 12 12",
762
+ fill: "none",
763
+ stroke: "currentColor",
764
+ strokeWidth: "2",
765
+ strokeLinecap: "round",
766
+ children: /* @__PURE__ */ V("path", { d: "M4 4l8 8M12 4l-8 8" })
767
+ }
768
+ ) })
769
+ ] }),
770
+ /* @__PURE__ */ V(
771
+ dn,
772
+ {
773
+ gutter: 8,
774
+ sameWidth: !0,
775
+ className: pe(
776
+ "z-50 max-h-80 overflow-auto rounded-lg border bg-white p-1 shadow-lg dark:bg-gray-900 dark:border-gray-700",
777
+ "opacity-0 transition-all duration-200 ease-out",
778
+ "data-enter:opacity-100 data-enter:translate-y-0",
779
+ "data-leave:opacity-0 data-leave:-translate-y-1"
780
+ ),
781
+ children: w.length > 0 ? w.map((d) => /* @__PURE__ */ V(
782
+ an,
783
+ {
784
+ value: d.value,
785
+ disabled: d.disabled,
786
+ onClick: () => g == null ? void 0 : g(d.value),
787
+ className: Sn(),
788
+ children: h ? h(d) : d.label || d.value
789
+ },
790
+ d.value
791
+ )) : /* @__PURE__ */ V("div", { className: "px-3 py-2 text-center text-sm text-gray-500 dark:text-gray-400", children: v })
792
+ }
793
+ )
794
+ ] })
795
+ }
796
+ );
797
+ }
798
+ );
799
+ hn.displayName = "Combobox";
800
+ const Nn = {
801
+ name: "Combobox",
802
+ description: "Searchable select with autocomplete functionality, built on Ariakit for accessibility.",
803
+ category: "Navigation",
804
+ installation: "pnpm add @component-labs/ui",
805
+ usage: `import { Combobox } from "@component-labs/ui";
806
+
807
+ const options = [
808
+ { value: "apple", label: "Apple" },
809
+ { value: "banana", label: "Banana" },
810
+ ];
811
+
812
+ <Combobox options={options} placeholder="Select fruit..." />`,
813
+ props: [
814
+ {
815
+ name: "options",
816
+ type: "ComboboxOption[]",
817
+ description: "Array of options to display in the dropdown",
818
+ required: !0
819
+ },
820
+ {
821
+ name: "variant",
822
+ type: "'default' | 'outline'",
823
+ description: "Visual style variant",
824
+ default: "'default'"
825
+ },
826
+ {
827
+ name: "size",
828
+ type: "'sm' | 'md' | 'lg'",
829
+ description: "Size of the input",
830
+ default: "'md'"
831
+ },
832
+ {
833
+ name: "label",
834
+ type: "string",
835
+ description: "Label text above the combobox"
836
+ },
837
+ {
838
+ name: "placeholder",
839
+ type: "string",
840
+ description: "Placeholder text for the input"
841
+ },
842
+ {
843
+ name: "showClear",
844
+ type: "boolean",
845
+ description: "Show clear button when value is not empty",
846
+ default: "true"
847
+ },
848
+ {
849
+ name: "filterFn",
850
+ type: "(options: ComboboxOption[], searchValue: string) => ComboboxOption[]",
851
+ description: "Custom filter function for options"
852
+ },
853
+ {
854
+ name: "onValueChange",
855
+ type: "(value: string) => void",
856
+ description: "Callback when search value changes"
857
+ },
858
+ {
859
+ name: "onSelectOption",
860
+ type: "(value: string) => void",
861
+ description: "Callback when an option is selected"
862
+ },
863
+ {
864
+ name: "emptyMessage",
865
+ type: "string",
866
+ description: "Message to display when no results found",
867
+ default: "'No results found'"
868
+ },
869
+ {
870
+ name: "renderItem",
871
+ type: "(option: ComboboxOption) => ReactNode",
872
+ description: "Custom render function for items"
873
+ }
874
+ ],
875
+ examples: [
876
+ {
877
+ title: "Basic Combobox",
878
+ code: `const fruits = [
879
+ { value: "apple", label: "Apple" },
880
+ { value: "banana", label: "Banana" },
881
+ { value: "orange", label: "Orange" },
882
+ ];
883
+
884
+ <Combobox
885
+ label="Select a fruit"
886
+ placeholder="Search fruits..."
887
+ options={fruits}
888
+ />`,
889
+ description: "Simple searchable select"
890
+ },
891
+ {
892
+ title: "With Custom Filter",
893
+ code: `const customFilter = (options, search) => {
894
+ return options.filter(opt =>
895
+ opt.label.toLowerCase().startsWith(search.toLowerCase())
896
+ );
897
+ };
898
+
899
+ <Combobox
900
+ options={fruits}
901
+ filterFn={customFilter}
902
+ placeholder="Type to search..."
903
+ />`,
904
+ description: "Using custom filter logic"
905
+ },
906
+ {
907
+ title: "Controlled Selection",
908
+ code: `const [selected, setSelected] = useState("");
909
+
910
+ <Combobox
911
+ options={fruits}
912
+ onSelectOption={(value) => {
913
+ setSelected(value);
914
+ console.log("Selected:", value);
915
+ }}
916
+ placeholder="Choose..."
917
+ />`,
918
+ description: "Handle selection changes"
919
+ },
920
+ {
921
+ title: "Custom Item Rendering",
922
+ code: `<Combobox
923
+ options={users}
924
+ renderItem={(option) => (
925
+ <div className="flex items-center gap-2">
926
+ <Avatar src={option.avatar} />
927
+ <span>{option.label}</span>
928
+ </div>
929
+ )}
930
+ />`,
931
+ description: "Customize how items are rendered"
932
+ }
933
+ ],
934
+ accessibility: [
935
+ "Built on Ariakit's accessible Combobox component",
936
+ "Keyboard navigation (Arrow keys, Enter, Escape)",
937
+ "Proper ARIA attributes (aria-autocomplete, aria-expanded)",
938
+ "Screen reader support with announcements",
939
+ "Focus management",
940
+ "Type-ahead functionality"
941
+ ],
942
+ relatedComponents: ["Menu", "Command"]
943
+ };
944
+ export {
945
+ hn as Combobox,
946
+ Nn as comboboxDocs
947
+ };
948
+ //# sourceMappingURL=combobox.js.map