@brightlocal/ui-components 2.10.0 → 2.11.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/README.md +3 -1
- package/component-meta.json +41 -9
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +42 -25
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -3
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +46 -49
- package/dist/button.cjs +1 -1
- package/dist/button.js +25 -25
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +10 -1
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +85 -82
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +13 -1
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +196 -150
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +101 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +383 -119
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +10 -10
- 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 +402 -391
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +1 -4
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +163 -170
- package/dist/map.cjs +1 -0
- package/dist/map.d.ts +192 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +250 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +32 -30
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +4 -0
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +101 -52
- package/package.json +3 -3
- package/src/blocks/sidebar.tsx +21 -26
- package/src/components/badge.tsx +22 -5
- package/src/components/button.tsx +13 -13
- package/src/components/card.tsx +35 -19
- package/src/components/carousel.tsx +101 -9
- package/src/components/command.tsx +637 -16
- package/src/components/input-chip.tsx +102 -65
- package/src/components/map.tsx +574 -0
- package/src/components/sonner.tsx +9 -3
- package/src/components/tabs.tsx +118 -22
- package/src/hooks/use-breakpoint.ts +2 -3
- package/src/index.ts +1 -0
|
@@ -47,6 +47,18 @@ interface CarouselProps extends React.ComponentProps<"div"> {
|
|
|
47
47
|
* Callback to receive the carousel API instance
|
|
48
48
|
*/
|
|
49
49
|
setApi?: (api: CarouselApi) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Enable lazy loading to only mount slides near the viewport.
|
|
52
|
+
* Off-screen slide children are not rendered until they scroll into view.
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
lazyLoad?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Number of off-screen slides to pre-render on each side of the viewport.
|
|
58
|
+
* Only applies when `lazyLoad` is enabled.
|
|
59
|
+
* @default 1
|
|
60
|
+
*/
|
|
61
|
+
overscan?: number;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
type CarouselContextProps = {
|
|
@@ -60,6 +72,8 @@ type CarouselContextProps = {
|
|
|
60
72
|
plugins?: CarouselPlugin;
|
|
61
73
|
orientation?: "horizontal" | "vertical";
|
|
62
74
|
setApi?: (api: CarouselApi) => void;
|
|
75
|
+
lazyLoad: boolean;
|
|
76
|
+
loadedSlides: Set<number>;
|
|
63
77
|
};
|
|
64
78
|
|
|
65
79
|
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
@@ -90,6 +104,8 @@ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
|
|
|
90
104
|
dataHook,
|
|
91
105
|
trackingEl,
|
|
92
106
|
trackingLabel,
|
|
107
|
+
lazyLoad = false,
|
|
108
|
+
overscan = 1,
|
|
93
109
|
...props
|
|
94
110
|
},
|
|
95
111
|
ref
|
|
@@ -103,6 +119,20 @@ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
|
|
|
103
119
|
);
|
|
104
120
|
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
105
121
|
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
122
|
+
const safeOverscan = Math.max(0, Math.floor(overscan));
|
|
123
|
+
const [loadedSlides, setLoadedSlides] = React.useState<Set<number>>(() => {
|
|
124
|
+
if (!lazyLoad) return new Set<number>();
|
|
125
|
+
const startIndex = opts?.startIndex ?? 0;
|
|
126
|
+
const initial = new Set<number>();
|
|
127
|
+
for (
|
|
128
|
+
let i = Math.max(0, startIndex - safeOverscan);
|
|
129
|
+
i <= startIndex + safeOverscan;
|
|
130
|
+
i++
|
|
131
|
+
) {
|
|
132
|
+
initial.add(i);
|
|
133
|
+
}
|
|
134
|
+
return initial;
|
|
135
|
+
});
|
|
106
136
|
|
|
107
137
|
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
108
138
|
if (!api) return;
|
|
@@ -152,6 +182,40 @@ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
|
|
|
152
182
|
};
|
|
153
183
|
}, [api, onSelect]);
|
|
154
184
|
|
|
185
|
+
const updateLoadedSlides = React.useCallback(
|
|
186
|
+
(emblaApi: CarouselApi) => {
|
|
187
|
+
if (!emblaApi || !lazyLoad) return;
|
|
188
|
+
const inView = emblaApi.slidesInView();
|
|
189
|
+
const slideCount = emblaApi.slideNodes().length;
|
|
190
|
+
setLoadedSlides((prev) => {
|
|
191
|
+
const next = new Set(prev);
|
|
192
|
+
for (const index of inView) {
|
|
193
|
+
const lo = Math.max(0, index - safeOverscan);
|
|
194
|
+
const hi = Math.min(slideCount - 1, index + safeOverscan);
|
|
195
|
+
for (let i = lo; i <= hi; i++) {
|
|
196
|
+
next.add(i);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (next.size === prev.size) return prev;
|
|
200
|
+
return next;
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
[lazyLoad, safeOverscan]
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
React.useEffect(() => {
|
|
207
|
+
if (!api || !lazyLoad) return;
|
|
208
|
+
updateLoadedSlides(api);
|
|
209
|
+
api.on("slidesInView", updateLoadedSlides);
|
|
210
|
+
api.on("select", updateLoadedSlides);
|
|
211
|
+
api.on("reInit", updateLoadedSlides);
|
|
212
|
+
return () => {
|
|
213
|
+
api.off("slidesInView", updateLoadedSlides);
|
|
214
|
+
api.off("select", updateLoadedSlides);
|
|
215
|
+
api.off("reInit", updateLoadedSlides);
|
|
216
|
+
};
|
|
217
|
+
}, [api, lazyLoad, updateLoadedSlides]);
|
|
218
|
+
|
|
155
219
|
return (
|
|
156
220
|
<CarouselContext.Provider
|
|
157
221
|
value={{
|
|
@@ -164,6 +228,8 @@ const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
|
|
|
164
228
|
scrollNext,
|
|
165
229
|
canScrollPrev,
|
|
166
230
|
canScrollNext,
|
|
231
|
+
lazyLoad,
|
|
232
|
+
loadedSlides,
|
|
167
233
|
}}
|
|
168
234
|
>
|
|
169
235
|
<div
|
|
@@ -193,17 +259,30 @@ Carousel.displayName = "Carousel";
|
|
|
193
259
|
const CarouselContent = React.forwardRef<
|
|
194
260
|
HTMLDivElement,
|
|
195
261
|
React.ComponentProps<"div">
|
|
196
|
-
>(({ className, ...props }, ref) => {
|
|
197
|
-
const { carouselRef, orientation } = useCarousel();
|
|
262
|
+
>(({ className, children, ...props }, ref) => {
|
|
263
|
+
const { carouselRef, orientation, lazyLoad } = useCarousel();
|
|
198
264
|
const isVertical = orientation === "vertical";
|
|
199
265
|
|
|
266
|
+
let slideIndex = 0;
|
|
267
|
+
const processedChildren = lazyLoad
|
|
268
|
+
? React.Children.map(children, (child) => {
|
|
269
|
+
if (React.isValidElement(child) && child.type === CarouselItem) {
|
|
270
|
+
const idx = slideIndex++;
|
|
271
|
+
return React.cloneElement(
|
|
272
|
+
child as React.ReactElement<{ _lazyIndex?: number }>,
|
|
273
|
+
{ _lazyIndex: idx }
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
return child;
|
|
277
|
+
})
|
|
278
|
+
: children;
|
|
279
|
+
|
|
200
280
|
return (
|
|
201
281
|
<div
|
|
202
282
|
ref={carouselRef}
|
|
203
283
|
className={cn("overflow-hidden", isVertical && "w-full", className)}
|
|
204
284
|
data-slot="carousel-content"
|
|
205
285
|
>
|
|
206
|
-
{/* Negative margins offset the positive padding on CarouselItem children (pt-4/pl-4) to create consistent gaps */}
|
|
207
286
|
<div
|
|
208
287
|
ref={ref}
|
|
209
288
|
className={cn(
|
|
@@ -211,21 +290,29 @@ const CarouselContent = React.forwardRef<
|
|
|
211
290
|
isVertical ? "-mt-4 h-full w-full flex-col" : "-ml-4"
|
|
212
291
|
)}
|
|
213
292
|
{...props}
|
|
214
|
-
|
|
293
|
+
>
|
|
294
|
+
{processedChildren}
|
|
295
|
+
</div>
|
|
215
296
|
</div>
|
|
216
297
|
);
|
|
217
298
|
});
|
|
218
299
|
|
|
219
300
|
CarouselContent.displayName = "CarouselContent";
|
|
220
301
|
|
|
302
|
+
type CarouselItemInternalProps = React.ComponentProps<"div"> & {
|
|
303
|
+
_lazyIndex?: number;
|
|
304
|
+
};
|
|
305
|
+
|
|
221
306
|
/**
|
|
222
307
|
* Individual slide item within the carousel.
|
|
223
308
|
*/
|
|
224
309
|
const CarouselItem = React.forwardRef<
|
|
225
310
|
HTMLDivElement,
|
|
226
|
-
|
|
227
|
-
>(({ className, ...props }, ref) => {
|
|
228
|
-
const { orientation } = useCarousel();
|
|
311
|
+
CarouselItemInternalProps
|
|
312
|
+
>(({ className, children, _lazyIndex, ...props }, ref) => {
|
|
313
|
+
const { orientation, lazyLoad, loadedSlides } = useCarousel();
|
|
314
|
+
const isLoaded =
|
|
315
|
+
!lazyLoad || _lazyIndex === undefined || loadedSlides.has(_lazyIndex);
|
|
229
316
|
|
|
230
317
|
return (
|
|
231
318
|
<div
|
|
@@ -236,12 +323,17 @@ const CarouselItem = React.forwardRef<
|
|
|
236
323
|
orientation === "horizontal" ? "pl-4" : "w-full pt-4",
|
|
237
324
|
className
|
|
238
325
|
)}
|
|
326
|
+
data-lazy-loaded={lazyLoad ? String(isLoaded) : undefined}
|
|
239
327
|
data-slot="carousel-item"
|
|
240
328
|
role="group"
|
|
241
329
|
{...props}
|
|
242
|
-
|
|
330
|
+
>
|
|
331
|
+
{isLoaded ? children : null}
|
|
332
|
+
</div>
|
|
243
333
|
);
|
|
244
|
-
})
|
|
334
|
+
}) as React.ForwardRefExoticComponent<
|
|
335
|
+
React.ComponentPropsWithoutRef<"div"> & React.RefAttributes<HTMLDivElement>
|
|
336
|
+
>;
|
|
245
337
|
|
|
246
338
|
CarouselItem.displayName = "CarouselItem";
|
|
247
339
|
|