@brightlocal/ui-components 0.1.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/LICENSE +21 -0
- package/README.md +349 -0
- package/dist/accordion.cjs +1 -0
- package/dist/accordion.d.ts +32 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +107 -0
- package/dist/alert-dialog.cjs +1 -0
- package/dist/alert-dialog.d.ts +15 -0
- package/dist/alert-dialog.d.ts.map +1 -0
- package/dist/alert-dialog.js +146 -0
- package/dist/alert.cjs +1 -0
- package/dist/alert.d.ts +16 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +174 -0
- package/dist/aspect-ratio.cjs +1 -0
- package/dist/aspect-ratio.d.ts +10 -0
- package/dist/aspect-ratio.d.ts.map +1 -0
- package/dist/aspect-ratio.js +22 -0
- package/dist/avatar.cjs +1 -0
- package/dist/avatar.d.ts +11 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +46 -0
- package/dist/badge.cjs +1 -0
- package/dist/badge.d.ts +19 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +50 -0
- package/dist/blocks/data-table.cjs +1 -0
- package/dist/blocks/data-table.d.ts +303 -0
- package/dist/blocks/data-table.d.ts.map +1 -0
- package/dist/blocks/data-table.js +555 -0
- package/dist/blocks/sidebar.cjs +1 -0
- package/dist/blocks/sidebar.d.ts +744 -0
- package/dist/blocks/sidebar.d.ts.map +1 -0
- package/dist/blocks/sidebar.js +839 -0
- package/dist/breadcrumb.cjs +1 -0
- package/dist/breadcrumb.d.ts +12 -0
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +102 -0
- package/dist/button.cjs +1 -0
- package/dist/button.d.ts +73 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +195 -0
- package/dist/calendar.cjs +1 -0
- package/dist/calendar.d.ts +28 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +191 -0
- package/dist/card.cjs +1 -0
- package/dist/card.d.ts +28 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/card.js +131 -0
- package/dist/carousel.cjs +1 -0
- package/dist/carousel.d.ts +21 -0
- package/dist/carousel.d.ts.map +1 -0
- package/dist/carousel.js +185 -0
- package/dist/centred-layout.cjs +1 -0
- package/dist/centred-layout.d.ts +49 -0
- package/dist/centred-layout.d.ts.map +1 -0
- package/dist/centred-layout.js +35 -0
- package/dist/chart.cjs +10 -0
- package/dist/chart.d.ts +83 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +254 -0
- package/dist/checkbox.cjs +1 -0
- package/dist/checkbox.d.ts +15 -0
- package/dist/checkbox.d.ts.map +1 -0
- package/dist/checkbox.js +96 -0
- package/dist/collapsible.cjs +1 -0
- package/dist/collapsible.d.ts +18 -0
- package/dist/collapsible.d.ts.map +1 -0
- package/dist/collapsible.js +58 -0
- package/dist/combobox.cjs +1 -0
- package/dist/combobox.d.ts +65 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +203 -0
- package/dist/command.cjs +1 -0
- package/dist/command.d.ts +44 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +166 -0
- package/dist/context-menu.cjs +1 -0
- package/dist/context-menu.d.ts +42 -0
- package/dist/context-menu.d.ts.map +1 -0
- package/dist/context-menu.js +226 -0
- package/dist/date-picker.cjs +1 -0
- package/dist/date-picker.d.ts +54 -0
- package/dist/date-picker.d.ts.map +1 -0
- package/dist/date-picker.js +95 -0
- package/dist/dialog.cjs +1 -0
- package/dist/dialog.d.ts +20 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +130 -0
- package/dist/drawer.cjs +1 -0
- package/dist/drawer.d.ts +22 -0
- package/dist/drawer.d.ts.map +1 -0
- package/dist/drawer.js +149 -0
- package/dist/dropdown-menu.cjs +1 -0
- package/dist/dropdown-menu.d.ts +253 -0
- package/dist/dropdown-menu.d.ts.map +1 -0
- package/dist/dropdown-menu.js +325 -0
- package/dist/field.cjs +1 -0
- package/dist/field.d.ts +21 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +148 -0
- package/dist/global-layout.cjs +1 -0
- package/dist/global-layout.d.ts +60 -0
- package/dist/global-layout.d.ts.map +1 -0
- package/dist/global-layout.js +87 -0
- package/dist/hooks/use-mobile.cjs +1 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-mobile.js +16 -0
- package/dist/hover-card.cjs +1 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.d.ts.map +1 -0
- package/dist/hover-card.js +71 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +412 -0
- package/dist/input-base.cjs +1 -0
- package/dist/input-base.d.ts +28 -0
- package/dist/input-base.d.ts.map +1 -0
- package/dist/input-base.js +56 -0
- package/dist/input-group.cjs +1 -0
- package/dist/input-group.d.ts +26 -0
- package/dist/input-group.d.ts.map +1 -0
- package/dist/input-group.js +116 -0
- package/dist/input-otp.cjs +1 -0
- package/dist/input-otp.d.ts +45 -0
- package/dist/input-otp.d.ts.map +1 -0
- package/dist/input-otp.js +186 -0
- package/dist/input-password.cjs +1 -0
- package/dist/input-password.d.ts +38 -0
- package/dist/input-password.d.ts.map +1 -0
- package/dist/input-password.js +101 -0
- package/dist/input.cjs +1 -0
- package/dist/input.d.ts +32 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +146 -0
- package/dist/label.cjs +1 -0
- package/dist/label.d.ts +12 -0
- package/dist/label.d.ts.map +1 -0
- package/dist/label.js +34 -0
- package/dist/lib/utils.cjs +1 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +8 -0
- package/dist/link.cjs +1 -0
- package/dist/link.d.ts +29 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.figma.d.ts +2 -0
- package/dist/link.figma.d.ts.map +1 -0
- package/dist/link.js +71 -0
- package/dist/logo.cjs +1 -0
- package/dist/logo.d.ts +25 -0
- package/dist/logo.d.ts.map +1 -0
- package/dist/logo.js +71 -0
- package/dist/menubar.cjs +1 -0
- package/dist/menubar.d.ts +106 -0
- package/dist/menubar.d.ts.map +1 -0
- package/dist/menubar.js +270 -0
- package/dist/navigation-menu.cjs +1 -0
- package/dist/navigation-menu.d.ts +108 -0
- package/dist/navigation-menu.d.ts.map +1 -0
- package/dist/navigation-menu.js +175 -0
- package/dist/pagination.cjs +1 -0
- package/dist/pagination.d.ts +81 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +216 -0
- package/dist/popover.cjs +1 -0
- package/dist/popover.d.ts +8 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +44 -0
- package/dist/progress.cjs +1 -0
- package/dist/progress.d.ts +29 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +64 -0
- package/dist/radio-group.cjs +1 -0
- package/dist/radio-group.d.ts +33 -0
- package/dist/radio-group.d.ts.map +1 -0
- package/dist/radio-group.js +193 -0
- package/dist/rating.cjs +1 -0
- package/dist/rating.d.ts +22 -0
- package/dist/rating.d.ts.map +1 -0
- package/dist/rating.js +51 -0
- package/dist/resizable.cjs +1 -0
- package/dist/resizable.d.ts +14 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +46 -0
- package/dist/scroll-area.cjs +1 -0
- package/dist/scroll-area.d.ts +12 -0
- package/dist/scroll-area.d.ts.map +1 -0
- package/dist/scroll-area.js +67 -0
- package/dist/select.cjs +1 -0
- package/dist/select.d.ts +77 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +259 -0
- package/dist/separator.cjs +1 -0
- package/dist/separator.d.ts +14 -0
- package/dist/separator.d.ts.map +1 -0
- package/dist/separator.js +43 -0
- package/dist/sheet.cjs +1 -0
- package/dist/sheet.d.ts +38 -0
- package/dist/sheet.d.ts.map +1 -0
- package/dist/sheet.js +190 -0
- package/dist/skeleton.cjs +1 -0
- package/dist/skeleton.d.ts +5 -0
- package/dist/skeleton.d.ts.map +1 -0
- package/dist/skeleton.js +15 -0
- package/dist/slider.cjs +1 -0
- package/dist/slider.d.ts +19 -0
- package/dist/slider.d.ts.map +1 -0
- package/dist/slider.js +69 -0
- package/dist/sonner.cjs +1 -0
- package/dist/sonner.d.ts +188 -0
- package/dist/sonner.d.ts.map +1 -0
- package/dist/sonner.js +150 -0
- package/dist/split-layout.cjs +1 -0
- package/dist/split-layout.d.ts +42 -0
- package/dist/split-layout.d.ts.map +1 -0
- package/dist/split-layout.js +108 -0
- package/dist/switch.cjs +1 -0
- package/dist/switch.d.ts +43 -0
- package/dist/switch.d.ts.map +1 -0
- package/dist/switch.figma.d.ts +2 -0
- package/dist/switch.figma.d.ts.map +1 -0
- package/dist/switch.js +110 -0
- package/dist/table.cjs +1 -0
- package/dist/table.d.ts +95 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +164 -0
- package/dist/tabs.cjs +1 -0
- package/dist/tabs.d.ts +29 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +96 -0
- package/dist/textarea.cjs +1 -0
- package/dist/textarea.d.ts +23 -0
- package/dist/textarea.d.ts.map +1 -0
- package/dist/textarea.js +47 -0
- package/dist/toggle-group.cjs +1 -0
- package/dist/toggle-group.d.ts +25 -0
- package/dist/toggle-group.d.ts.map +1 -0
- package/dist/toggle-group.js +74 -0
- package/dist/toggle.cjs +1 -0
- package/dist/toggle.d.ts +44 -0
- package/dist/toggle.d.ts.map +1 -0
- package/dist/toggle.figma.d.ts +2 -0
- package/dist/toggle.figma.d.ts.map +1 -0
- package/dist/toggle.js +57 -0
- package/dist/tooltip.cjs +1 -0
- package/dist/tooltip.d.ts +66 -0
- package/dist/tooltip.d.ts.map +1 -0
- package/dist/tooltip.js +78 -0
- package/package.json +184 -0
- package/src/blocks/data-table.tsx +1166 -0
- package/src/blocks/sidebar.tsx +1830 -0
- package/src/components/.gitkeep +0 -0
- package/src/components/accordion.tsx +142 -0
- package/src/components/alert-dialog.tsx +157 -0
- package/src/components/alert.tsx +199 -0
- package/src/components/aspect-ratio.tsx +30 -0
- package/src/components/avatar.tsx +56 -0
- package/src/components/badge.tsx +72 -0
- package/src/components/breadcrumb.tsx +109 -0
- package/src/components/button.tsx +296 -0
- package/src/components/calendar.tsx +234 -0
- package/src/components/card.tsx +158 -0
- package/src/components/carousel.tsx +256 -0
- package/src/components/centred-layout.tsx +91 -0
- package/src/components/chart.tsx +456 -0
- package/src/components/checkbox.tsx +132 -0
- package/src/components/collapsible.tsx +68 -0
- package/src/components/combobox.tsx +321 -0
- package/src/components/command.tsx +220 -0
- package/src/components/context-menu.tsx +305 -0
- package/src/components/date-picker.tsx +155 -0
- package/src/components/dialog.tsx +152 -0
- package/src/components/drawer.tsx +168 -0
- package/src/components/dropdown-menu.tsx +575 -0
- package/src/components/field.tsx +155 -0
- package/src/components/global-layout.tsx +153 -0
- package/src/components/hover-card.tsx +121 -0
- package/src/components/input-base.tsx +86 -0
- package/src/components/input-group.tsx +158 -0
- package/src/components/input-otp.tsx +327 -0
- package/src/components/input-password.tsx +191 -0
- package/src/components/input.tsx +220 -0
- package/src/components/label.tsx +42 -0
- package/src/components/link.figma.tsx +71 -0
- package/src/components/link.tsx +105 -0
- package/src/components/logo.tsx +97 -0
- package/src/components/menubar.tsx +379 -0
- package/src/components/navigation-menu.tsx +324 -0
- package/src/components/pagination.tsx +368 -0
- package/src/components/popover.tsx +46 -0
- package/src/components/progress.tsx +100 -0
- package/src/components/radio-group.tsx +281 -0
- package/src/components/rating.tsx +87 -0
- package/src/components/resizable.tsx +66 -0
- package/src/components/scroll-area.tsx +72 -0
- package/src/components/select.tsx +442 -0
- package/src/components/separator.tsx +53 -0
- package/src/components/sheet.tsx +220 -0
- package/src/components/skeleton.tsx +17 -0
- package/src/components/slider.tsx +86 -0
- package/src/components/sonner.tsx +396 -0
- package/src/components/split-layout.tsx +155 -0
- package/src/components/switch.figma.tsx +115 -0
- package/src/components/switch.tsx +173 -0
- package/src/components/table.tsx +277 -0
- package/src/components/tabs.tsx +142 -0
- package/src/components/textarea.tsx +77 -0
- package/src/components/toggle-group.tsx +109 -0
- package/src/components/toggle.figma.tsx +81 -0
- package/src/components/toggle.tsx +103 -0
- package/src/components/tooltip.tsx +156 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/index.ts +67 -0
- package/src/lib/utils.ts +6 -0
- package/src/types/external-modules.d.ts +16 -0
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Available card visual variants
|
|
8
|
+
*/
|
|
9
|
+
export enum CardVariant {
|
|
10
|
+
/** Default card with background, border */
|
|
11
|
+
DEFAULT = "default",
|
|
12
|
+
/** Transparent card with no background or border */
|
|
13
|
+
TRANSPARENT = "transparent",
|
|
14
|
+
/** Card with border only, no background or shadow */
|
|
15
|
+
BORDER = "border",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cardVariants = cva(
|
|
19
|
+
["flex", "flex-col", "gap-8", "rounded-[14px]", "py-8", "transition-colors"],
|
|
20
|
+
{
|
|
21
|
+
variants: {
|
|
22
|
+
variant: {
|
|
23
|
+
default: [
|
|
24
|
+
"bg-card",
|
|
25
|
+
"text-card-foreground",
|
|
26
|
+
"border",
|
|
27
|
+
"border-card-border",
|
|
28
|
+
],
|
|
29
|
+
transparent: ["bg-transparent", "text-foreground"],
|
|
30
|
+
border: [
|
|
31
|
+
"bg-transparent",
|
|
32
|
+
"text-foreground",
|
|
33
|
+
"border",
|
|
34
|
+
"border-border",
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultVariants: {
|
|
39
|
+
variant: CardVariant.DEFAULT,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
type CardProps = React.ComponentProps<"div"> & {
|
|
45
|
+
variant?: CardVariant;
|
|
46
|
+
dataHook: string;
|
|
47
|
+
trackingEl?: string;
|
|
48
|
+
trackingLabel?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const Card = React.forwardRef<HTMLDivElement, CardProps>(
|
|
52
|
+
(
|
|
53
|
+
{
|
|
54
|
+
className,
|
|
55
|
+
variant = CardVariant.DEFAULT,
|
|
56
|
+
dataHook,
|
|
57
|
+
trackingEl,
|
|
58
|
+
trackingLabel,
|
|
59
|
+
...props
|
|
60
|
+
},
|
|
61
|
+
ref
|
|
62
|
+
) => {
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
ref={ref}
|
|
66
|
+
className={cn(cardVariants({ variant }), className)}
|
|
67
|
+
data-hook={dataHook}
|
|
68
|
+
data-slot="card"
|
|
69
|
+
data-tracking-el={trackingEl || `card-${variant}`}
|
|
70
|
+
data-tracking-label={trackingLabel}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
Card.displayName = "Card";
|
|
78
|
+
|
|
79
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
className={cn(
|
|
83
|
+
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-8 has-data-[slot=card-action]:grid-cols-[1fr_auto]",
|
|
84
|
+
className
|
|
85
|
+
)}
|
|
86
|
+
data-slot="card-header"
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
className={cn("heading-sm", className)}
|
|
96
|
+
data-slot="card-title"
|
|
97
|
+
{...props}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
103
|
+
return (
|
|
104
|
+
<div
|
|
105
|
+
className={cn(
|
|
106
|
+
"text-muted-foreground text-sm leading-normal font-normal",
|
|
107
|
+
className
|
|
108
|
+
)}
|
|
109
|
+
data-slot="card-description"
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
116
|
+
return (
|
|
117
|
+
<div
|
|
118
|
+
className={cn(
|
|
119
|
+
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
120
|
+
className
|
|
121
|
+
)}
|
|
122
|
+
data-slot="card-action"
|
|
123
|
+
{...props}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
129
|
+
return (
|
|
130
|
+
<div
|
|
131
|
+
className={cn("px-8", className)}
|
|
132
|
+
data-slot="card-content"
|
|
133
|
+
{...props}
|
|
134
|
+
/>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
139
|
+
return (
|
|
140
|
+
<div
|
|
141
|
+
className={cn("flex items-center px-8", className)}
|
|
142
|
+
data-slot="card-footer"
|
|
143
|
+
{...props}
|
|
144
|
+
/>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
Card,
|
|
150
|
+
CardHeader,
|
|
151
|
+
CardFooter,
|
|
152
|
+
CardTitle,
|
|
153
|
+
CardAction,
|
|
154
|
+
CardDescription,
|
|
155
|
+
CardContent,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type { CardProps };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import useEmblaCarousel, {
|
|
3
|
+
type UseEmblaCarouselType,
|
|
4
|
+
} from "embla-carousel-react";
|
|
5
|
+
import { ArrowLeft, ArrowRight } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
ButtonVariant,
|
|
11
|
+
ButtonSize,
|
|
12
|
+
} from "@brightlocal/ui-components/button";
|
|
13
|
+
|
|
14
|
+
type CarouselApi = UseEmblaCarouselType[1];
|
|
15
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
|
|
16
|
+
type CarouselOptions = UseCarouselParameters[0];
|
|
17
|
+
type CarouselPlugin = UseCarouselParameters[1];
|
|
18
|
+
|
|
19
|
+
type CarouselProps = {
|
|
20
|
+
opts?: CarouselOptions;
|
|
21
|
+
plugins?: CarouselPlugin;
|
|
22
|
+
orientation?: "horizontal" | "vertical";
|
|
23
|
+
setApi?: (api: CarouselApi) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type CarouselContextProps = {
|
|
27
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0];
|
|
28
|
+
api: ReturnType<typeof useEmblaCarousel>[1];
|
|
29
|
+
scrollPrev: () => void;
|
|
30
|
+
scrollNext: () => void;
|
|
31
|
+
canScrollPrev: boolean;
|
|
32
|
+
canScrollNext: boolean;
|
|
33
|
+
} & CarouselProps;
|
|
34
|
+
|
|
35
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null);
|
|
36
|
+
|
|
37
|
+
function useCarousel() {
|
|
38
|
+
const context = React.useContext(CarouselContext);
|
|
39
|
+
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error("useCarousel must be used within a <Carousel />");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return context;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function Carousel({
|
|
48
|
+
orientation = "horizontal",
|
|
49
|
+
opts,
|
|
50
|
+
setApi,
|
|
51
|
+
plugins,
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
...props
|
|
55
|
+
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
56
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
57
|
+
{
|
|
58
|
+
...opts,
|
|
59
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
60
|
+
},
|
|
61
|
+
plugins
|
|
62
|
+
);
|
|
63
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
64
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
65
|
+
|
|
66
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
67
|
+
if (!api) return;
|
|
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
|
+
}
|
|
92
|
+
},
|
|
93
|
+
[orientation, scrollPrev, scrollNext]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (!api || !setApi) return;
|
|
98
|
+
setApi(api);
|
|
99
|
+
}, [api, setApi]);
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (!api) return;
|
|
103
|
+
onSelect(api);
|
|
104
|
+
api.on("reInit", onSelect);
|
|
105
|
+
api.on("select", onSelect);
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
api?.off("reInit", onSelect);
|
|
109
|
+
api?.off("select", onSelect);
|
|
110
|
+
};
|
|
111
|
+
}, [api, onSelect]);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<CarouselContext.Provider
|
|
115
|
+
value={{
|
|
116
|
+
carouselRef,
|
|
117
|
+
api,
|
|
118
|
+
opts,
|
|
119
|
+
orientation:
|
|
120
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
121
|
+
scrollPrev,
|
|
122
|
+
scrollNext,
|
|
123
|
+
canScrollPrev,
|
|
124
|
+
canScrollNext,
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
<div
|
|
128
|
+
aria-roledescription="carousel"
|
|
129
|
+
className={cn("relative", className)}
|
|
130
|
+
data-slot="carousel"
|
|
131
|
+
role="region"
|
|
132
|
+
onKeyDownCapture={handleKeyDown}
|
|
133
|
+
{...props}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</div>
|
|
137
|
+
</CarouselContext.Provider>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
142
|
+
const { carouselRef, orientation } = useCarousel();
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<div
|
|
146
|
+
ref={carouselRef}
|
|
147
|
+
className={cn(
|
|
148
|
+
"overflow-hidden",
|
|
149
|
+
orientation === "vertical" && "h-[400px]"
|
|
150
|
+
)}
|
|
151
|
+
data-slot="carousel-content"
|
|
152
|
+
>
|
|
153
|
+
<div
|
|
154
|
+
className={cn(
|
|
155
|
+
"flex gap-4",
|
|
156
|
+
orientation === "horizontal" ? "" : "h-full flex-col",
|
|
157
|
+
className
|
|
158
|
+
)}
|
|
159
|
+
{...props}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
166
|
+
const { orientation } = useCarousel();
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
aria-roledescription="slide"
|
|
171
|
+
className={cn(
|
|
172
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
173
|
+
orientation === "horizontal" ? "pl-1" : "pt-1",
|
|
174
|
+
className
|
|
175
|
+
)}
|
|
176
|
+
data-slot="carousel-item"
|
|
177
|
+
role="group"
|
|
178
|
+
{...props}
|
|
179
|
+
/>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function CarouselPrevious({
|
|
184
|
+
className,
|
|
185
|
+
variant = ButtonVariant.OUTLINE,
|
|
186
|
+
size = ButtonSize.SM,
|
|
187
|
+
dataHook = "carousel-previous",
|
|
188
|
+
...props
|
|
189
|
+
}: React.ComponentProps<typeof Button>) {
|
|
190
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Button
|
|
194
|
+
className={cn(
|
|
195
|
+
"absolute size-8 rounded-full",
|
|
196
|
+
orientation === "horizontal"
|
|
197
|
+
? "top-1/2 -left-12 -translate-y-1/2"
|
|
198
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
199
|
+
className
|
|
200
|
+
)}
|
|
201
|
+
data-slot="carousel-previous"
|
|
202
|
+
dataHook={dataHook}
|
|
203
|
+
disabled={!canScrollPrev}
|
|
204
|
+
size={size}
|
|
205
|
+
variant={variant}
|
|
206
|
+
onClick={scrollPrev}
|
|
207
|
+
{...props}
|
|
208
|
+
>
|
|
209
|
+
<ArrowLeft />
|
|
210
|
+
<span className="sr-only">Previous slide</span>
|
|
211
|
+
</Button>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function CarouselNext({
|
|
216
|
+
className,
|
|
217
|
+
variant = ButtonVariant.OUTLINE,
|
|
218
|
+
size = ButtonSize.SM,
|
|
219
|
+
dataHook = "carousel-next",
|
|
220
|
+
...props
|
|
221
|
+
}: React.ComponentProps<typeof Button>) {
|
|
222
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<Button
|
|
226
|
+
className={cn(
|
|
227
|
+
"absolute size-8 rounded-full",
|
|
228
|
+
orientation === "horizontal"
|
|
229
|
+
? "top-1/2 -right-12 -translate-y-1/2"
|
|
230
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
231
|
+
className
|
|
232
|
+
)}
|
|
233
|
+
data-slot="carousel-next"
|
|
234
|
+
dataHook={dataHook}
|
|
235
|
+
disabled={!canScrollNext}
|
|
236
|
+
size={size}
|
|
237
|
+
variant={variant}
|
|
238
|
+
onClick={scrollNext}
|
|
239
|
+
{...props}
|
|
240
|
+
>
|
|
241
|
+
<ArrowRight />
|
|
242
|
+
<span className="sr-only">Next slide</span>
|
|
243
|
+
</Button>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export {
|
|
248
|
+
type CarouselApi,
|
|
249
|
+
Carousel,
|
|
250
|
+
CarouselContent,
|
|
251
|
+
CarouselItem,
|
|
252
|
+
CarouselPrevious,
|
|
253
|
+
CarouselNext,
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type { CarouselProps };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CentredLayout provides a responsive centered container with max-width constraints
|
|
7
|
+
* based on different breakpoint sizes.
|
|
8
|
+
*
|
|
9
|
+
* Breakpoints align with Tailwind's default breakpoints:
|
|
10
|
+
* - XL: 1280px (max-w-7xl)
|
|
11
|
+
* - LG: 1024px (max-w-5xl)
|
|
12
|
+
* - MD: 768px (max-w-3xl)
|
|
13
|
+
* - SM: 640px (max-w-2xl)
|
|
14
|
+
*
|
|
15
|
+
* The component centers content horizontally and applies consistent padding
|
|
16
|
+
* across all breakpoints.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Breakpoint variants for CentredLayout
|
|
21
|
+
*/
|
|
22
|
+
export enum CentredLayoutBreakpoint {
|
|
23
|
+
/**
|
|
24
|
+
* Extra large breakpoint (1280px max-width)
|
|
25
|
+
*/
|
|
26
|
+
XL = "xl",
|
|
27
|
+
/**
|
|
28
|
+
* Large breakpoint (1024px max-width)
|
|
29
|
+
*/
|
|
30
|
+
LG = "lg",
|
|
31
|
+
/**
|
|
32
|
+
* Medium breakpoint (768px max-width)
|
|
33
|
+
*/
|
|
34
|
+
MD = "md",
|
|
35
|
+
/**
|
|
36
|
+
* Small breakpoint (640px max-width)
|
|
37
|
+
*/
|
|
38
|
+
SM = "sm",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface CentredLayoutProps extends React.ComponentProps<"div"> {
|
|
42
|
+
/**
|
|
43
|
+
* Breakpoint size variant (default: xl)
|
|
44
|
+
*/
|
|
45
|
+
breakpoint?: CentredLayoutBreakpoint;
|
|
46
|
+
/**
|
|
47
|
+
* Custom max-width value (overrides breakpoint)
|
|
48
|
+
*/
|
|
49
|
+
maxWidth?: string | number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function CentredLayout({
|
|
53
|
+
className,
|
|
54
|
+
breakpoint = CentredLayoutBreakpoint.XL,
|
|
55
|
+
maxWidth,
|
|
56
|
+
children,
|
|
57
|
+
...props
|
|
58
|
+
}: CentredLayoutProps) {
|
|
59
|
+
// Map breakpoints to Tailwind max-width utility classes
|
|
60
|
+
const breakpointMaxWidthClass = {
|
|
61
|
+
[CentredLayoutBreakpoint.XL]: "max-w-7xl",
|
|
62
|
+
[CentredLayoutBreakpoint.LG]: "max-w-5xl",
|
|
63
|
+
[CentredLayoutBreakpoint.MD]: "max-w-3xl",
|
|
64
|
+
[CentredLayoutBreakpoint.SM]: "max-w-2xl",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// If custom maxWidth is provided, use inline style; otherwise use Tailwind class
|
|
68
|
+
const maxWidthStyle =
|
|
69
|
+
maxWidth !== undefined
|
|
70
|
+
? { maxWidth: typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth }
|
|
71
|
+
: undefined;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
className={cn(
|
|
76
|
+
"bg-background flex min-h-screen items-center justify-center p-6",
|
|
77
|
+
!maxWidth && breakpointMaxWidthClass[breakpoint],
|
|
78
|
+
className
|
|
79
|
+
)}
|
|
80
|
+
data-slot="centred-layout"
|
|
81
|
+
style={maxWidthStyle}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { CentredLayout };
|
|
90
|
+
|
|
91
|
+
export type { CentredLayoutProps };
|