@brightlocal/ui-components 2.0.1 → 2.1.0

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/dist/combobox.js CHANGED
@@ -1,73 +1,105 @@
1
- import { jsx as a, jsxs as E, Fragment as A } from "react/jsx-runtime";
2
- import * as t from "react";
3
- import { Check as M, ChevronsUpDown as j } from "@brightlocal/icons";
4
- import { cva as O } from "class-variance-authority";
5
- import { defaultFilter as P } from "cmdk";
6
- import { cn as y } from "@brightlocal/ui-components/lib/utils";
7
- import { Popover as _, PopoverContent as G, PopoverTrigger as U } from "@brightlocal/ui-components/popover";
8
- import { Command as $, CommandEmpty as q, CommandGroup as z, CommandInput as D, CommandItem as H, CommandList as B, CommandSeparator as J } from "@brightlocal/ui-components/command";
9
- const F = t.createContext(null);
10
- function I() {
11
- const e = t.useContext(F);
12
- if (!e)
1
+ import { jsx as c, jsxs as _, Fragment as W } from "react/jsx-runtime";
2
+ import * as e from "react";
3
+ import { Check as G, ChevronsUpDown as Y } from "@brightlocal/icons";
4
+ import { useVirtualizer as B } from "@tanstack/react-virtual";
5
+ import { cva as J } from "class-variance-authority";
6
+ import { defaultFilter as U } from "cmdk";
7
+ import { cn as L } from "@brightlocal/ui-components/lib/utils";
8
+ import { useDevWarning as q } from "@brightlocal/ui-components/lib/use-dev-warning";
9
+ import { Popover as Q, PopoverContent as X, PopoverTrigger as Z } from "@brightlocal/ui-components/popover";
10
+ import { Command as V, CommandEmpty as ee, CommandGroup as te, CommandInput as oe, CommandItem as re, CommandList as ne, CommandSeparator as ae } from "@brightlocal/ui-components/command";
11
+ const H = e.createContext(null), K = e.createContext(null);
12
+ function A() {
13
+ const t = e.useContext(H);
14
+ if (!t)
13
15
  throw new Error("Combobox components must be used within a <Combobox>");
14
- return e;
16
+ return t;
15
17
  }
16
- function ue({
17
- value: e,
18
+ function Ee({
19
+ value: t,
18
20
  onValueChange: o,
19
21
  open: n,
20
- onOpenChange: r,
22
+ onOpenChange: s,
21
23
  shouldFilter: u = !0,
22
- disabled: c = !1,
23
- itemToStringValue: s,
24
- children: v
24
+ disabled: b = !1,
25
+ itemToStringValue: d,
26
+ children: C
25
27
  }) {
26
- const [b, C] = t.useState(""), [f, h] = t.useState(!1), [g, i] = t.useState(
28
+ const [w, k] = e.useState(""), [R, E] = e.useState(!1), [S, I] = e.useState(
27
29
  () => /* @__PURE__ */ new Map()
28
- ), w = e !== void 0, p = n !== void 0, d = w ? e : b, m = p ? n : f, x = t.useCallback(
29
- (l) => {
30
- p || h(l), r?.(l);
30
+ ), [y, p] = e.useState(""), [P, m] = e.useState(void 0), f = t !== void 0, x = n !== void 0, v = f ? t : w, a = x ? n : R, h = e.useCallback(
31
+ (r) => {
32
+ r || p(""), x || E(r), s?.(r);
31
33
  },
32
- [p, r]
33
- ), k = t.useCallback(
34
- (l) => {
35
- w || C(l), o?.(l);
34
+ [x, s]
35
+ ), g = e.useCallback(
36
+ (r) => {
37
+ f || k(r), o?.(r);
36
38
  },
37
- [w, o]
38
- ), N = t.useCallback((l, L) => {
39
- i((S) => {
40
- if (S.get(l) === L) return S;
41
- const T = new Map(S);
42
- return T.set(l, L), T;
43
- });
44
- }, []), R = t.useMemo(
39
+ [f, o]
40
+ ), D = e.useRef(/* @__PURE__ */ new Map()), F = e.useRef(!1), M = e.useRef(!0);
41
+ e.useEffect(() => () => {
42
+ M.current = !1;
43
+ }, []);
44
+ const T = e.useCallback(() => {
45
+ F.current || (F.current = !0, queueMicrotask(() => {
46
+ F.current = !1, M.current && I(new Map(D.current));
47
+ }));
48
+ }, []), $ = e.useCallback(
49
+ (r, l) => {
50
+ D.current.get(r) !== l && (D.current.set(r, l), T());
51
+ },
52
+ [T]
53
+ ), O = e.useRef(v);
54
+ e.useLayoutEffect(() => {
55
+ O.current = v;
56
+ }, [v]);
57
+ const z = e.useCallback(
58
+ (r) => {
59
+ r !== O.current && D.current.has(r) && (D.current.delete(r), T());
60
+ },
61
+ [T]
62
+ ), j = e.useMemo(
63
+ () => d ? (r, l, N) => U(d(r), l, N) : U,
64
+ [d]
65
+ ), i = e.useMemo(
45
66
  () => ({
46
- open: m,
47
- setOpen: x,
48
- value: d,
49
- onValueChange: k,
67
+ open: a,
68
+ setOpen: h,
69
+ value: v,
70
+ onValueChange: g,
50
71
  shouldFilter: u,
51
- disabled: c,
52
- itemLabels: g,
53
- registerItem: N,
54
- itemToStringValue: s
72
+ disabled: b,
73
+ itemLabels: S,
74
+ registerItem: $,
75
+ unregisterItem: z,
76
+ itemToStringValue: d,
77
+ filterFn: j,
78
+ searchValue: y,
79
+ setSearchValue: p,
80
+ activeDescendantId: P,
81
+ setActiveDescendantId: m
55
82
  }),
56
83
  [
57
- m,
58
- x,
59
- d,
60
- k,
61
- u,
62
- c,
84
+ a,
85
+ h,
86
+ v,
63
87
  g,
64
- N,
65
- s
88
+ u,
89
+ b,
90
+ S,
91
+ $,
92
+ z,
93
+ d,
94
+ j,
95
+ y,
96
+ P,
97
+ m
66
98
  ]
67
99
  );
68
- return /* @__PURE__ */ a(F.Provider, { value: R, children: /* @__PURE__ */ a(_, { open: m, onOpenChange: x, children: v }) });
100
+ return /* @__PURE__ */ c(H.Provider, { value: i, children: /* @__PURE__ */ c(Q, { open: a, onOpenChange: h, children: C }) });
69
101
  }
70
- const K = O([
102
+ const se = J([
71
103
  // Base layout
72
104
  "relative flex w-full items-center justify-between gap-2",
73
105
  "px-4 py-2 h-9",
@@ -90,44 +122,44 @@ const K = O([
90
122
  "transition-[background-color,border-color,box-shadow] duration-200 ease-out",
91
123
  // Icon styles
92
124
  "[&_svg]:pointer-events-none [&_svg]:shrink-0"
93
- ]), Q = t.forwardRef(
125
+ ]), ie = e.forwardRef(
94
126
  ({
95
- className: e,
127
+ className: t,
96
128
  dataHook: o,
97
129
  error: n,
98
- trackingEl: r,
130
+ trackingEl: s,
99
131
  trackingLabel: u,
100
- children: c,
101
- ...s
102
- }, v) => {
103
- const { open: b, disabled: C, value: f } = I(), h = t.useId(), g = !f, i = n || s["aria-invalid"] === !0 || s["aria-invalid"] === "true";
104
- return /* @__PURE__ */ a(U, { asChild: !0, children: /* @__PURE__ */ E(
132
+ children: b,
133
+ ...d
134
+ }, C) => {
135
+ const { open: w, disabled: k, value: R } = A(), E = e.useId(), S = !R, I = n || d["aria-invalid"] === !0 || d["aria-invalid"] === "true";
136
+ return /* @__PURE__ */ c(Z, { asChild: !0, children: /* @__PURE__ */ _(
105
137
  "button",
106
138
  {
107
- ref: v,
108
- "aria-controls": b ? h : void 0,
109
- "aria-expanded": b,
139
+ ref: C,
140
+ "aria-controls": w ? E : void 0,
141
+ "aria-expanded": w,
110
142
  "aria-haspopup": "listbox",
111
- "aria-invalid": i ? "true" : void 0,
112
- className: y(
113
- K(),
114
- i && "border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",
115
- e
143
+ "aria-invalid": I ? "true" : void 0,
144
+ className: L(
145
+ se(),
146
+ I && "border-destructive-40 dark:border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",
147
+ t
116
148
  ),
117
149
  "data-hook": o,
118
- "data-placeholder": g,
150
+ "data-placeholder": S,
119
151
  "data-slot": "combobox-trigger",
120
- "data-state": b ? "open" : "closed",
121
- "data-tracking-el": r || "combobox-trigger",
152
+ "data-state": w ? "open" : "closed",
153
+ "data-tracking-el": s || "combobox-trigger",
122
154
  "data-tracking-label": u,
123
- disabled: C || s.disabled,
155
+ disabled: k || d.disabled,
124
156
  role: "combobox",
125
157
  type: "button",
126
- ...s,
158
+ ...d,
127
159
  children: [
128
- c,
129
- /* @__PURE__ */ a(
130
- j,
160
+ b,
161
+ /* @__PURE__ */ c(
162
+ Y,
131
163
  {
132
164
  "aria-hidden": "true",
133
165
  className: "text-muted-foreground ml-auto shrink-0"
@@ -138,13 +170,13 @@ const K = O([
138
170
  ) });
139
171
  }
140
172
  );
141
- Q.displayName = "ComboboxTrigger";
142
- function ce({ placeholder: e, className: o }) {
143
- const { value: n, itemLabels: r } = I(), u = n ? r.get(n) || n : e;
144
- return /* @__PURE__ */ a(
173
+ ie.displayName = "ComboboxTrigger";
174
+ function Ne({ placeholder: t, className: o }) {
175
+ const { value: n, itemLabels: s } = A(), u = n ? s.get(n) || n : t;
176
+ return /* @__PURE__ */ c(
145
177
  "span",
146
178
  {
147
- className: y(
179
+ className: L(
148
180
  "text-foreground overflow-hidden text-sm leading-normal font-medium text-ellipsis whitespace-nowrap",
149
181
  o
150
182
  ),
@@ -153,149 +185,387 @@ function ce({ placeholder: e, className: o }) {
153
185
  }
154
186
  );
155
187
  }
156
- function le({
157
- dataHook: e,
188
+ function Se({
189
+ dataHook: t,
158
190
  className: o,
159
191
  children: n,
160
- align: r = "start",
192
+ align: s = "start",
161
193
  side: u = "bottom",
162
- sideOffset: c,
163
- avoidCollisions: s,
164
- hideList: v = !1
194
+ sideOffset: b,
195
+ avoidCollisions: d,
196
+ hideList: C = !1
165
197
  }) {
166
- const { open: b, shouldFilter: C, itemToStringValue: f } = I(), [h, g] = t.useState(
198
+ const { open: w, shouldFilter: k, filterFn: R, itemToStringValue: E } = A(), [S, I] = e.useState(
167
199
  null
168
- ), i = t.useRef(null), w = t.useCallback((d) => {
169
- if (i.current?.(), i.current = null, !d) return;
170
- let m = !1;
171
- const x = (l) => {
172
- m || (l === "top" || l === "bottom") && (m = !0, k.disconnect(), g(l));
173
- }, k = new MutationObserver(() => {
174
- x(d.getAttribute("data-side"));
200
+ ), y = e.useRef(null), p = e.useCallback((m) => {
201
+ if (y.current?.(), y.current = null, !m) return;
202
+ let f = !1;
203
+ const x = (g) => {
204
+ f || (g === "top" || g === "bottom") && (f = !0, v.disconnect(), I(g));
205
+ }, v = new MutationObserver(() => {
206
+ x(m.getAttribute("data-side"));
175
207
  });
176
- k.observe(d, {
208
+ v.observe(m, {
177
209
  attributes: !0,
178
210
  attributeFilter: ["data-side"]
179
211
  });
180
- let N = 0, R = 0;
181
- N = requestAnimationFrame(() => {
182
- R = requestAnimationFrame(() => {
183
- x(d.getAttribute("data-side"));
212
+ let a = 0, h = 0;
213
+ a = requestAnimationFrame(() => {
214
+ h = requestAnimationFrame(() => {
215
+ x(m.getAttribute("data-side"));
184
216
  });
185
- }), i.current = () => {
186
- m = !0, k.disconnect(), cancelAnimationFrame(N), cancelAnimationFrame(R);
217
+ }), y.current = () => {
218
+ f = !0, v.disconnect(), cancelAnimationFrame(a), cancelAnimationFrame(h);
187
219
  };
188
220
  }, []);
189
- t.useEffect(() => {
190
- if (!b) {
191
- i.current?.(), i.current = null;
192
- const d = setTimeout(() => g(null), 150);
193
- return () => clearTimeout(d);
221
+ e.useEffect(() => {
222
+ if (!w) {
223
+ y.current?.(), y.current = null;
224
+ const m = setTimeout(() => I(null), 150);
225
+ return () => clearTimeout(m);
194
226
  }
195
- }, [b]);
196
- const p = t.useMemo(() => {
197
- if (f)
198
- return (d, m, x) => P(f(d), m, x);
199
- }, [f]);
200
- return /* @__PURE__ */ a(
201
- G,
227
+ }, [w]);
228
+ const P = E ? R : void 0;
229
+ return /* @__PURE__ */ c(
230
+ X,
202
231
  {
203
- ref: w,
204
- align: r,
232
+ ref: p,
233
+ align: s,
205
234
  "aria-label": "Options",
206
- avoidCollisions: s,
207
- className: y(
235
+ avoidCollisions: d,
236
+ className: L(
208
237
  "flex max-h-[var(--radix-popover-content-available-height)] w-[var(--radix-popover-trigger-width)] flex-col overflow-hidden p-0",
209
238
  o
210
239
  ),
240
+ collisionPadding: 4,
211
241
  "data-slot": "combobox-popover",
212
- side: h ?? u,
213
- sideOffset: c,
214
- children: /* @__PURE__ */ a(
215
- $,
242
+ side: S ?? u,
243
+ sideOffset: b,
244
+ children: /* @__PURE__ */ c(
245
+ V,
216
246
  {
217
- className: y(
247
+ className: L(
218
248
  "min-h-0 flex-1 border-0 shadow-none",
219
249
  "[&_[data-slot='command-input-wrapper']]:shrink-0",
220
- v && "[&_[data-slot='command-input-wrapper']]:border-b-0"
250
+ C && "[&_[data-slot='command-input-wrapper']]:border-b-0"
221
251
  ),
222
252
  "data-slot": "combobox-command",
223
- dataHook: e || "combobox-command",
224
- filter: p,
225
- shouldFilter: C,
253
+ dataHook: t || "combobox-command",
254
+ filter: P,
255
+ shouldFilter: k,
226
256
  children: n
227
257
  }
228
258
  )
229
259
  }
230
260
  );
231
261
  }
232
- const V = t.forwardRef((e, o) => /* @__PURE__ */ a(D, { ref: o, "data-slot": "combobox-input", ...e }));
233
- V.displayName = "ComboboxInput";
234
- const W = t.forwardRef(({ className: e, ...o }, n) => /* @__PURE__ */ a(
235
- B,
262
+ const ce = e.forwardRef(({ debounceMs: t, onValueChange: o, ...n }, s) => {
263
+ const { setSearchValue: u, shouldFilter: b, activeDescendantId: d } = A(), C = e.useRef(
264
+ void 0
265
+ );
266
+ q(
267
+ () => !!(t && t > 0 && b),
268
+ `debounceMs is set on <ComboboxInput> but shouldFilter is true (default).
269
+ Debounce is designed for async/server-driven search where the consumer controls the items list.
270
+ Set shouldFilter={false} on <Combobox> for async search, or remove debounceMs for client-side filtering.`,
271
+ [t, b]
272
+ ), q(
273
+ () => !!(t && t > 0 && n.value !== void 0),
274
+ "debounceMs is set on <ComboboxInput> together with a controlled `value` prop.\nThe debounced onValueChange callback cannot update the controlled value synchronously, so the input will appear to lag behind typing.\nRemove `value` to let the input manage its own display, or remove debounceMs if you need a controlled input.",
275
+ [t, n.value]
276
+ ), e.useEffect(() => () => {
277
+ C.current && clearTimeout(C.current);
278
+ }, []);
279
+ const w = e.useCallback(
280
+ (k) => {
281
+ u(k), t && t > 0 ? (clearTimeout(C.current), C.current = setTimeout(() => {
282
+ o?.(k);
283
+ }, t)) : o?.(k);
284
+ },
285
+ [t, o, u]
286
+ );
287
+ return /* @__PURE__ */ c(
288
+ oe,
289
+ {
290
+ ref: s,
291
+ "aria-activedescendant": d,
292
+ "data-slot": "combobox-input",
293
+ onValueChange: w,
294
+ ...n
295
+ }
296
+ );
297
+ });
298
+ ce.displayName = "ComboboxInput";
299
+ const le = e.forwardRef(({ className: t, ...o }, n) => /* @__PURE__ */ c(
300
+ ne,
236
301
  {
237
302
  ref: n,
238
- className: y("min-h-0 flex-1", e),
303
+ className: L("min-h-0 flex-1", t),
239
304
  "data-slot": "combobox-list",
240
305
  ...o
241
306
  }
242
307
  ));
243
- W.displayName = "ComboboxList";
244
- const X = t.forwardRef((e, o) => /* @__PURE__ */ a(q, { ref: o, "data-slot": "combobox-empty", ...e }));
245
- X.displayName = "ComboboxEmpty";
246
- const Y = t.forwardRef((e, o) => /* @__PURE__ */ a(z, { ref: o, "data-slot": "combobox-group", ...e }));
247
- Y.displayName = "ComboboxGroup";
248
- function Z(e, o, n) {
308
+ le.displayName = "ComboboxList";
309
+ function ue({
310
+ items: t,
311
+ getItemValue: o,
312
+ getItemLabel: n,
313
+ estimateSize: s = 36,
314
+ overscan: u = 5,
315
+ children: b,
316
+ renderEmpty: d,
317
+ className: C,
318
+ dataHook: w
319
+ }, k) {
320
+ const R = e.useRef(null), {
321
+ value: E,
322
+ onValueChange: S,
323
+ setOpen: I,
324
+ shouldFilter: y,
325
+ searchValue: p,
326
+ filterFn: P,
327
+ setActiveDescendantId: m
328
+ } = A(), [f, x] = e.useState(0), v = e.useId();
329
+ e.useImperativeHandle(k, () => R.current, []);
330
+ const a = e.useMemo(() => {
331
+ if (!y || !p.trim()) return t;
332
+ const i = [];
333
+ for (const r of t) {
334
+ const l = n ? U(n(r), p) : P(o(r), p);
335
+ l > 0 && i.push({ item: r, score: l });
336
+ }
337
+ return i.sort((r, l) => l.score - r.score), i.map((r) => r.item);
338
+ }, [t, y, p, o, n, P]), h = B({
339
+ count: a.length,
340
+ getScrollElement: () => R.current,
341
+ estimateSize: () => s,
342
+ overscan: u
343
+ }), g = f >= 0 && f < a.length ? o(a[f]) : null;
344
+ e.useEffect(() => {
345
+ x(0);
346
+ }, [p, a.length]);
347
+ const D = e.useRef(!1);
348
+ e.useEffect(() => {
349
+ if (D.current || !E) return;
350
+ const i = a.findIndex((r) => o(r) === E);
351
+ i >= 0 && (x(i), h.scrollToIndex(i, { align: "center" }), D.current = !0);
352
+ }, [E, a, o, h]);
353
+ const F = e.useRef(!1);
354
+ e.useEffect(() => {
355
+ F.current && f >= 0 && f < a.length && h.scrollToIndex(f, { align: "auto" }), F.current = !1;
356
+ }, [f, a.length, h]), e.useEffect(() => {
357
+ const i = R.current?.closest(
358
+ '[data-slot="combobox-command"]'
359
+ );
360
+ if (!i) return;
361
+ const r = (l) => {
362
+ switch (l.key) {
363
+ case "ArrowDown":
364
+ l.preventDefault(), l.stopPropagation(), F.current = !0, x(
365
+ (N) => N < a.length - 1 ? N + 1 : N
366
+ );
367
+ break;
368
+ case "ArrowUp":
369
+ l.preventDefault(), l.stopPropagation(), F.current = !0, x((N) => N > 0 ? N - 1 : N);
370
+ break;
371
+ case "Enter":
372
+ if (l.preventDefault(), l.stopPropagation(), f >= 0 && f < a.length) {
373
+ const N = o(a[f]);
374
+ S(N === E ? "" : N), I(!1);
375
+ }
376
+ break;
377
+ case "Home":
378
+ l.preventDefault(), l.stopPropagation(), F.current = !0, x(0);
379
+ break;
380
+ case "End":
381
+ l.preventDefault(), l.stopPropagation(), F.current = !0, x(a.length - 1);
382
+ break;
383
+ }
384
+ };
385
+ return i.addEventListener("keydown", r, { capture: !0 }), () => i.removeEventListener("keydown", r, { capture: !0 });
386
+ }, [a, f, E, S, I, o]);
387
+ const M = e.useMemo(() => {
388
+ const i = /* @__PURE__ */ new Map();
389
+ return a.forEach((r, l) => {
390
+ i.set(o(r), l);
391
+ }), i;
392
+ }, [a, o]), T = e.useCallback(
393
+ (i) => {
394
+ const r = M.get(i);
395
+ r !== void 0 && x(r);
396
+ },
397
+ [M]
398
+ ), $ = e.useCallback(
399
+ (i) => (M.get(i) ?? 0) + 1,
400
+ [M]
401
+ ), O = a.length, z = e.useMemo(
402
+ () => ({
403
+ activeValue: g,
404
+ onItemPointerMove: T,
405
+ idPrefix: v,
406
+ filteredCount: O,
407
+ getItemPosition: $
408
+ }),
409
+ [g, T, v, O, $]
410
+ ), j = g != null ? `${v}item-${g}` : void 0;
411
+ return e.useEffect(() => (m(j), () => m(void 0)), [j, m]), a.length === 0 ? /* @__PURE__ */ c(
412
+ "div",
413
+ {
414
+ ref: R,
415
+ className: L(
416
+ "max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
417
+ C
418
+ ),
419
+ "data-hook": w,
420
+ "data-slot": "combobox-virtual-list",
421
+ role: "listbox",
422
+ children: d
423
+ }
424
+ ) : /* @__PURE__ */ c(K.Provider, { value: z, children: /* @__PURE__ */ c(
425
+ "div",
426
+ {
427
+ ref: R,
428
+ className: L(
429
+ "max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
430
+ C
431
+ ),
432
+ "data-hook": w,
433
+ "data-slot": "combobox-virtual-list",
434
+ role: "listbox",
435
+ children: /* @__PURE__ */ c(
436
+ "div",
437
+ {
438
+ className: "relative w-full",
439
+ style: { height: `${h.getTotalSize()}px` },
440
+ children: h.getVirtualItems().map((i) => /* @__PURE__ */ c(
441
+ "div",
442
+ {
443
+ ref: h.measureElement,
444
+ className: "absolute top-0 left-0 w-full px-2",
445
+ "data-index": i.index,
446
+ style: {
447
+ transform: `translateY(${i.start}px)`
448
+ },
449
+ children: b(a[i.index], i.index)
450
+ },
451
+ i.key
452
+ ))
453
+ }
454
+ )
455
+ }
456
+ ) });
457
+ }
458
+ const Pe = e.forwardRef(ue), de = e.forwardRef((t, o) => /* @__PURE__ */ c(ee, { ref: o, "data-slot": "combobox-empty", ...t }));
459
+ de.displayName = "ComboboxEmpty";
460
+ const fe = e.forwardRef(({ children: t, ...o }, n) => {
461
+ const s = e.useRef(null);
462
+ return q(
463
+ () => s.current ? s.current.querySelectorAll('[data-slot="combobox-item"]').length >= 100 : !1,
464
+ `ComboboxGroup contains 100+ items. Use <ComboboxVirtualList> for large datasets to avoid DOM bloat and slow renders.
465
+ Import: import { ComboboxVirtualList } from "@brightlocal/ui-components/combobox"`,
466
+ [t]
467
+ ), /* @__PURE__ */ c(
468
+ te,
469
+ {
470
+ ref: (u) => {
471
+ s.current = u, typeof n == "function" ? n(u) : n && (n.current = u);
472
+ },
473
+ "data-slot": "combobox-group",
474
+ ...o,
475
+ children: t
476
+ }
477
+ );
478
+ });
479
+ fe.displayName = "ComboboxGroup";
480
+ function me(t, o, n) {
249
481
  if (!o || !o.trim())
250
- return e;
251
- const r = new RegExp(
482
+ return t;
483
+ const s = new RegExp(
252
484
  `(${o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
253
485
  "gi"
254
- ), u = e.split(r);
255
- return /* @__PURE__ */ a("span", { children: u.map(
256
- (c, s) => s % 2 === 1 ? /* @__PURE__ */ a("span", { className: n, children: c }, s) : /* @__PURE__ */ a(t.Fragment, { children: c }, s)
486
+ ), u = t.split(s);
487
+ return /* @__PURE__ */ c("span", { children: u.map(
488
+ (b, d) => d % 2 === 1 ? /* @__PURE__ */ c("span", { className: n, children: b }, d) : /* @__PURE__ */ c(e.Fragment, { children: b }, d)
257
489
  ) });
258
490
  }
259
- const ee = t.forwardRef(
491
+ const be = e.forwardRef(
260
492
  ({
261
- value: e,
493
+ value: t,
262
494
  label: o,
263
495
  dataHook: n,
264
- children: r,
496
+ children: s,
265
497
  className: u,
266
- highlight: c,
267
- highlightClassName: s,
268
- keywords: v,
269
- ...b
270
- }, C) => {
271
- const { value: f, onValueChange: h, setOpen: g, registerItem: i } = I(), w = f === e, p = t.useMemo(() => o || (typeof r == "string" ? r : typeof r == "number" ? String(r) : e), [o, r, e]), d = t.useRef(i);
272
- t.useEffect(() => {
273
- d.current = i;
274
- }, [i]), t.useEffect(() => {
275
- d.current(e, p);
276
- }, [e, p]);
277
- const m = () => {
278
- h(e === f ? "" : e), g(!1);
279
- }, x = () => c && typeof r == "string" ? Z(
280
- r,
281
- c,
282
- s || "text-sm leading-normal font-semibold"
283
- ) : r;
284
- return /* @__PURE__ */ E(
285
- H,
498
+ highlight: b,
499
+ highlightClassName: d,
500
+ keywords: C,
501
+ ...w
502
+ }, k) => {
503
+ const { value: R, onValueChange: E, setOpen: S, registerItem: I, unregisterItem: y } = A(), p = e.useContext(K), P = R === t, m = e.useMemo(() => o || (typeof s == "string" ? s : typeof s == "number" ? String(s) : t), [o, s, t]), f = e.useRef(I), x = e.useRef(y);
504
+ e.useEffect(() => {
505
+ f.current = I, x.current = y;
506
+ }, [I, y]), e.useEffect(() => (f.current(t, m), () => x.current(t)), [t, m]);
507
+ const v = () => {
508
+ E(t === R ? "" : t), S(!1);
509
+ }, a = () => b && typeof s == "string" ? me(
510
+ s,
511
+ b,
512
+ d || "text-sm leading-normal font-semibold"
513
+ ) : s;
514
+ if (p) {
515
+ const h = p.activeValue === t, g = !!w.disabled;
516
+ return /* @__PURE__ */ _(
517
+ "div",
518
+ {
519
+ ref: k,
520
+ "aria-disabled": g || void 0,
521
+ "aria-posinset": p.getItemPosition(t),
522
+ "aria-selected": P,
523
+ "aria-setsize": p.filteredCount,
524
+ className: L(
525
+ "data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground relative flex cursor-default items-center justify-between gap-2 rounded-sm px-2 py-3 text-sm outline-hidden select-none",
526
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
527
+ g && "pointer-events-none opacity-50",
528
+ u
529
+ ),
530
+ "data-highlighted": h || void 0,
531
+ "data-hook": n,
532
+ "data-slot": "combobox-item",
533
+ id: `${p.idPrefix}item-${t}`,
534
+ role: "option",
535
+ tabIndex: -1,
536
+ onClick: g ? void 0 : v,
537
+ onKeyDown: g ? void 0 : (D) => {
538
+ (D.key === "Enter" || D.key === " ") && v();
539
+ },
540
+ onPointerMove: g ? void 0 : () => p.onItemPointerMove(t),
541
+ children: [
542
+ a(),
543
+ P && /* @__PURE__ */ c(
544
+ G,
545
+ {
546
+ "aria-hidden": "true",
547
+ className: "text-muted-foreground shrink-0"
548
+ }
549
+ )
550
+ ]
551
+ }
552
+ );
553
+ }
554
+ return /* @__PURE__ */ _(
555
+ re,
286
556
  {
287
- ref: C,
288
- className: y("justify-between", u),
557
+ ref: k,
558
+ className: L("justify-between", u),
289
559
  "data-slot": "combobox-item",
290
560
  dataHook: n,
291
- keywords: v ? [p, ...v] : [p],
292
- value: e,
293
- onSelect: m,
294
- ...b,
561
+ keywords: C ? [m, ...C] : [m],
562
+ value: t,
563
+ onSelect: v,
564
+ ...w,
295
565
  children: [
296
- x(),
297
- w && /* @__PURE__ */ a(
298
- M,
566
+ a(),
567
+ P && /* @__PURE__ */ c(
568
+ G,
299
569
  {
300
570
  "aria-hidden": "true",
301
571
  className: "text-muted-foreground shrink-0"
@@ -306,23 +576,22 @@ const ee = t.forwardRef(
306
576
  );
307
577
  }
308
578
  );
309
- ee.displayName = "ComboboxItem";
310
- const oe = t.forwardRef((e, o) => /* @__PURE__ */ a(J, { ref: o, "data-slot": "combobox-separator", ...e }));
311
- oe.displayName = "ComboboxSeparator";
312
- function me({ className: e, children: o }) {
313
- return /* @__PURE__ */ a(
579
+ be.displayName = "ComboboxItem";
580
+ const pe = e.forwardRef((t, o) => /* @__PURE__ */ c(ae, { ref: o, "data-slot": "combobox-separator", ...t }));
581
+ pe.displayName = "ComboboxSeparator";
582
+ function De({ className: t, children: o }) {
583
+ return /* @__PURE__ */ c(
314
584
  "div",
315
585
  {
316
- "aria-disabled": "true",
317
- "aria-selected": "false",
318
- className: y(
586
+ "aria-live": "polite",
587
+ className: L(
319
588
  "text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",
320
- e
589
+ t
321
590
  ),
322
591
  "data-slot": "combobox-loading",
323
- role: "option",
324
- children: o || /* @__PURE__ */ E(A, { children: [
325
- /* @__PURE__ */ a(
592
+ role: "status",
593
+ children: o || /* @__PURE__ */ _(W, { children: [
594
+ /* @__PURE__ */ c(
326
595
  "div",
327
596
  {
328
597
  "aria-hidden": "true",
@@ -335,15 +604,16 @@ function me({ className: e, children: o }) {
335
604
  );
336
605
  }
337
606
  export {
338
- ue as Combobox,
339
- le as ComboboxContent,
340
- X as ComboboxEmpty,
341
- Y as ComboboxGroup,
342
- V as ComboboxInput,
343
- ee as ComboboxItem,
344
- W as ComboboxList,
345
- me as ComboboxLoading,
346
- oe as ComboboxSeparator,
347
- Q as ComboboxTrigger,
348
- ce as ComboboxValue
607
+ Ee as Combobox,
608
+ Se as ComboboxContent,
609
+ de as ComboboxEmpty,
610
+ fe as ComboboxGroup,
611
+ ce as ComboboxInput,
612
+ be as ComboboxItem,
613
+ le as ComboboxList,
614
+ De as ComboboxLoading,
615
+ pe as ComboboxSeparator,
616
+ ie as ComboboxTrigger,
617
+ Ne as ComboboxValue,
618
+ Pe as ComboboxVirtualList
349
619
  };