vite-shadcn-ui-cli 1.0.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 +52 -0
- package/components.json +21 -0
- package/eslint.config.js +28 -0
- package/index.html +13 -0
- package/package.json +55 -0
- package/postcss.config.js +6 -0
- package/public/vite.svg +1 -0
- package/src/App.css +5 -0
- package/src/App.tsx +14 -0
- package/src/assets/react.svg +1 -0
- package/src/components/ui/accordion.tsx +58 -0
- package/src/components/ui/alert-dialog.tsx +141 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/aspect-ratio.tsx +7 -0
- package/src/components/ui/avatar.tsx +50 -0
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/breadcrumb.tsx +115 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +66 -0
- package/src/components/ui/card.tsx +79 -0
- package/src/components/ui/carousel.tsx +262 -0
- package/src/components/ui/chart.tsx +365 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/collapsible.tsx +11 -0
- package/src/components/ui/command.tsx +155 -0
- package/src/components/ui/context-menu.tsx +200 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/drawer.tsx +118 -0
- package/src/components/ui/dropdown-menu.tsx +200 -0
- package/src/components/ui/form.tsx +178 -0
- package/src/components/ui/hover-card.tsx +29 -0
- package/src/components/ui/input-otp.tsx +71 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/menubar.tsx +236 -0
- package/src/components/ui/navigation-menu.tsx +128 -0
- package/src/components/ui/pagination.tsx +67 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/progress.tsx +28 -0
- package/src/components/ui/radio-group.tsx +44 -0
- package/src/components/ui/resizable.tsx +45 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/select.tsx +160 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/sheet.tsx +140 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/slider.tsx +28 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +117 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/toast.tsx +129 -0
- package/src/components/ui/toaster.tsx +35 -0
- package/src/components/ui/toggle-group.tsx +61 -0
- package/src/components/ui/toggle.tsx +45 -0
- package/src/components/ui/tooltip.tsx +30 -0
- package/src/index.css +93 -0
- package/src/lib/utils.ts +6 -0
- package/src/main.tsx +10 -0
- package/src/vite-env.d.ts +1 -0
- package/tailwind.config.js +57 -0
- package/tsconfig.app.json +32 -0
- package/tsconfig.json +17 -0
- package/tsconfig.node.json +24 -0
- package/vite.config.ts +12 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
import * as React from "react"
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
3
|
+
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
4
|
+
|
5
|
+
import { cn } from "@/lib/utils"
|
6
|
+
|
7
|
+
const Breadcrumb = React.forwardRef<
|
8
|
+
HTMLElement,
|
9
|
+
React.ComponentPropsWithoutRef<"nav"> & {
|
10
|
+
separator?: React.ReactNode
|
11
|
+
}
|
12
|
+
>(({ ...props }, ref) => <nav ref={ref} aria-label="breadcrumb" {...props} />)
|
13
|
+
Breadcrumb.displayName = "Breadcrumb"
|
14
|
+
|
15
|
+
const BreadcrumbList = React.forwardRef<
|
16
|
+
HTMLOListElement,
|
17
|
+
React.ComponentPropsWithoutRef<"ol">
|
18
|
+
>(({ className, ...props }, ref) => (
|
19
|
+
<ol
|
20
|
+
ref={ref}
|
21
|
+
className={cn(
|
22
|
+
"flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",
|
23
|
+
className
|
24
|
+
)}
|
25
|
+
{...props}
|
26
|
+
/>
|
27
|
+
))
|
28
|
+
BreadcrumbList.displayName = "BreadcrumbList"
|
29
|
+
|
30
|
+
const BreadcrumbItem = React.forwardRef<
|
31
|
+
HTMLLIElement,
|
32
|
+
React.ComponentPropsWithoutRef<"li">
|
33
|
+
>(({ className, ...props }, ref) => (
|
34
|
+
<li
|
35
|
+
ref={ref}
|
36
|
+
className={cn("inline-flex items-center gap-1.5", className)}
|
37
|
+
{...props}
|
38
|
+
/>
|
39
|
+
))
|
40
|
+
BreadcrumbItem.displayName = "BreadcrumbItem"
|
41
|
+
|
42
|
+
const BreadcrumbLink = React.forwardRef<
|
43
|
+
HTMLAnchorElement,
|
44
|
+
React.ComponentPropsWithoutRef<"a"> & {
|
45
|
+
asChild?: boolean
|
46
|
+
}
|
47
|
+
>(({ asChild, className, ...props }, ref) => {
|
48
|
+
const Comp = asChild ? Slot : "a"
|
49
|
+
|
50
|
+
return (
|
51
|
+
<Comp
|
52
|
+
ref={ref}
|
53
|
+
className={cn("transition-colors hover:text-foreground", className)}
|
54
|
+
{...props}
|
55
|
+
/>
|
56
|
+
)
|
57
|
+
})
|
58
|
+
BreadcrumbLink.displayName = "BreadcrumbLink"
|
59
|
+
|
60
|
+
const BreadcrumbPage = React.forwardRef<
|
61
|
+
HTMLSpanElement,
|
62
|
+
React.ComponentPropsWithoutRef<"span">
|
63
|
+
>(({ className, ...props }, ref) => (
|
64
|
+
<span
|
65
|
+
ref={ref}
|
66
|
+
role="link"
|
67
|
+
aria-disabled="true"
|
68
|
+
aria-current="page"
|
69
|
+
className={cn("font-normal text-foreground", className)}
|
70
|
+
{...props}
|
71
|
+
/>
|
72
|
+
))
|
73
|
+
BreadcrumbPage.displayName = "BreadcrumbPage"
|
74
|
+
|
75
|
+
const BreadcrumbSeparator = ({
|
76
|
+
children,
|
77
|
+
className,
|
78
|
+
...props
|
79
|
+
}: React.ComponentProps<"li">) => (
|
80
|
+
<li
|
81
|
+
role="presentation"
|
82
|
+
aria-hidden="true"
|
83
|
+
className={cn("[&>svg]:size-3.5", className)}
|
84
|
+
{...props}
|
85
|
+
>
|
86
|
+
{children ?? <ChevronRight />}
|
87
|
+
</li>
|
88
|
+
)
|
89
|
+
BreadcrumbSeparator.displayName = "BreadcrumbSeparator"
|
90
|
+
|
91
|
+
const BreadcrumbEllipsis = ({
|
92
|
+
className,
|
93
|
+
...props
|
94
|
+
}: React.ComponentProps<"span">) => (
|
95
|
+
<span
|
96
|
+
role="presentation"
|
97
|
+
aria-hidden="true"
|
98
|
+
className={cn("flex h-9 w-9 items-center justify-center", className)}
|
99
|
+
{...props}
|
100
|
+
>
|
101
|
+
<MoreHorizontal className="h-4 w-4" />
|
102
|
+
<span className="sr-only">More</span>
|
103
|
+
</span>
|
104
|
+
)
|
105
|
+
BreadcrumbEllipsis.displayName = "BreadcrumbElipssis"
|
106
|
+
|
107
|
+
export {
|
108
|
+
Breadcrumb,
|
109
|
+
BreadcrumbList,
|
110
|
+
BreadcrumbItem,
|
111
|
+
BreadcrumbLink,
|
112
|
+
BreadcrumbPage,
|
113
|
+
BreadcrumbSeparator,
|
114
|
+
BreadcrumbEllipsis,
|
115
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import * as React from "react"
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
4
|
+
|
5
|
+
import { cn } from "@/lib/utils"
|
6
|
+
|
7
|
+
const buttonVariants = cva(
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
9
|
+
{
|
10
|
+
variants: {
|
11
|
+
variant: {
|
12
|
+
default:
|
13
|
+
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
14
|
+
destructive:
|
15
|
+
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
16
|
+
outline:
|
17
|
+
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
18
|
+
secondary:
|
19
|
+
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
20
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
22
|
+
},
|
23
|
+
size: {
|
24
|
+
default: "h-9 px-4 py-2",
|
25
|
+
sm: "h-8 rounded-md px-3 text-xs",
|
26
|
+
lg: "h-10 rounded-md px-8",
|
27
|
+
icon: "h-9 w-9",
|
28
|
+
},
|
29
|
+
},
|
30
|
+
defaultVariants: {
|
31
|
+
variant: "default",
|
32
|
+
size: "default",
|
33
|
+
},
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
37
|
+
export interface ButtonProps
|
38
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
39
|
+
VariantProps<typeof buttonVariants> {
|
40
|
+
asChild?: boolean
|
41
|
+
}
|
42
|
+
|
43
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
44
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
45
|
+
const Comp = asChild ? Slot : "button"
|
46
|
+
return (
|
47
|
+
<Comp
|
48
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
49
|
+
ref={ref}
|
50
|
+
{...props}
|
51
|
+
/>
|
52
|
+
)
|
53
|
+
}
|
54
|
+
)
|
55
|
+
Button.displayName = "Button"
|
56
|
+
|
57
|
+
export { Button, buttonVariants }
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use client"
|
2
|
+
|
3
|
+
import * as React from "react"
|
4
|
+
import { ChevronLeft, ChevronRight } from "lucide-react"
|
5
|
+
import { DayPicker } from "react-day-picker"
|
6
|
+
|
7
|
+
import { cn } from "@/lib/utils"
|
8
|
+
import { buttonVariants } from "@/components/ui/button"
|
9
|
+
|
10
|
+
export type CalendarProps = React.ComponentProps<typeof DayPicker>
|
11
|
+
|
12
|
+
function Calendar({
|
13
|
+
className,
|
14
|
+
classNames,
|
15
|
+
showOutsideDays = true,
|
16
|
+
...props
|
17
|
+
}: CalendarProps) {
|
18
|
+
return (
|
19
|
+
<DayPicker
|
20
|
+
showOutsideDays={showOutsideDays}
|
21
|
+
className={cn("p-3", className)}
|
22
|
+
classNames={{
|
23
|
+
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
24
|
+
month: "space-y-4",
|
25
|
+
caption: "flex justify-center pt-1 relative items-center",
|
26
|
+
caption_label: "text-sm font-medium",
|
27
|
+
nav: "space-x-1 flex items-center",
|
28
|
+
nav_button: cn(
|
29
|
+
buttonVariants({ variant: "outline" }),
|
30
|
+
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"
|
31
|
+
),
|
32
|
+
nav_button_previous: "absolute left-1",
|
33
|
+
nav_button_next: "absolute right-1",
|
34
|
+
table: "w-full border-collapse space-y-1",
|
35
|
+
head_row: "flex",
|
36
|
+
head_cell:
|
37
|
+
"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]",
|
38
|
+
row: "flex w-full mt-2",
|
39
|
+
cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
|
40
|
+
day: cn(
|
41
|
+
buttonVariants({ variant: "ghost" }),
|
42
|
+
"h-9 w-9 p-0 font-normal aria-selected:opacity-100"
|
43
|
+
),
|
44
|
+
day_range_end: "day-range-end",
|
45
|
+
day_selected:
|
46
|
+
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
|
47
|
+
day_today: "bg-accent text-accent-foreground",
|
48
|
+
day_outside:
|
49
|
+
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
|
50
|
+
day_disabled: "text-muted-foreground opacity-50",
|
51
|
+
day_range_middle:
|
52
|
+
"aria-selected:bg-accent aria-selected:text-accent-foreground",
|
53
|
+
day_hidden: "invisible",
|
54
|
+
...classNames,
|
55
|
+
}}
|
56
|
+
components={{
|
57
|
+
IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
|
58
|
+
IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
|
59
|
+
}}
|
60
|
+
{...props}
|
61
|
+
/>
|
62
|
+
)
|
63
|
+
}
|
64
|
+
Calendar.displayName = "Calendar"
|
65
|
+
|
66
|
+
export { Calendar }
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import * as React from "react"
|
2
|
+
|
3
|
+
import { cn } from "@/lib/utils"
|
4
|
+
|
5
|
+
const Card = React.forwardRef<
|
6
|
+
HTMLDivElement,
|
7
|
+
React.HTMLAttributes<HTMLDivElement>
|
8
|
+
>(({ className, ...props }, ref) => (
|
9
|
+
<div
|
10
|
+
ref={ref}
|
11
|
+
className={cn(
|
12
|
+
"rounded-lg border bg-card text-card-foreground shadow-sm",
|
13
|
+
className
|
14
|
+
)}
|
15
|
+
{...props}
|
16
|
+
/>
|
17
|
+
))
|
18
|
+
Card.displayName = "Card"
|
19
|
+
|
20
|
+
const CardHeader = React.forwardRef<
|
21
|
+
HTMLDivElement,
|
22
|
+
React.HTMLAttributes<HTMLDivElement>
|
23
|
+
>(({ className, ...props }, ref) => (
|
24
|
+
<div
|
25
|
+
ref={ref}
|
26
|
+
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
27
|
+
{...props}
|
28
|
+
/>
|
29
|
+
))
|
30
|
+
CardHeader.displayName = "CardHeader"
|
31
|
+
|
32
|
+
const CardTitle = React.forwardRef<
|
33
|
+
HTMLParagraphElement,
|
34
|
+
React.HTMLAttributes<HTMLHeadingElement>
|
35
|
+
>(({ className, ...props }, ref) => (
|
36
|
+
<h3
|
37
|
+
ref={ref}
|
38
|
+
className={cn(
|
39
|
+
"text-2xl font-semibold leading-none tracking-tight",
|
40
|
+
className
|
41
|
+
)}
|
42
|
+
{...props}
|
43
|
+
/>
|
44
|
+
))
|
45
|
+
CardTitle.displayName = "CardTitle"
|
46
|
+
|
47
|
+
const CardDescription = React.forwardRef<
|
48
|
+
HTMLParagraphElement,
|
49
|
+
React.HTMLAttributes<HTMLParagraphElement>
|
50
|
+
>(({ className, ...props }, ref) => (
|
51
|
+
<p
|
52
|
+
ref={ref}
|
53
|
+
className={cn("text-sm text-muted-foreground", className)}
|
54
|
+
{...props}
|
55
|
+
/>
|
56
|
+
))
|
57
|
+
CardDescription.displayName = "CardDescription"
|
58
|
+
|
59
|
+
const CardContent = React.forwardRef<
|
60
|
+
HTMLDivElement,
|
61
|
+
React.HTMLAttributes<HTMLDivElement>
|
62
|
+
>(({ className, ...props }, ref) => (
|
63
|
+
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
64
|
+
))
|
65
|
+
CardContent.displayName = "CardContent"
|
66
|
+
|
67
|
+
const CardFooter = React.forwardRef<
|
68
|
+
HTMLDivElement,
|
69
|
+
React.HTMLAttributes<HTMLDivElement>
|
70
|
+
>(({ className, ...props }, ref) => (
|
71
|
+
<div
|
72
|
+
ref={ref}
|
73
|
+
className={cn("flex items-center p-6 pt-0", className)}
|
74
|
+
{...props}
|
75
|
+
/>
|
76
|
+
))
|
77
|
+
CardFooter.displayName = "CardFooter"
|
78
|
+
|
79
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
@@ -0,0 +1,262 @@
|
|
1
|
+
"use client"
|
2
|
+
|
3
|
+
import * as React from "react"
|
4
|
+
import useEmblaCarousel, {
|
5
|
+
type UseEmblaCarouselType,
|
6
|
+
} from "embla-carousel-react"
|
7
|
+
import { ArrowLeft, ArrowRight } from "lucide-react"
|
8
|
+
|
9
|
+
import { cn } from "@/lib/utils"
|
10
|
+
import { Button } from "@/components/ui/button"
|
11
|
+
|
12
|
+
type CarouselApi = UseEmblaCarouselType[1]
|
13
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
14
|
+
type CarouselOptions = UseCarouselParameters[0]
|
15
|
+
type CarouselPlugin = UseCarouselParameters[1]
|
16
|
+
|
17
|
+
type CarouselProps = {
|
18
|
+
opts?: CarouselOptions
|
19
|
+
plugins?: CarouselPlugin
|
20
|
+
orientation?: "horizontal" | "vertical"
|
21
|
+
setApi?: (api: CarouselApi) => void
|
22
|
+
}
|
23
|
+
|
24
|
+
type CarouselContextProps = {
|
25
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
26
|
+
api: ReturnType<typeof useEmblaCarousel>[1]
|
27
|
+
scrollPrev: () => void
|
28
|
+
scrollNext: () => void
|
29
|
+
canScrollPrev: boolean
|
30
|
+
canScrollNext: boolean
|
31
|
+
} & CarouselProps
|
32
|
+
|
33
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
34
|
+
|
35
|
+
function useCarousel() {
|
36
|
+
const context = React.useContext(CarouselContext)
|
37
|
+
|
38
|
+
if (!context) {
|
39
|
+
throw new Error("useCarousel must be used within a <Carousel />")
|
40
|
+
}
|
41
|
+
|
42
|
+
return context
|
43
|
+
}
|
44
|
+
|
45
|
+
const Carousel = React.forwardRef<
|
46
|
+
HTMLDivElement,
|
47
|
+
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
48
|
+
>(
|
49
|
+
(
|
50
|
+
{
|
51
|
+
orientation = "horizontal",
|
52
|
+
opts,
|
53
|
+
setApi,
|
54
|
+
plugins,
|
55
|
+
className,
|
56
|
+
children,
|
57
|
+
...props
|
58
|
+
},
|
59
|
+
ref
|
60
|
+
) => {
|
61
|
+
const [carouselRef, api] = useEmblaCarousel(
|
62
|
+
{
|
63
|
+
...opts,
|
64
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
65
|
+
},
|
66
|
+
plugins
|
67
|
+
)
|
68
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
69
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
70
|
+
|
71
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
72
|
+
if (!api) {
|
73
|
+
return
|
74
|
+
}
|
75
|
+
|
76
|
+
setCanScrollPrev(api.canScrollPrev())
|
77
|
+
setCanScrollNext(api.canScrollNext())
|
78
|
+
}, [])
|
79
|
+
|
80
|
+
const scrollPrev = React.useCallback(() => {
|
81
|
+
api?.scrollPrev()
|
82
|
+
}, [api])
|
83
|
+
|
84
|
+
const scrollNext = React.useCallback(() => {
|
85
|
+
api?.scrollNext()
|
86
|
+
}, [api])
|
87
|
+
|
88
|
+
const handleKeyDown = React.useCallback(
|
89
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
90
|
+
if (event.key === "ArrowLeft") {
|
91
|
+
event.preventDefault()
|
92
|
+
scrollPrev()
|
93
|
+
} else if (event.key === "ArrowRight") {
|
94
|
+
event.preventDefault()
|
95
|
+
scrollNext()
|
96
|
+
}
|
97
|
+
},
|
98
|
+
[scrollPrev, scrollNext]
|
99
|
+
)
|
100
|
+
|
101
|
+
React.useEffect(() => {
|
102
|
+
if (!api || !setApi) {
|
103
|
+
return
|
104
|
+
}
|
105
|
+
|
106
|
+
setApi(api)
|
107
|
+
}, [api, setApi])
|
108
|
+
|
109
|
+
React.useEffect(() => {
|
110
|
+
if (!api) {
|
111
|
+
return
|
112
|
+
}
|
113
|
+
|
114
|
+
onSelect(api)
|
115
|
+
api.on("reInit", onSelect)
|
116
|
+
api.on("select", onSelect)
|
117
|
+
|
118
|
+
return () => {
|
119
|
+
api?.off("select", onSelect)
|
120
|
+
}
|
121
|
+
}, [api, onSelect])
|
122
|
+
|
123
|
+
return (
|
124
|
+
<CarouselContext.Provider
|
125
|
+
value={{
|
126
|
+
carouselRef,
|
127
|
+
api: api,
|
128
|
+
opts,
|
129
|
+
orientation:
|
130
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
131
|
+
scrollPrev,
|
132
|
+
scrollNext,
|
133
|
+
canScrollPrev,
|
134
|
+
canScrollNext,
|
135
|
+
}}
|
136
|
+
>
|
137
|
+
<div
|
138
|
+
ref={ref}
|
139
|
+
onKeyDownCapture={handleKeyDown}
|
140
|
+
className={cn("relative", className)}
|
141
|
+
role="region"
|
142
|
+
aria-roledescription="carousel"
|
143
|
+
{...props}
|
144
|
+
>
|
145
|
+
{children}
|
146
|
+
</div>
|
147
|
+
</CarouselContext.Provider>
|
148
|
+
)
|
149
|
+
}
|
150
|
+
)
|
151
|
+
Carousel.displayName = "Carousel"
|
152
|
+
|
153
|
+
const CarouselContent = React.forwardRef<
|
154
|
+
HTMLDivElement,
|
155
|
+
React.HTMLAttributes<HTMLDivElement>
|
156
|
+
>(({ className, ...props }, ref) => {
|
157
|
+
const { carouselRef, orientation } = useCarousel()
|
158
|
+
|
159
|
+
return (
|
160
|
+
<div ref={carouselRef} className="overflow-hidden">
|
161
|
+
<div
|
162
|
+
ref={ref}
|
163
|
+
className={cn(
|
164
|
+
"flex",
|
165
|
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
166
|
+
className
|
167
|
+
)}
|
168
|
+
{...props}
|
169
|
+
/>
|
170
|
+
</div>
|
171
|
+
)
|
172
|
+
})
|
173
|
+
CarouselContent.displayName = "CarouselContent"
|
174
|
+
|
175
|
+
const CarouselItem = React.forwardRef<
|
176
|
+
HTMLDivElement,
|
177
|
+
React.HTMLAttributes<HTMLDivElement>
|
178
|
+
>(({ className, ...props }, ref) => {
|
179
|
+
const { orientation } = useCarousel()
|
180
|
+
|
181
|
+
return (
|
182
|
+
<div
|
183
|
+
ref={ref}
|
184
|
+
role="group"
|
185
|
+
aria-roledescription="slide"
|
186
|
+
className={cn(
|
187
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
188
|
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
189
|
+
className
|
190
|
+
)}
|
191
|
+
{...props}
|
192
|
+
/>
|
193
|
+
)
|
194
|
+
})
|
195
|
+
CarouselItem.displayName = "CarouselItem"
|
196
|
+
|
197
|
+
const CarouselPrevious = React.forwardRef<
|
198
|
+
HTMLButtonElement,
|
199
|
+
React.ComponentProps<typeof Button>
|
200
|
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
201
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
202
|
+
|
203
|
+
return (
|
204
|
+
<Button
|
205
|
+
ref={ref}
|
206
|
+
variant={variant}
|
207
|
+
size={size}
|
208
|
+
className={cn(
|
209
|
+
"absolute h-8 w-8 rounded-full",
|
210
|
+
orientation === "horizontal"
|
211
|
+
? "-left-12 top-1/2 -translate-y-1/2"
|
212
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
213
|
+
className
|
214
|
+
)}
|
215
|
+
disabled={!canScrollPrev}
|
216
|
+
onClick={scrollPrev}
|
217
|
+
{...props}
|
218
|
+
>
|
219
|
+
<ArrowLeft className="h-4 w-4" />
|
220
|
+
<span className="sr-only">Previous slide</span>
|
221
|
+
</Button>
|
222
|
+
)
|
223
|
+
})
|
224
|
+
CarouselPrevious.displayName = "CarouselPrevious"
|
225
|
+
|
226
|
+
const CarouselNext = React.forwardRef<
|
227
|
+
HTMLButtonElement,
|
228
|
+
React.ComponentProps<typeof Button>
|
229
|
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
230
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
231
|
+
|
232
|
+
return (
|
233
|
+
<Button
|
234
|
+
ref={ref}
|
235
|
+
variant={variant}
|
236
|
+
size={size}
|
237
|
+
className={cn(
|
238
|
+
"absolute h-8 w-8 rounded-full",
|
239
|
+
orientation === "horizontal"
|
240
|
+
? "-right-12 top-1/2 -translate-y-1/2"
|
241
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
242
|
+
className
|
243
|
+
)}
|
244
|
+
disabled={!canScrollNext}
|
245
|
+
onClick={scrollNext}
|
246
|
+
{...props}
|
247
|
+
>
|
248
|
+
<ArrowRight className="h-4 w-4" />
|
249
|
+
<span className="sr-only">Next slide</span>
|
250
|
+
</Button>
|
251
|
+
)
|
252
|
+
})
|
253
|
+
CarouselNext.displayName = "CarouselNext"
|
254
|
+
|
255
|
+
export {
|
256
|
+
type CarouselApi,
|
257
|
+
Carousel,
|
258
|
+
CarouselContent,
|
259
|
+
CarouselItem,
|
260
|
+
CarouselPrevious,
|
261
|
+
CarouselNext,
|
262
|
+
}
|