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