@brightlocal/ui-components 0.1.1 → 0.1.3
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/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +74 -4
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +100 -105
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +30 -10
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +129 -132
- package/dist/alert.d.ts +22 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/aspect-ratio.cjs +1 -1
- package/dist/aspect-ratio.d.ts +11 -1
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +16 -20
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.d.ts +43 -3
- package/dist/avatar.d.ts.map +1 -1
- package/dist/avatar.js +18 -16
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +24 -9
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +34 -32
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +209 -202
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +154 -154
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +63 -8
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +97 -93
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts +17 -45
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +49 -50
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts +12 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +10 -8
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +58 -18
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +60 -51
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +99 -9
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +142 -128
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +18 -2
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +46 -33
- package/dist/chart.cjs +4 -4
- package/dist/chart.d.ts +70 -7
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +71 -66
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +9 -5
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +61 -82
- package/dist/collapsible.cjs +1 -1
- package/dist/collapsible.d.ts +65 -8
- package/dist/collapsible.d.ts.map +1 -1
- package/dist/collapsible.js +41 -55
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +29 -11
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +193 -159
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +115 -9
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +176 -152
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts +188 -20
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +119 -121
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +75 -9
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +220 -81
- package/dist/description.cjs +1 -0
- package/dist/description.d.ts +37 -0
- package/dist/description.d.ts.map +1 -0
- package/dist/description.js +25 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +73 -9
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +103 -112
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +92 -0
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +67 -52
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts +95 -11
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +146 -106
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +23 -6
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +54 -53
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +27 -17
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +86 -79
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +36 -6
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +44 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +383 -387
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +21 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +51 -41
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +24 -25
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts +38 -24
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +68 -136
- package/dist/label.cjs +1 -1
- package/dist/label.d.ts +20 -1
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +31 -18
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +3 -0
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +12 -10
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts +40 -6
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +97 -76
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts +59 -4
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +42 -34
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +9 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +71 -59
- package/dist/radio-group.d.ts +40 -0
- package/dist/radio-group.d.ts.map +1 -1
- package/dist/rating.d.ts +4 -0
- package/dist/rating.d.ts.map +1 -1
- package/dist/resizable.cjs +1 -1
- package/dist/resizable.d.ts +65 -4
- package/dist/resizable.d.ts.map +1 -1
- package/dist/resizable.js +53 -36
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +46 -5
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +42 -38
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts +30 -0
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +64 -54
- package/dist/separator.cjs +1 -1
- package/dist/separator.d.ts +49 -2
- package/dist/separator.d.ts.map +1 -1
- package/dist/separator.js +48 -36
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +80 -9
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +117 -113
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.d.ts +24 -2
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js +15 -9
- package/dist/slider.cjs +1 -1
- package/dist/slider.d.ts +18 -4
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +72 -66
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts +4 -2
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +29 -28
- package/dist/split-layout.d.ts +4 -1
- package/dist/split-layout.d.ts.map +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.js +1 -1
- package/dist/toggle-group.cjs +1 -1
- package/dist/toggle-group.d.ts +3 -1
- package/dist/toggle-group.d.ts.map +1 -1
- package/dist/toggle-group.js +38 -36
- package/package.json +8 -2
- package/src/blocks/data-table.tsx +42 -32
- package/src/blocks/sidebar.tsx +4 -12
- package/src/components/accordion.tsx +163 -77
- package/src/components/alert-dialog.tsx +156 -111
- package/src/components/alert.tsx +26 -13
- package/src/components/aspect-ratio.tsx +25 -16
- package/src/components/avatar.tsx +56 -8
- package/src/components/badge.tsx +65 -42
- package/src/components/breadcrumb.tsx +158 -82
- package/src/components/button.tsx +41 -62
- package/src/components/calendar.tsx +16 -2
- package/src/components/card.tsx +92 -40
- package/src/components/carousel.tsx +240 -115
- package/src/components/centred-layout.tsx +67 -35
- package/src/components/chart.tsx +118 -47
- package/src/components/checkbox.tsx +42 -78
- package/src/components/collapsible.tsx +95 -26
- package/src/components/combobox.tsx +242 -144
- package/src/components/command.tsx +295 -121
- package/src/components/context-menu.tsx +278 -81
- package/src/components/date-picker.tsx +281 -30
- package/src/components/description.tsx +60 -0
- package/src/components/dialog.tsx +162 -86
- package/src/components/drawer.tsx +76 -2
- package/src/components/dropdown-menu.tsx +143 -37
- package/src/components/field.tsx +36 -11
- package/src/components/global-layout.tsx +116 -77
- package/src/components/hover-card.tsx +54 -14
- package/src/components/input-group.tsx +56 -18
- package/src/components/input-password.tsx +3 -4
- package/src/components/input.tsx +93 -186
- package/src/components/label.tsx +56 -15
- package/src/components/logo.tsx +3 -0
- package/src/components/menubar.tsx +58 -4
- package/src/components/popover.tsx +103 -20
- package/src/components/progress.tsx +82 -60
- package/src/components/radio-group.tsx +40 -0
- package/src/components/rating.tsx +4 -1
- package/src/components/resizable.tsx +119 -31
- package/src/components/scroll-area.tsx +123 -56
- package/src/components/select.tsx +21 -1
- package/src/components/separator.tsx +97 -20
- package/src/components/sheet.tsx +180 -79
- package/src/components/skeleton.tsx +40 -10
- package/src/components/slider.tsx +83 -57
- package/src/components/sonner.tsx +10 -7
- package/src/components/split-layout.tsx +4 -1
- package/src/components/table.tsx +1 -1
- package/src/components/toggle-group.tsx +4 -0
- package/src/index.ts +1 -1
- package/dist/input-base.cjs +0 -1
- package/dist/input-base.d.ts +0 -28
- package/dist/input-base.d.ts.map +0 -1
- package/dist/input-base.js +0 -56
- package/src/components/input-base.tsx +0 -86
|
@@ -1,27 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import * as React from "react";
|
|
2
4
|
import useEmblaCarousel, {
|
|
3
5
|
type UseEmblaCarouselType,
|
|
4
6
|
} from "embla-carousel-react";
|
|
5
|
-
import { ArrowLeft, ArrowRight } from "
|
|
7
|
+
import { ArrowLeft, ArrowRight } from "@brightlocal/icons";
|
|
6
8
|
|
|
7
9
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
-
import {
|
|
9
|
-
Button,
|
|
10
|
-
ButtonVariant,
|
|
11
|
-
ButtonSize,
|
|
12
|
-
} from "@brightlocal/ui-components/button";
|
|
10
|
+
import { Button, type ButtonProps } from "@brightlocal/ui-components/button";
|
|
13
11
|
|
|
14
12
|
type CarouselApi = UseEmblaCarouselType[1];
|
|
15
13
|
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
16
14
|
type CarouselOptions = UseCarouselParameters[0];
|
|
17
15
|
type CarouselPlugin = UseCarouselParameters[1];
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Props for the Carousel component.
|
|
19
|
+
*/
|
|
20
|
+
interface CarouselProps extends React.ComponentProps<"div"> {
|
|
21
|
+
/**
|
|
22
|
+
* Data hook for automated testing (required)
|
|
23
|
+
*/
|
|
24
|
+
dataHook: string;
|
|
25
|
+
/**
|
|
26
|
+
* Tracking element identifier for analytics
|
|
27
|
+
*/
|
|
28
|
+
trackingEl?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Tracking label for analytics context
|
|
31
|
+
*/
|
|
32
|
+
trackingLabel?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Embla carousel options
|
|
35
|
+
*/
|
|
20
36
|
opts?: CarouselOptions;
|
|
37
|
+
/**
|
|
38
|
+
* Embla carousel plugins
|
|
39
|
+
*/
|
|
21
40
|
plugins?: CarouselPlugin;
|
|
41
|
+
/**
|
|
42
|
+
* Carousel orientation
|
|
43
|
+
* @default "horizontal"
|
|
44
|
+
*/
|
|
22
45
|
orientation?: "horizontal" | "vertical";
|
|
46
|
+
/**
|
|
47
|
+
* Callback to receive the carousel API instance
|
|
48
|
+
*/
|
|
23
49
|
setApi?: (api: CarouselApi) => void;
|
|
24
|
-
}
|
|
50
|
+
}
|
|
25
51
|
|
|
26
52
|
type CarouselContextProps = {
|
|
27
53
|
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
@@ -30,7 +56,11 @@ type CarouselContextProps = {
|
|
|
30
56
|
scrollNext: () => void;
|
|
31
57
|
canScrollPrev: boolean;
|
|
32
58
|
canScrollNext: boolean;
|
|
33
|
-
|
|
59
|
+
opts?: CarouselOptions;
|
|
60
|
+
plugins?: CarouselPlugin;
|
|
61
|
+
orientation?: "horizontal" | "vertical";
|
|
62
|
+
setApi?: (api: CarouselApi) => void;
|
|
63
|
+
};
|
|
34
64
|
|
|
35
65
|
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
36
66
|
|
|
@@ -44,133 +74,166 @@ function useCarousel() {
|
|
|
44
74
|
return context;
|
|
45
75
|
}
|
|
46
76
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
children,
|
|
54
|
-
...props
|
|
55
|
-
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
56
|
-
const [carouselRef, api] = useEmblaCarousel(
|
|
77
|
+
/**
|
|
78
|
+
* Carousel component for displaying a scrollable series of content.
|
|
79
|
+
* Built on Embla Carousel for smooth touch-enabled sliding.
|
|
80
|
+
*/
|
|
81
|
+
const Carousel = React.forwardRef<HTMLDivElement, CarouselProps>(
|
|
82
|
+
(
|
|
57
83
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setCanScrollPrev(api.canScrollPrev());
|
|
69
|
-
setCanScrollNext(api.canScrollNext());
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
72
|
-
const scrollPrev = React.useCallback(() => {
|
|
73
|
-
api?.scrollPrev();
|
|
74
|
-
}, [api]);
|
|
75
|
-
|
|
76
|
-
const scrollNext = React.useCallback(() => {
|
|
77
|
-
api?.scrollNext();
|
|
78
|
-
}, [api]);
|
|
79
|
-
|
|
80
|
-
const handleKeyDown = React.useCallback(
|
|
81
|
-
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
82
|
-
const prevKey = orientation === "horizontal" ? "ArrowLeft" : "ArrowUp";
|
|
83
|
-
const nextKey = orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
|
|
84
|
-
|
|
85
|
-
if (event.key === prevKey) {
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
scrollPrev();
|
|
88
|
-
} else if (event.key === nextKey) {
|
|
89
|
-
event.preventDefault();
|
|
90
|
-
scrollNext();
|
|
91
|
-
}
|
|
84
|
+
orientation = "horizontal",
|
|
85
|
+
opts,
|
|
86
|
+
setApi,
|
|
87
|
+
plugins,
|
|
88
|
+
className,
|
|
89
|
+
children,
|
|
90
|
+
dataHook,
|
|
91
|
+
trackingEl,
|
|
92
|
+
trackingLabel,
|
|
93
|
+
...props
|
|
92
94
|
},
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
+
ref
|
|
96
|
+
) => {
|
|
97
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
98
|
+
{
|
|
99
|
+
...opts,
|
|
100
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
101
|
+
},
|
|
102
|
+
plugins
|
|
103
|
+
);
|
|
104
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
105
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
95
106
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
108
|
+
if (!api) return;
|
|
109
|
+
setCanScrollPrev(api.canScrollPrev());
|
|
110
|
+
setCanScrollNext(api.canScrollNext());
|
|
111
|
+
}, []);
|
|
100
112
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
api.on("reInit", onSelect);
|
|
105
|
-
api.on("select", onSelect);
|
|
113
|
+
const scrollPrev = React.useCallback(() => {
|
|
114
|
+
api?.scrollPrev();
|
|
115
|
+
}, [api]);
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
api?.
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
}, [api, onSelect]);
|
|
117
|
+
const scrollNext = React.useCallback(() => {
|
|
118
|
+
api?.scrollNext();
|
|
119
|
+
}, [api]);
|
|
112
120
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
const handleKeyDown = React.useCallback(
|
|
122
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
123
|
+
const prevKey = orientation === "horizontal" ? "ArrowLeft" : "ArrowUp";
|
|
124
|
+
const nextKey =
|
|
125
|
+
orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
|
|
126
|
+
|
|
127
|
+
if (event.key === prevKey) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
scrollPrev();
|
|
130
|
+
} else if (event.key === nextKey) {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
scrollNext();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[orientation, scrollPrev, scrollNext]
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
React.useEffect(() => {
|
|
139
|
+
if (!api || !setApi) return;
|
|
140
|
+
setApi(api);
|
|
141
|
+
}, [api, setApi]);
|
|
142
|
+
|
|
143
|
+
React.useEffect(() => {
|
|
144
|
+
if (!api) return;
|
|
145
|
+
onSelect(api);
|
|
146
|
+
api.on("reInit", onSelect);
|
|
147
|
+
api.on("select", onSelect);
|
|
148
|
+
|
|
149
|
+
return () => {
|
|
150
|
+
api?.off("reInit", onSelect);
|
|
151
|
+
api?.off("select", onSelect);
|
|
152
|
+
};
|
|
153
|
+
}, [api, onSelect]);
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<CarouselContext.Provider
|
|
157
|
+
value={{
|
|
158
|
+
carouselRef,
|
|
159
|
+
api,
|
|
160
|
+
opts,
|
|
161
|
+
orientation:
|
|
162
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
163
|
+
scrollPrev,
|
|
164
|
+
scrollNext,
|
|
165
|
+
canScrollPrev,
|
|
166
|
+
canScrollNext,
|
|
167
|
+
}}
|
|
134
168
|
>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
169
|
+
<div
|
|
170
|
+
ref={ref}
|
|
171
|
+
aria-roledescription="carousel"
|
|
172
|
+
className={cn("relative", className)}
|
|
173
|
+
data-hook={dataHook}
|
|
174
|
+
data-slot="carousel"
|
|
175
|
+
data-tracking-el={trackingEl}
|
|
176
|
+
data-tracking-label={trackingLabel}
|
|
177
|
+
role="region"
|
|
178
|
+
onKeyDownCapture={handleKeyDown}
|
|
179
|
+
{...props}
|
|
180
|
+
>
|
|
181
|
+
{children}
|
|
182
|
+
</div>
|
|
183
|
+
</CarouselContext.Provider>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
);
|
|
140
187
|
|
|
141
|
-
|
|
188
|
+
Carousel.displayName = "Carousel";
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Container for carousel items with overflow handling.
|
|
192
|
+
*/
|
|
193
|
+
const CarouselContent = React.forwardRef<
|
|
194
|
+
HTMLDivElement,
|
|
195
|
+
React.ComponentProps<"div">
|
|
196
|
+
>(({ className, ...props }, ref) => {
|
|
142
197
|
const { carouselRef, orientation } = useCarousel();
|
|
198
|
+
const isVertical = orientation === "vertical";
|
|
143
199
|
|
|
144
200
|
return (
|
|
145
201
|
<div
|
|
146
202
|
ref={carouselRef}
|
|
147
|
-
className={cn(
|
|
148
|
-
"overflow-hidden",
|
|
149
|
-
orientation === "vertical" && "h-[400px]"
|
|
150
|
-
)}
|
|
203
|
+
className={cn("overflow-hidden", isVertical && "w-full", className)}
|
|
151
204
|
data-slot="carousel-content"
|
|
152
205
|
>
|
|
206
|
+
{/* Negative margins offset the positive padding on CarouselItem children (pt-4/pl-4) to create consistent gaps */}
|
|
153
207
|
<div
|
|
208
|
+
ref={ref}
|
|
154
209
|
className={cn(
|
|
155
|
-
"flex
|
|
156
|
-
|
|
157
|
-
className
|
|
210
|
+
"flex",
|
|
211
|
+
isVertical ? "-mt-4 h-full w-full flex-col" : "-ml-4"
|
|
158
212
|
)}
|
|
159
213
|
{...props}
|
|
160
214
|
/>
|
|
161
215
|
</div>
|
|
162
216
|
);
|
|
163
|
-
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
CarouselContent.displayName = "CarouselContent";
|
|
164
220
|
|
|
165
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Individual slide item within the carousel.
|
|
223
|
+
*/
|
|
224
|
+
const CarouselItem = React.forwardRef<
|
|
225
|
+
HTMLDivElement,
|
|
226
|
+
React.ComponentProps<"div">
|
|
227
|
+
>(({ className, ...props }, ref) => {
|
|
166
228
|
const { orientation } = useCarousel();
|
|
167
229
|
|
|
168
230
|
return (
|
|
169
231
|
<div
|
|
232
|
+
ref={ref}
|
|
170
233
|
aria-roledescription="slide"
|
|
171
234
|
className={cn(
|
|
172
235
|
"min-w-0 shrink-0 grow-0 basis-full",
|
|
173
|
-
orientation === "horizontal" ? "pl-
|
|
236
|
+
orientation === "horizontal" ? "pl-4" : "w-full pt-4",
|
|
174
237
|
className
|
|
175
238
|
)}
|
|
176
239
|
data-slot="carousel-item"
|
|
@@ -178,21 +241,51 @@ function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
178
241
|
{...props}
|
|
179
242
|
/>
|
|
180
243
|
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
CarouselItem.displayName = "CarouselItem";
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Props for CarouselPrevious component.
|
|
250
|
+
*/
|
|
251
|
+
interface CarouselPreviousProps extends Omit<
|
|
252
|
+
ButtonProps,
|
|
253
|
+
"variant" | "size" | "dataHook"
|
|
254
|
+
> {
|
|
255
|
+
/**
|
|
256
|
+
* Visual style variant of the button
|
|
257
|
+
* @default "outline"
|
|
258
|
+
*/
|
|
259
|
+
variant?: ButtonProps["variant"];
|
|
260
|
+
/**
|
|
261
|
+
* Size variant of the button
|
|
262
|
+
* @default "default"
|
|
263
|
+
*/
|
|
264
|
+
size?: ButtonProps["size"];
|
|
265
|
+
/**
|
|
266
|
+
* Data hook for automated testing
|
|
267
|
+
* @default "carousel-previous"
|
|
268
|
+
*/
|
|
269
|
+
dataHook?: string;
|
|
181
270
|
}
|
|
182
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Button to navigate to the previous slide.
|
|
274
|
+
*/
|
|
183
275
|
function CarouselPrevious({
|
|
184
276
|
className,
|
|
185
|
-
variant =
|
|
186
|
-
size =
|
|
277
|
+
variant = "outline",
|
|
278
|
+
size = "default",
|
|
187
279
|
dataHook = "carousel-previous",
|
|
188
280
|
...props
|
|
189
|
-
}:
|
|
281
|
+
}: CarouselPreviousProps) {
|
|
190
282
|
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
191
283
|
|
|
192
284
|
return (
|
|
193
285
|
<Button
|
|
286
|
+
iconOnly
|
|
194
287
|
className={cn(
|
|
195
|
-
"absolute
|
|
288
|
+
"absolute",
|
|
196
289
|
orientation === "horizontal"
|
|
197
290
|
? "top-1/2 -left-12 -translate-y-1/2"
|
|
198
291
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
@@ -212,19 +305,49 @@ function CarouselPrevious({
|
|
|
212
305
|
);
|
|
213
306
|
}
|
|
214
307
|
|
|
308
|
+
CarouselPrevious.displayName = "CarouselPrevious";
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Props for CarouselNext component.
|
|
312
|
+
*/
|
|
313
|
+
interface CarouselNextProps extends Omit<
|
|
314
|
+
ButtonProps,
|
|
315
|
+
"variant" | "size" | "dataHook"
|
|
316
|
+
> {
|
|
317
|
+
/**
|
|
318
|
+
* Visual style variant of the button
|
|
319
|
+
* @default "outline"
|
|
320
|
+
*/
|
|
321
|
+
variant?: ButtonProps["variant"];
|
|
322
|
+
/**
|
|
323
|
+
* Size variant of the button
|
|
324
|
+
* @default "default"
|
|
325
|
+
*/
|
|
326
|
+
size?: ButtonProps["size"];
|
|
327
|
+
/**
|
|
328
|
+
* Data hook for automated testing
|
|
329
|
+
* @default "carousel-next"
|
|
330
|
+
*/
|
|
331
|
+
dataHook?: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Button to navigate to the next slide.
|
|
336
|
+
*/
|
|
215
337
|
function CarouselNext({
|
|
216
338
|
className,
|
|
217
|
-
variant =
|
|
218
|
-
size =
|
|
339
|
+
variant = "outline",
|
|
340
|
+
size = "default",
|
|
219
341
|
dataHook = "carousel-next",
|
|
220
342
|
...props
|
|
221
|
-
}:
|
|
343
|
+
}: CarouselNextProps) {
|
|
222
344
|
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
223
345
|
|
|
224
346
|
return (
|
|
225
347
|
<Button
|
|
348
|
+
iconOnly
|
|
226
349
|
className={cn(
|
|
227
|
-
"absolute
|
|
350
|
+
"absolute",
|
|
228
351
|
orientation === "horizontal"
|
|
229
352
|
? "top-1/2 -right-12 -translate-y-1/2"
|
|
230
353
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
@@ -244,6 +367,8 @@ function CarouselNext({
|
|
|
244
367
|
);
|
|
245
368
|
}
|
|
246
369
|
|
|
370
|
+
CarouselNext.displayName = "CarouselNext";
|
|
371
|
+
|
|
247
372
|
export {
|
|
248
373
|
type CarouselApi,
|
|
249
374
|
Carousel,
|
|
@@ -253,4 +378,4 @@ export {
|
|
|
253
378
|
CarouselNext,
|
|
254
379
|
};
|
|
255
380
|
|
|
256
|
-
export type { CarouselProps };
|
|
381
|
+
export type { CarouselProps, CarouselPreviousProps, CarouselNextProps };
|
|
@@ -40,7 +40,20 @@ export enum CentredLayoutBreakpoint {
|
|
|
40
40
|
|
|
41
41
|
interface CentredLayoutProps extends React.ComponentProps<"div"> {
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Data hook for automated testing (required)
|
|
44
|
+
*/
|
|
45
|
+
dataHook: string;
|
|
46
|
+
/**
|
|
47
|
+
* Tracking element identifier for analytics
|
|
48
|
+
*/
|
|
49
|
+
trackingEl?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Tracking label for analytics context
|
|
52
|
+
*/
|
|
53
|
+
trackingLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Breakpoint size variant
|
|
56
|
+
* @default "xl"
|
|
44
57
|
*/
|
|
45
58
|
breakpoint?: CentredLayoutBreakpoint;
|
|
46
59
|
/**
|
|
@@ -49,42 +62,61 @@ interface CentredLayoutProps extends React.ComponentProps<"div"> {
|
|
|
49
62
|
maxWidth?: string | number;
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
/**
|
|
66
|
+
* CentredLayout component for centering content with responsive max-width constraints.
|
|
67
|
+
*/
|
|
68
|
+
const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
|
|
69
|
+
(
|
|
70
|
+
{
|
|
71
|
+
className,
|
|
72
|
+
breakpoint = CentredLayoutBreakpoint.XL,
|
|
73
|
+
maxWidth,
|
|
74
|
+
children,
|
|
75
|
+
dataHook,
|
|
76
|
+
trackingEl,
|
|
77
|
+
trackingLabel,
|
|
78
|
+
...props
|
|
79
|
+
},
|
|
80
|
+
ref
|
|
81
|
+
) => {
|
|
82
|
+
// Map breakpoints to Tailwind max-width utility classes
|
|
83
|
+
const breakpointMaxWidthClass = {
|
|
84
|
+
[CentredLayoutBreakpoint.XL]: "max-w-7xl",
|
|
85
|
+
[CentredLayoutBreakpoint.LG]: "max-w-5xl",
|
|
86
|
+
[CentredLayoutBreakpoint.MD]: "max-w-3xl",
|
|
87
|
+
[CentredLayoutBreakpoint.SM]: "max-w-2xl",
|
|
88
|
+
};
|
|
66
89
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
// If custom maxWidth is provided, use inline style; otherwise use Tailwind class
|
|
91
|
+
const maxWidthStyle =
|
|
92
|
+
maxWidth !== undefined
|
|
93
|
+
? {
|
|
94
|
+
maxWidth: typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth,
|
|
95
|
+
}
|
|
96
|
+
: undefined;
|
|
72
97
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
ref={ref}
|
|
101
|
+
className={cn(
|
|
102
|
+
"bg-background flex min-h-screen items-center justify-center p-6",
|
|
103
|
+
!maxWidth && breakpointMaxWidthClass[breakpoint],
|
|
104
|
+
className
|
|
105
|
+
)}
|
|
106
|
+
data-hook={dataHook}
|
|
107
|
+
data-slot="centred-layout"
|
|
108
|
+
data-tracking-el={trackingEl}
|
|
109
|
+
data-tracking-label={trackingLabel}
|
|
110
|
+
style={maxWidthStyle}
|
|
111
|
+
{...props}
|
|
112
|
+
>
|
|
113
|
+
{children}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
CentredLayout.displayName = "CentredLayout";
|
|
88
120
|
|
|
89
121
|
export { CentredLayout };
|
|
90
122
|
|