@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/component-meta.json +2 -1
- package/dist/combobox.cjs +4 -1
- package/dist/combobox.d.ts +74 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +469 -199
- package/dist/index.cjs +1 -1
- package/dist/index.js +378 -376
- package/dist/resizable.d.ts +1 -1
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +52 -1
- package/dist/split-layout.d.ts.map +1 -1
- package/dist/split-layout.js +82 -55
- package/package.json +1 -1
- package/src/components/combobox.tsx +621 -27
- package/src/components/split-layout.tsx +96 -2
package/dist/combobox.js
CHANGED
|
@@ -1,73 +1,105 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import * as
|
|
3
|
-
import { Check as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
16
|
+
return t;
|
|
15
17
|
}
|
|
16
|
-
function
|
|
17
|
-
value:
|
|
18
|
+
function Ee({
|
|
19
|
+
value: t,
|
|
18
20
|
onValueChange: o,
|
|
19
21
|
open: n,
|
|
20
|
-
onOpenChange:
|
|
22
|
+
onOpenChange: s,
|
|
21
23
|
shouldFilter: u = !0,
|
|
22
|
-
disabled:
|
|
23
|
-
itemToStringValue:
|
|
24
|
-
children:
|
|
24
|
+
disabled: b = !1,
|
|
25
|
+
itemToStringValue: d,
|
|
26
|
+
children: C
|
|
25
27
|
}) {
|
|
26
|
-
const [
|
|
28
|
+
const [w, k] = e.useState(""), [R, E] = e.useState(!1), [S, I] = e.useState(
|
|
27
29
|
() => /* @__PURE__ */ new Map()
|
|
28
|
-
),
|
|
29
|
-
(
|
|
30
|
-
p ||
|
|
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
|
-
[
|
|
33
|
-
),
|
|
34
|
-
(
|
|
35
|
-
|
|
34
|
+
[x, s]
|
|
35
|
+
), g = e.useCallback(
|
|
36
|
+
(r) => {
|
|
37
|
+
f || k(r), o?.(r);
|
|
36
38
|
},
|
|
37
|
-
[
|
|
38
|
-
),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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:
|
|
47
|
-
setOpen:
|
|
48
|
-
value:
|
|
49
|
-
onValueChange:
|
|
67
|
+
open: a,
|
|
68
|
+
setOpen: h,
|
|
69
|
+
value: v,
|
|
70
|
+
onValueChange: g,
|
|
50
71
|
shouldFilter: u,
|
|
51
|
-
disabled:
|
|
52
|
-
itemLabels:
|
|
53
|
-
registerItem:
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
k,
|
|
61
|
-
u,
|
|
62
|
-
c,
|
|
84
|
+
a,
|
|
85
|
+
h,
|
|
86
|
+
v,
|
|
63
87
|
g,
|
|
64
|
-
|
|
65
|
-
|
|
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__ */
|
|
100
|
+
return /* @__PURE__ */ c(H.Provider, { value: i, children: /* @__PURE__ */ c(Q, { open: a, onOpenChange: h, children: C }) });
|
|
69
101
|
}
|
|
70
|
-
const
|
|
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
|
-
]),
|
|
125
|
+
]), ie = e.forwardRef(
|
|
94
126
|
({
|
|
95
|
-
className:
|
|
127
|
+
className: t,
|
|
96
128
|
dataHook: o,
|
|
97
129
|
error: n,
|
|
98
|
-
trackingEl:
|
|
130
|
+
trackingEl: s,
|
|
99
131
|
trackingLabel: u,
|
|
100
|
-
children:
|
|
101
|
-
...
|
|
102
|
-
},
|
|
103
|
-
const { open:
|
|
104
|
-
return /* @__PURE__ */
|
|
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:
|
|
108
|
-
"aria-controls":
|
|
109
|
-
"aria-expanded":
|
|
139
|
+
ref: C,
|
|
140
|
+
"aria-controls": w ? E : void 0,
|
|
141
|
+
"aria-expanded": w,
|
|
110
142
|
"aria-haspopup": "listbox",
|
|
111
|
-
"aria-invalid":
|
|
112
|
-
className:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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":
|
|
150
|
+
"data-placeholder": S,
|
|
119
151
|
"data-slot": "combobox-trigger",
|
|
120
|
-
"data-state":
|
|
121
|
-
"data-tracking-el":
|
|
152
|
+
"data-state": w ? "open" : "closed",
|
|
153
|
+
"data-tracking-el": s || "combobox-trigger",
|
|
122
154
|
"data-tracking-label": u,
|
|
123
|
-
disabled:
|
|
155
|
+
disabled: k || d.disabled,
|
|
124
156
|
role: "combobox",
|
|
125
157
|
type: "button",
|
|
126
|
-
...
|
|
158
|
+
...d,
|
|
127
159
|
children: [
|
|
128
|
-
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
|
|
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
|
-
|
|
142
|
-
function
|
|
143
|
-
const { value: n, itemLabels:
|
|
144
|
-
return /* @__PURE__ */
|
|
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:
|
|
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
|
|
157
|
-
dataHook:
|
|
188
|
+
function Se({
|
|
189
|
+
dataHook: t,
|
|
158
190
|
className: o,
|
|
159
191
|
children: n,
|
|
160
|
-
align:
|
|
192
|
+
align: s = "start",
|
|
161
193
|
side: u = "bottom",
|
|
162
|
-
sideOffset:
|
|
163
|
-
avoidCollisions:
|
|
164
|
-
hideList:
|
|
194
|
+
sideOffset: b,
|
|
195
|
+
avoidCollisions: d,
|
|
196
|
+
hideList: C = !1
|
|
165
197
|
}) {
|
|
166
|
-
const { open:
|
|
198
|
+
const { open: w, shouldFilter: k, filterFn: R, itemToStringValue: E } = A(), [S, I] = e.useState(
|
|
167
199
|
null
|
|
168
|
-
),
|
|
169
|
-
if (
|
|
170
|
-
let
|
|
171
|
-
const x = (
|
|
172
|
-
|
|
173
|
-
},
|
|
174
|
-
x(
|
|
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
|
-
|
|
208
|
+
v.observe(m, {
|
|
177
209
|
attributes: !0,
|
|
178
210
|
attributeFilter: ["data-side"]
|
|
179
211
|
});
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
x(
|
|
212
|
+
let a = 0, h = 0;
|
|
213
|
+
a = requestAnimationFrame(() => {
|
|
214
|
+
h = requestAnimationFrame(() => {
|
|
215
|
+
x(m.getAttribute("data-side"));
|
|
184
216
|
});
|
|
185
|
-
}),
|
|
186
|
-
|
|
217
|
+
}), y.current = () => {
|
|
218
|
+
f = !0, v.disconnect(), cancelAnimationFrame(a), cancelAnimationFrame(h);
|
|
187
219
|
};
|
|
188
220
|
}, []);
|
|
189
|
-
|
|
190
|
-
if (!
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
return () => clearTimeout(
|
|
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
|
-
}, [
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
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:
|
|
204
|
-
align:
|
|
232
|
+
ref: p,
|
|
233
|
+
align: s,
|
|
205
234
|
"aria-label": "Options",
|
|
206
|
-
avoidCollisions:
|
|
207
|
-
className:
|
|
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:
|
|
213
|
-
sideOffset:
|
|
214
|
-
children: /* @__PURE__ */
|
|
215
|
-
|
|
242
|
+
side: S ?? u,
|
|
243
|
+
sideOffset: b,
|
|
244
|
+
children: /* @__PURE__ */ c(
|
|
245
|
+
V,
|
|
216
246
|
{
|
|
217
|
-
className:
|
|
247
|
+
className: L(
|
|
218
248
|
"min-h-0 flex-1 border-0 shadow-none",
|
|
219
249
|
"[&_[data-slot='command-input-wrapper']]:shrink-0",
|
|
220
|
-
|
|
250
|
+
C && "[&_[data-slot='command-input-wrapper']]:border-b-0"
|
|
221
251
|
),
|
|
222
252
|
"data-slot": "combobox-command",
|
|
223
|
-
dataHook:
|
|
224
|
-
filter:
|
|
225
|
-
shouldFilter:
|
|
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
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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:
|
|
303
|
+
className: L("min-h-0 flex-1", t),
|
|
239
304
|
"data-slot": "combobox-list",
|
|
240
305
|
...o
|
|
241
306
|
}
|
|
242
307
|
));
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
251
|
-
const
|
|
482
|
+
return t;
|
|
483
|
+
const s = new RegExp(
|
|
252
484
|
`(${o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
|
|
253
485
|
"gi"
|
|
254
|
-
), u =
|
|
255
|
-
return /* @__PURE__ */
|
|
256
|
-
(
|
|
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
|
|
491
|
+
const be = e.forwardRef(
|
|
260
492
|
({
|
|
261
|
-
value:
|
|
493
|
+
value: t,
|
|
262
494
|
label: o,
|
|
263
495
|
dataHook: n,
|
|
264
|
-
children:
|
|
496
|
+
children: s,
|
|
265
497
|
className: u,
|
|
266
|
-
highlight:
|
|
267
|
-
highlightClassName:
|
|
268
|
-
keywords:
|
|
269
|
-
...
|
|
270
|
-
},
|
|
271
|
-
const { value:
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}, [
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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:
|
|
288
|
-
className:
|
|
557
|
+
ref: k,
|
|
558
|
+
className: L("justify-between", u),
|
|
289
559
|
"data-slot": "combobox-item",
|
|
290
560
|
dataHook: n,
|
|
291
|
-
keywords:
|
|
292
|
-
value:
|
|
293
|
-
onSelect:
|
|
294
|
-
...
|
|
561
|
+
keywords: C ? [m, ...C] : [m],
|
|
562
|
+
value: t,
|
|
563
|
+
onSelect: v,
|
|
564
|
+
...w,
|
|
295
565
|
children: [
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
function
|
|
313
|
-
return /* @__PURE__ */
|
|
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-
|
|
317
|
-
|
|
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
|
-
|
|
589
|
+
t
|
|
321
590
|
),
|
|
322
591
|
"data-slot": "combobox-loading",
|
|
323
|
-
role: "
|
|
324
|
-
children: o || /* @__PURE__ */
|
|
325
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
};
|