@brightlocal/ui-components 2.2.0 → 2.4.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 +6 -5
- package/component-meta.json +531 -32
- 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 +1 -1
- package/dist/combobox.js +2 -2
- package/dist/command.cjs +1 -1
- package/dist/command.js +27 -27
- 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-chip.cjs +1 -1
- package/dist/input-chip.js +1 -1
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.js +1 -1
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.js +9 -9
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +6 -7
- package/dist/sheet.d.ts +1 -1
- package/dist/split-layout.cjs +1 -1
- package/dist/split-layout.d.ts +17 -3
- package/dist/split-layout.d.ts.map +1 -1
- package/dist/split-layout.js +86 -114
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.js +6 -6
- package/package.json +34 -10
- 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 +2 -2
- package/src/components/command.tsx +1 -1
- package/src/components/input-chip.tsx +1 -1
- package/src/components/input-group.tsx +1 -1
- package/src/components/input-otp.tsx +1 -1
- package/src/components/input.tsx +2 -3
- package/src/components/split-layout.tsx +27 -65
- package/src/components/textarea.tsx +1 -1
- package/src/index.ts +1 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
|
+
|
|
6
|
+
/** Available color variants for the Callout component */
|
|
7
|
+
type CalloutVariant = "primary" | "purple" | "blue" | "green";
|
|
8
|
+
|
|
9
|
+
/** Pointer/caret position for the Callout speech bubble */
|
|
10
|
+
type CalloutPointer = "top" | "bottom" | "left" | "right" | "none";
|
|
11
|
+
|
|
12
|
+
const calloutVariants = cva("relative rounded-2xl p-12 shadow-lg", {
|
|
13
|
+
variants: {
|
|
14
|
+
variant: {
|
|
15
|
+
primary: "bg-primary text-primary-foreground",
|
|
16
|
+
purple: "bg-violet-300 text-violet-950",
|
|
17
|
+
blue: "bg-sky-300 text-sky-950",
|
|
18
|
+
green: "bg-green-200 text-green-950",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
variant: "primary",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const citationColorMap: Record<CalloutVariant, string> = {
|
|
27
|
+
primary: "text-primary-foreground/80",
|
|
28
|
+
purple: "text-violet-800",
|
|
29
|
+
blue: "text-sky-900",
|
|
30
|
+
green: "text-green-900",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const pointerBgMap: Record<CalloutVariant, string> = {
|
|
34
|
+
primary: "bg-primary",
|
|
35
|
+
purple: "bg-violet-300",
|
|
36
|
+
blue: "bg-sky-300",
|
|
37
|
+
green: "bg-green-200",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const pointerPositionMap: Record<Exclude<CalloutPointer, "none">, string> = {
|
|
41
|
+
bottom: "left-1/2 -bottom-2 -translate-x-1/2",
|
|
42
|
+
top: "left-1/2 -top-2 -translate-x-1/2",
|
|
43
|
+
left: "top-1/2 -left-2 -translate-y-1/2",
|
|
44
|
+
right: "top-1/2 -right-2 -translate-y-1/2",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Context for sharing variant with sub-components */
|
|
48
|
+
const CalloutContext = React.createContext<{ variant: CalloutVariant }>({
|
|
49
|
+
variant: "primary",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/** Props for the Callout component */
|
|
53
|
+
interface CalloutProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
54
|
+
/** Required test hook identifier */
|
|
55
|
+
dataHook: string;
|
|
56
|
+
/**
|
|
57
|
+
* Color variant
|
|
58
|
+
* @default "primary"
|
|
59
|
+
*/
|
|
60
|
+
variant?: CalloutVariant;
|
|
61
|
+
/**
|
|
62
|
+
* Pointer/caret direction
|
|
63
|
+
* @default "bottom"
|
|
64
|
+
*/
|
|
65
|
+
pointer?: CalloutPointer;
|
|
66
|
+
/** Analytics element identifier */
|
|
67
|
+
trackingEl?: string;
|
|
68
|
+
/** Analytics label */
|
|
69
|
+
trackingLabel?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Speech bubble callout for highlighting key statements or quotes.
|
|
74
|
+
* Supports 4 color variants and configurable pointer direction.
|
|
75
|
+
*
|
|
76
|
+
* Use with `CalloutHeading` and optionally `CalloutCitation` as children.
|
|
77
|
+
*/
|
|
78
|
+
const Callout = React.forwardRef<HTMLDivElement, CalloutProps>(
|
|
79
|
+
(
|
|
80
|
+
{
|
|
81
|
+
className,
|
|
82
|
+
variant = "primary",
|
|
83
|
+
pointer = "bottom",
|
|
84
|
+
children,
|
|
85
|
+
dataHook,
|
|
86
|
+
trackingEl,
|
|
87
|
+
trackingLabel,
|
|
88
|
+
...props
|
|
89
|
+
},
|
|
90
|
+
ref
|
|
91
|
+
) => {
|
|
92
|
+
const contextValue = React.useMemo(() => ({ variant }), [variant]);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<CalloutContext.Provider value={contextValue}>
|
|
96
|
+
<div
|
|
97
|
+
ref={ref}
|
|
98
|
+
className={cn(calloutVariants({ variant }), className)}
|
|
99
|
+
data-hook={dataHook}
|
|
100
|
+
data-slot="callout"
|
|
101
|
+
data-tracking-el={trackingEl || `callout-${variant}`}
|
|
102
|
+
data-tracking-label={trackingLabel}
|
|
103
|
+
{...props}
|
|
104
|
+
>
|
|
105
|
+
<div className="flex flex-col gap-8">{children}</div>
|
|
106
|
+
{pointer !== "none" && (
|
|
107
|
+
<span
|
|
108
|
+
aria-hidden="true"
|
|
109
|
+
className={cn(
|
|
110
|
+
"pointer-events-none absolute size-4 rotate-45",
|
|
111
|
+
pointerPositionMap[pointer],
|
|
112
|
+
pointerBgMap[variant]
|
|
113
|
+
)}
|
|
114
|
+
data-slot="callout-pointer"
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
</CalloutContext.Provider>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
Callout.displayName = "Callout";
|
|
124
|
+
|
|
125
|
+
/** Props for the CalloutHeading sub-component */
|
|
126
|
+
interface CalloutHeadingProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
127
|
+
/** Optional test hook identifier */
|
|
128
|
+
dataHook?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Main heading/statement content for a Callout */
|
|
132
|
+
const CalloutHeading = React.forwardRef<HTMLDivElement, CalloutHeadingProps>(
|
|
133
|
+
({ className, dataHook, ...props }, ref) => (
|
|
134
|
+
<div
|
|
135
|
+
ref={ref}
|
|
136
|
+
className={cn("heading-lg font-semibold", className)}
|
|
137
|
+
data-hook={dataHook}
|
|
138
|
+
data-slot="callout-heading"
|
|
139
|
+
{...props}
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
CalloutHeading.displayName = "CalloutHeading";
|
|
145
|
+
|
|
146
|
+
/** Props for the CalloutCitation sub-component */
|
|
147
|
+
interface CalloutCitationProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
148
|
+
/** Optional test hook identifier */
|
|
149
|
+
dataHook?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Citation/attribution text for a Callout. Auto-styles based on parent variant. */
|
|
153
|
+
const CalloutCitation = React.forwardRef<HTMLDivElement, CalloutCitationProps>(
|
|
154
|
+
({ className, dataHook, ...props }, ref) => {
|
|
155
|
+
const { variant } = React.useContext(CalloutContext);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div
|
|
159
|
+
ref={ref}
|
|
160
|
+
className={cn(
|
|
161
|
+
"text-xs font-medium",
|
|
162
|
+
citationColorMap[variant],
|
|
163
|
+
className
|
|
164
|
+
)}
|
|
165
|
+
data-hook={dataHook}
|
|
166
|
+
data-slot="callout-citation"
|
|
167
|
+
{...props}
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
CalloutCitation.displayName = "CalloutCitation";
|
|
174
|
+
|
|
175
|
+
export { Callout, CalloutHeading, CalloutCitation, calloutVariants };
|
|
176
|
+
export type {
|
|
177
|
+
CalloutProps,
|
|
178
|
+
CalloutHeadingProps,
|
|
179
|
+
CalloutCitationProps,
|
|
180
|
+
CalloutVariant,
|
|
181
|
+
CalloutPointer,
|
|
182
|
+
};
|
|
@@ -267,6 +267,11 @@ interface CarouselPreviousProps extends Omit<
|
|
|
267
267
|
* @default "carousel-previous"
|
|
268
268
|
*/
|
|
269
269
|
dataHook?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Hide the button instead of disabling it when there are no previous slides
|
|
272
|
+
* @default false
|
|
273
|
+
*/
|
|
274
|
+
hideWhenDisabled?: boolean;
|
|
270
275
|
}
|
|
271
276
|
|
|
272
277
|
/**
|
|
@@ -277,17 +282,20 @@ function CarouselPrevious({
|
|
|
277
282
|
variant = "outline",
|
|
278
283
|
size = "default",
|
|
279
284
|
dataHook = "carousel-previous",
|
|
285
|
+
hideWhenDisabled = false,
|
|
280
286
|
...props
|
|
281
287
|
}: CarouselPreviousProps) {
|
|
282
288
|
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
283
289
|
|
|
290
|
+
if (hideWhenDisabled && !canScrollPrev) return null;
|
|
291
|
+
|
|
284
292
|
return (
|
|
285
293
|
<Button
|
|
286
294
|
iconOnly
|
|
287
295
|
className={cn(
|
|
288
296
|
"absolute",
|
|
289
297
|
orientation === "horizontal"
|
|
290
|
-
? "top-1/2
|
|
298
|
+
? "top-1/2 left-1 -translate-y-1/2 sm:-left-12"
|
|
291
299
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
292
300
|
className
|
|
293
301
|
)}
|
|
@@ -329,6 +337,11 @@ interface CarouselNextProps extends Omit<
|
|
|
329
337
|
* @default "carousel-next"
|
|
330
338
|
*/
|
|
331
339
|
dataHook?: string;
|
|
340
|
+
/**
|
|
341
|
+
* Hide the button instead of disabling it when there are no next slides
|
|
342
|
+
* @default false
|
|
343
|
+
*/
|
|
344
|
+
hideWhenDisabled?: boolean;
|
|
332
345
|
}
|
|
333
346
|
|
|
334
347
|
/**
|
|
@@ -339,17 +352,20 @@ function CarouselNext({
|
|
|
339
352
|
variant = "outline",
|
|
340
353
|
size = "default",
|
|
341
354
|
dataHook = "carousel-next",
|
|
355
|
+
hideWhenDisabled = false,
|
|
342
356
|
...props
|
|
343
357
|
}: CarouselNextProps) {
|
|
344
358
|
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
345
359
|
|
|
360
|
+
if (hideWhenDisabled && !canScrollNext) return null;
|
|
361
|
+
|
|
346
362
|
return (
|
|
347
363
|
<Button
|
|
348
364
|
iconOnly
|
|
349
365
|
className={cn(
|
|
350
366
|
"absolute",
|
|
351
367
|
orientation === "horizontal"
|
|
352
|
-
? "top-1/2
|
|
368
|
+
? "top-1/2 right-1 -translate-y-1/2 sm:-right-12"
|
|
353
369
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
354
370
|
className
|
|
355
371
|
)}
|
|
@@ -369,6 +385,102 @@ function CarouselNext({
|
|
|
369
385
|
|
|
370
386
|
CarouselNext.displayName = "CarouselNext";
|
|
371
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Props for CarouselDots component.
|
|
390
|
+
*/
|
|
391
|
+
interface CarouselDotsProps extends React.ComponentProps<"div"> {
|
|
392
|
+
/**
|
|
393
|
+
* Data hook for automated testing
|
|
394
|
+
* @default "carousel-dots"
|
|
395
|
+
*/
|
|
396
|
+
dataHook?: string;
|
|
397
|
+
/**
|
|
398
|
+
* Tracking element identifier for analytics
|
|
399
|
+
*/
|
|
400
|
+
trackingEl?: string;
|
|
401
|
+
/**
|
|
402
|
+
* Tracking label for analytics context
|
|
403
|
+
*/
|
|
404
|
+
trackingLabel?: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Dot/pill pagination indicator for the carousel.
|
|
409
|
+
* Active slide is shown as an elongated pill, inactive slides as circles.
|
|
410
|
+
*/
|
|
411
|
+
function CarouselDots({
|
|
412
|
+
className,
|
|
413
|
+
dataHook = "carousel-dots",
|
|
414
|
+
trackingEl,
|
|
415
|
+
trackingLabel,
|
|
416
|
+
...props
|
|
417
|
+
}: CarouselDotsProps) {
|
|
418
|
+
const { api } = useCarousel();
|
|
419
|
+
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
420
|
+
const [scrollSnaps, setScrollSnaps] = React.useState<number[]>([]);
|
|
421
|
+
|
|
422
|
+
React.useEffect(() => {
|
|
423
|
+
if (!api) return;
|
|
424
|
+
|
|
425
|
+
setScrollSnaps(api.scrollSnapList());
|
|
426
|
+
setSelectedIndex(api.selectedScrollSnap());
|
|
427
|
+
|
|
428
|
+
const onSelect = () => {
|
|
429
|
+
setSelectedIndex(api.selectedScrollSnap());
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const onReInit = () => {
|
|
433
|
+
setScrollSnaps(api.scrollSnapList());
|
|
434
|
+
setSelectedIndex(api.selectedScrollSnap());
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
api.on("select", onSelect);
|
|
438
|
+
api.on("reInit", onReInit);
|
|
439
|
+
|
|
440
|
+
return () => {
|
|
441
|
+
api.off("select", onSelect);
|
|
442
|
+
api.off("reInit", onReInit);
|
|
443
|
+
};
|
|
444
|
+
}, [api]);
|
|
445
|
+
|
|
446
|
+
if (scrollSnaps.length === 0) return null;
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<div
|
|
450
|
+
aria-label="Slide navigation"
|
|
451
|
+
className={cn(
|
|
452
|
+
"border-border dark:border-input dark:bg-input/30 inline-flex items-center justify-center gap-2 rounded-full border bg-white px-2.5 py-2",
|
|
453
|
+
className
|
|
454
|
+
)}
|
|
455
|
+
data-hook={dataHook}
|
|
456
|
+
data-slot="carousel-dots"
|
|
457
|
+
data-tracking-el={trackingEl}
|
|
458
|
+
data-tracking-label={trackingLabel}
|
|
459
|
+
role="group"
|
|
460
|
+
{...props}
|
|
461
|
+
>
|
|
462
|
+
{scrollSnaps.map((_, index) => (
|
|
463
|
+
<button
|
|
464
|
+
key={index}
|
|
465
|
+
aria-current={index === selectedIndex ? "step" : undefined}
|
|
466
|
+
aria-label={`Go to slide ${index + 1}`}
|
|
467
|
+
className={cn(
|
|
468
|
+
"focus-visible:shadow-default size-3 rounded-full transition-[width,background-color] duration-200 ease-out outline-none",
|
|
469
|
+
index === selectedIndex
|
|
470
|
+
? "bg-muted-foreground/50 dark:bg-muted-foreground/70 w-9"
|
|
471
|
+
: "bg-input hover:bg-muted-foreground/30 dark:bg-input/80 dark:hover:bg-muted-foreground/50"
|
|
472
|
+
)}
|
|
473
|
+
data-slot="carousel-dot"
|
|
474
|
+
type="button"
|
|
475
|
+
onClick={() => api?.scrollTo(index)}
|
|
476
|
+
/>
|
|
477
|
+
))}
|
|
478
|
+
</div>
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
CarouselDots.displayName = "CarouselDots";
|
|
483
|
+
|
|
372
484
|
export {
|
|
373
485
|
type CarouselApi,
|
|
374
486
|
Carousel,
|
|
@@ -376,6 +488,12 @@ export {
|
|
|
376
488
|
CarouselItem,
|
|
377
489
|
CarouselPrevious,
|
|
378
490
|
CarouselNext,
|
|
491
|
+
CarouselDots,
|
|
379
492
|
};
|
|
380
493
|
|
|
381
|
-
export type {
|
|
494
|
+
export type {
|
|
495
|
+
CarouselProps,
|
|
496
|
+
CarouselPreviousProps,
|
|
497
|
+
CarouselNextProps,
|
|
498
|
+
CarouselDotsProps,
|
|
499
|
+
};
|
|
@@ -322,7 +322,7 @@ const comboboxTriggerVariants = cva([
|
|
|
322
322
|
"dark:bg-white/5 dark:border-white/15",
|
|
323
323
|
|
|
324
324
|
// Typography
|
|
325
|
-
"text-
|
|
325
|
+
"text-base font-normal font-sans text-foreground",
|
|
326
326
|
|
|
327
327
|
// Placeholder state
|
|
328
328
|
"data-[placeholder=true]:text-muted-foreground",
|
|
@@ -460,7 +460,7 @@ function ComboboxValue({
|
|
|
460
460
|
return (
|
|
461
461
|
<span
|
|
462
462
|
className={cn(
|
|
463
|
-
"text-foreground overflow-hidden text-
|
|
463
|
+
"text-foreground overflow-hidden text-base leading-normal font-medium text-ellipsis whitespace-nowrap",
|
|
464
464
|
className
|
|
465
465
|
)}
|
|
466
466
|
data-slot="combobox-value"
|
|
@@ -131,7 +131,7 @@ const CommandInput = React.forwardRef<
|
|
|
131
131
|
<CommandPrimitive.Input
|
|
132
132
|
ref={inputRef}
|
|
133
133
|
className={cn(
|
|
134
|
-
"placeholder:text-muted-foreground flex w-full bg-transparent text-
|
|
134
|
+
"placeholder:text-muted-foreground flex w-full bg-transparent text-base outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
135
135
|
className
|
|
136
136
|
)}
|
|
137
137
|
data-slot="command-input"
|
|
@@ -8,7 +8,7 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
|
8
8
|
import { Input, type InputProps } from "./input";
|
|
9
9
|
|
|
10
10
|
const inputGroupVariants = cva(
|
|
11
|
-
"relative flex w-full items-center rounded-
|
|
11
|
+
"relative flex w-full items-center rounded-sm border border-input bg-background transition-colors has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50",
|
|
12
12
|
{
|
|
13
13
|
variants: {
|
|
14
14
|
size: {
|
|
@@ -137,7 +137,7 @@ function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
|
|
|
137
137
|
// Base styles
|
|
138
138
|
"relative flex h-9 w-9 items-center justify-center",
|
|
139
139
|
"border-input bg-background border-y border-r",
|
|
140
|
-
"text-foreground text-
|
|
140
|
+
"text-foreground text-base font-normal transition-[border-color,box-shadow] outline-none",
|
|
141
141
|
"first:rounded-l-md first:border-l last:rounded-r-md",
|
|
142
142
|
// Focus state
|
|
143
143
|
"data-[active=true]:border-ring data-[active=true]:z-10",
|
package/src/components/input.tsx
CHANGED
|
@@ -16,7 +16,7 @@ export const inputVariants = cva(
|
|
|
16
16
|
"border border-input bg-background rounded-sm",
|
|
17
17
|
"outline-none transition-[border-color,box-shadow,background-color]",
|
|
18
18
|
// Typography
|
|
19
|
-
"text-
|
|
19
|
+
"text-base font-sans",
|
|
20
20
|
"text-foreground",
|
|
21
21
|
"overflow-hidden text-ellipsis",
|
|
22
22
|
// States - Focus
|
|
@@ -27,8 +27,7 @@ export const inputVariants = cva(
|
|
|
27
27
|
// Pseudo-elements
|
|
28
28
|
"placeholder:text-muted-foreground",
|
|
29
29
|
"placeholder:overflow-hidden placeholder:text-ellipsis",
|
|
30
|
-
|
|
31
|
-
"items-center px-3 pb-[1px] leading-5",
|
|
30
|
+
"items-center px-3",
|
|
32
31
|
// Hide default browser icons for date/time inputs
|
|
33
32
|
"[&::-webkit-calendar-picker-indicator]:hidden",
|
|
34
33
|
],
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
3
3
|
|
|
4
|
-
/* -------------------------------------------------------------------------------------------------
|
|
5
|
-
* Internal context — lets SplitLayoutContentLeft know if a header is present
|
|
6
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
7
|
-
|
|
8
|
-
const SplitLayoutContext = React.createContext(false);
|
|
9
|
-
|
|
10
4
|
/* -------------------------------------------------------------------------------------------------
|
|
11
5
|
* SplitLayout Root
|
|
12
6
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -37,8 +31,10 @@ interface SplitLayoutProps extends React.ComponentProps<"div"> {
|
|
|
37
31
|
* and shows only the left section on smaller screens (hiding the right/marketing section).
|
|
38
32
|
* This pattern is commonly used for authentication pages where the form is prioritized on mobile.
|
|
39
33
|
*
|
|
40
|
-
* Uses
|
|
41
|
-
*
|
|
34
|
+
* Uses CSS Grid for slot positioning — sub-components self-place into the correct
|
|
35
|
+
* grid area via their own classes, so SplitLayout renders {children} without
|
|
36
|
+
* inspecting them. This enables composition through any wrapping: Fragments,
|
|
37
|
+
* router Outlets, memoized components, or conditional renders.
|
|
42
38
|
*
|
|
43
39
|
* @example
|
|
44
40
|
* // Basic usage
|
|
@@ -65,6 +61,15 @@ interface SplitLayoutProps extends React.ComponentProps<"div"> {
|
|
|
65
61
|
* </SplitLayoutContentRight>
|
|
66
62
|
* </SplitLayout>
|
|
67
63
|
*
|
|
64
|
+
* @example
|
|
65
|
+
* // With router Outlet — slots project up through any wrapping
|
|
66
|
+
* <SplitLayout dataHook="auth-layout">
|
|
67
|
+
* <SplitLayoutHeader>
|
|
68
|
+
* <Header dataHook="my-header"><Logo dataHook="my-logo" /></Header>
|
|
69
|
+
* </SplitLayoutHeader>
|
|
70
|
+
* <Outlet />
|
|
71
|
+
* </SplitLayout>
|
|
72
|
+
*
|
|
68
73
|
* Layout specifications:
|
|
69
74
|
* - Mobile/Tablet: Stacked layout, only left section visible, content centered
|
|
70
75
|
* - Desktop (≥1024px): Side-by-side, content centered within each section
|
|
@@ -86,42 +91,11 @@ const SplitLayout = React.forwardRef<HTMLDivElement, SplitLayoutProps>(
|
|
|
86
91
|
},
|
|
87
92
|
ref
|
|
88
93
|
) => {
|
|
89
|
-
const headerChildren: React.ReactNode[] = [];
|
|
90
|
-
const leftChildren: React.ReactNode[] = [];
|
|
91
|
-
const rightChildren: React.ReactNode[] = [];
|
|
92
|
-
|
|
93
|
-
const collectChild = (child: React.ReactNode): void => {
|
|
94
|
-
if (!React.isValidElement(child)) return;
|
|
95
|
-
if (child.type === React.Fragment) {
|
|
96
|
-
React.Children.forEach(
|
|
97
|
-
(child.props as { children: React.ReactNode }).children,
|
|
98
|
-
collectChild
|
|
99
|
-
);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (child.type === SplitLayoutHeader) {
|
|
103
|
-
headerChildren.push(child);
|
|
104
|
-
} else if (child.type === SplitLayoutContentRight) {
|
|
105
|
-
rightChildren.push(child);
|
|
106
|
-
} else {
|
|
107
|
-
leftChildren.push(child);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
React.Children.forEach(children, collectChild);
|
|
111
|
-
|
|
112
|
-
// Support legacy left/right props as fallback
|
|
113
|
-
const hasLegacyProps = left != null || right != null;
|
|
114
|
-
const hasCompositionChildren =
|
|
115
|
-
leftChildren.length > 0 || rightChildren.length > 0;
|
|
116
|
-
const useLegacy = hasLegacyProps && !hasCompositionChildren;
|
|
117
|
-
|
|
118
|
-
const hasHeader = headerChildren.length > 0;
|
|
119
|
-
|
|
120
94
|
return (
|
|
121
95
|
<div
|
|
122
96
|
ref={ref}
|
|
123
97
|
className={cn(
|
|
124
|
-
"
|
|
98
|
+
"group/split-layout bg-background grid min-h-screen w-full grid-cols-1 grid-rows-[auto_1fr] lg:has-[[data-slot=split-layout-right]]:grid-cols-2",
|
|
125
99
|
className
|
|
126
100
|
)}
|
|
127
101
|
data-hook={dataHook}
|
|
@@ -130,22 +104,9 @@ const SplitLayout = React.forwardRef<HTMLDivElement, SplitLayoutProps>(
|
|
|
130
104
|
data-tracking-label={trackingLabel}
|
|
131
105
|
{...props}
|
|
132
106
|
>
|
|
133
|
-
{
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
data-slot="split-layout-body"
|
|
137
|
-
>
|
|
138
|
-
<SplitLayoutContext.Provider value={hasHeader}>
|
|
139
|
-
{headerChildren}
|
|
140
|
-
{useLegacy
|
|
141
|
-
? left && <SplitLayoutContentLeft>{left}</SplitLayoutContentLeft>
|
|
142
|
-
: leftChildren}
|
|
143
|
-
</SplitLayoutContext.Provider>
|
|
144
|
-
</div>
|
|
145
|
-
{/* Right column: extends full height with bg-card */}
|
|
146
|
-
{useLegacy
|
|
147
|
-
? right && <SplitLayoutContentRight>{right}</SplitLayoutContentRight>
|
|
148
|
-
: rightChildren}
|
|
107
|
+
{children}
|
|
108
|
+
{left && <SplitLayoutContentLeft>{left}</SplitLayoutContentLeft>}
|
|
109
|
+
{right && <SplitLayoutContentRight>{right}</SplitLayoutContentRight>}
|
|
149
110
|
</div>
|
|
150
111
|
);
|
|
151
112
|
}
|
|
@@ -168,6 +129,7 @@ interface SplitLayoutHeaderProps extends React.ComponentProps<"div"> {
|
|
|
168
129
|
* SplitLayoutHeader component for rendering header content at the top of SplitLayout.
|
|
169
130
|
* Content is centered on mobile/tablet, left-aligned from lg breakpoint onwards.
|
|
170
131
|
* Uses section padding tokens for responsive horizontal and vertical padding (16px mobile, 24px desktop).
|
|
132
|
+
* Self-positions in the first column, first row of the grid.
|
|
171
133
|
*/
|
|
172
134
|
const SplitLayoutHeader = React.forwardRef<
|
|
173
135
|
HTMLDivElement,
|
|
@@ -177,7 +139,7 @@ const SplitLayoutHeader = React.forwardRef<
|
|
|
177
139
|
<div
|
|
178
140
|
ref={ref}
|
|
179
141
|
className={cn(
|
|
180
|
-
"px-section-sm pt-section-sm flex w-full items-center justify-center lg:justify-start",
|
|
142
|
+
"px-section-sm pt-section-sm col-start-1 row-start-1 flex w-full items-center justify-center lg:justify-start",
|
|
181
143
|
className
|
|
182
144
|
)}
|
|
183
145
|
data-slot="split-layout-header"
|
|
@@ -202,20 +164,19 @@ interface SplitLayoutContentLeftProps extends React.ComponentProps<"div"> {
|
|
|
202
164
|
* SplitLayoutContentLeft - Left/primary section within a SplitLayout.
|
|
203
165
|
*
|
|
204
166
|
* Always visible. When a SplitLayoutHeader is present, top padding is
|
|
205
|
-
* automatically reduced to avoid excessive spacing below the header.
|
|
167
|
+
* automatically reduced via CSS :has() to avoid excessive spacing below the header.
|
|
168
|
+
* Self-positions in the first column, second row of the grid.
|
|
206
169
|
*/
|
|
207
170
|
const SplitLayoutContentLeft = React.forwardRef<
|
|
208
171
|
HTMLDivElement,
|
|
209
172
|
SplitLayoutContentLeftProps
|
|
210
173
|
>(({ className, children, ...props }, ref) => {
|
|
211
|
-
const hasHeader = React.useContext(SplitLayoutContext);
|
|
212
|
-
|
|
213
174
|
return (
|
|
214
175
|
<div
|
|
215
176
|
ref={ref}
|
|
216
177
|
className={cn(
|
|
217
|
-
"p-section-sm flex
|
|
218
|
-
|
|
178
|
+
"p-section-sm col-start-1 row-start-2 flex min-h-0 items-center justify-center overflow-auto",
|
|
179
|
+
"group-has-[[data-slot=split-layout-header]]/split-layout:pt-2",
|
|
219
180
|
className
|
|
220
181
|
)}
|
|
221
182
|
data-slot="split-layout-left"
|
|
@@ -247,6 +208,7 @@ interface SplitLayoutContentRightProps extends React.ComponentProps<"div"> {
|
|
|
247
208
|
*
|
|
248
209
|
* Hidden on mobile/tablet (<1024px), visible on desktop (≥1024px).
|
|
249
210
|
* Uses bg-card background color.
|
|
211
|
+
* Self-positions in the second column, spanning all rows of the grid.
|
|
250
212
|
*
|
|
251
213
|
* Set `flush` to remove padding for full-bleed content (e.g. images).
|
|
252
214
|
*/
|
|
@@ -258,10 +220,10 @@ const SplitLayoutContentRight = React.forwardRef<
|
|
|
258
220
|
<div
|
|
259
221
|
ref={ref}
|
|
260
222
|
className={cn(
|
|
261
|
-
"bg-card hidden",
|
|
223
|
+
"bg-card hidden lg:col-start-2 lg:row-span-full lg:row-start-1",
|
|
262
224
|
flush
|
|
263
|
-
? "relative
|
|
264
|
-
: "p-section-sm
|
|
225
|
+
? "relative overflow-hidden lg:block"
|
|
226
|
+
: "p-section-sm min-h-0 items-center justify-center overflow-auto lg:flex",
|
|
265
227
|
className
|
|
266
228
|
)}
|
|
267
229
|
data-slot="split-layout-right"
|
|
@@ -10,7 +10,7 @@ const textareaVariants = cva([
|
|
|
10
10
|
"border border-input bg-background rounded-md",
|
|
11
11
|
"outline-none transition-[border-color,background-color,box-shadow]",
|
|
12
12
|
// Typography
|
|
13
|
-
"text-
|
|
13
|
+
"text-base leading-normal font-sans",
|
|
14
14
|
"text-foreground",
|
|
15
15
|
// Spacing
|
|
16
16
|
"px-3 py-2",
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./components/badge";
|
|
|
8
8
|
export * from "./components/breadcrumb";
|
|
9
9
|
export * from "./components/button";
|
|
10
10
|
export * from "./components/calendar";
|
|
11
|
+
export * from "./components/callout";
|
|
11
12
|
export * from "./components/card";
|
|
12
13
|
export * from "./components/carousel";
|
|
13
14
|
export * from "./components/chart";
|