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