@openconsole/shadcn 0.2.5 → 0.2.7
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/components/index.ts +1 -2
- package/components/ui/accordion.tsx +66 -66
- package/components/ui/alert-dialog.tsx +196 -196
- package/components/ui/alert.tsx +66 -66
- package/components/ui/aspect-ratio.tsx +11 -11
- package/components/ui/avatar.tsx +53 -53
- package/components/ui/badge.tsx +46 -46
- package/components/ui/breadcrumb.tsx +109 -109
- package/components/ui/button-group.tsx +83 -83
- package/components/ui/button.tsx +60 -60
- package/components/ui/calendar.tsx +219 -219
- package/components/ui/card.tsx +92 -92
- package/components/ui/carousel.tsx +241 -241
- package/components/ui/chart.tsx +374 -374
- package/components/ui/checkbox.tsx +32 -32
- package/components/ui/collapsible.tsx +33 -33
- package/components/ui/command.tsx +184 -184
- package/components/ui/context-menu.tsx +252 -252
- package/components/ui/dialog.tsx +143 -143
- package/components/ui/direction.tsx +22 -22
- package/components/ui/drawer.tsx +135 -135
- package/components/ui/dropdown-menu.tsx +257 -257
- package/components/ui/empty.tsx +104 -104
- package/components/ui/field.tsx +248 -248
- package/components/ui/form.tsx +167 -167
- package/components/ui/hover-card.tsx +44 -44
- package/components/ui/index.ts +59 -59
- package/components/ui/input-group.tsx +170 -170
- package/components/ui/input-otp.tsx +77 -77
- package/components/ui/input.tsx +21 -21
- package/components/ui/item.tsx +193 -193
- package/components/ui/kbd.tsx +28 -28
- package/components/ui/label.tsx +24 -24
- package/components/ui/menubar.tsx +276 -276
- package/components/ui/native-select.tsx +62 -62
- package/components/ui/navigation-menu.tsx +168 -168
- package/components/ui/pagination.tsx +127 -127
- package/components/ui/popover.tsx +89 -89
- package/components/ui/progress.tsx +31 -31
- package/components/ui/radio-group.tsx +45 -45
- package/components/ui/resizable.tsx +53 -53
- package/components/ui/scroll-area.tsx +58 -58
- package/components/ui/select.tsx +187 -187
- package/components/ui/separator.tsx +28 -28
- package/components/ui/sheet.tsx +139 -139
- package/components/ui/sidebar.tsx +724 -724
- package/components/ui/skeleton.tsx +13 -13
- package/components/ui/slider.tsx +63 -63
- package/components/ui/sonner.tsx +40 -40
- package/components/ui/spinner.tsx +16 -16
- package/components/ui/switch.tsx +35 -35
- package/components/ui/table.tsx +116 -116
- package/components/ui/tabs.tsx +66 -66
- package/components/ui/textarea.tsx +18 -18
- package/components/ui/toggle-group.tsx +83 -83
- package/components/ui/toggle.tsx +47 -47
- package/components/ui/tooltip.tsx +61 -61
- package/hooks/index.ts +1 -1
- package/hooks/use-mobile.ts +19 -19
- package/index.ts +3 -3
- package/lib/index.ts +1 -1
- package/lib/utils.ts +6 -6
- package/package.json +1 -1
- package/styles.css +124 -124
- package/components/ai-elements/agent.tsx +0 -141
- package/components/ai-elements/artifact.tsx +0 -148
- package/components/ai-elements/attachments.tsx +0 -426
- package/components/ai-elements/audio-player.tsx +0 -231
- package/components/ai-elements/canvas.tsx +0 -26
- package/components/ai-elements/chain-of-thought.tsx +0 -222
- package/components/ai-elements/checkpoint.tsx +0 -71
- package/components/ai-elements/code-block.tsx +0 -562
- package/components/ai-elements/commit.tsx +0 -458
- package/components/ai-elements/confirmation.tsx +0 -174
- package/components/ai-elements/connection.tsx +0 -28
- package/components/ai-elements/context.tsx +0 -409
- package/components/ai-elements/controls.tsx +0 -18
- package/components/ai-elements/conversation.tsx +0 -168
- package/components/ai-elements/edge.tsx +0 -143
- package/components/ai-elements/environment-variables.tsx +0 -324
- package/components/ai-elements/file-tree.tsx +0 -304
- package/components/ai-elements/image.tsx +0 -24
- package/components/ai-elements/index.ts +0 -51
- package/components/ai-elements/inline-citation.tsx +0 -296
- package/components/ai-elements/jsx-preview.tsx +0 -310
- package/components/ai-elements/message.tsx +0 -360
- package/components/ai-elements/mic-selector.tsx +0 -375
- package/components/ai-elements/model-selector.tsx +0 -213
- package/components/ai-elements/node.tsx +0 -71
- package/components/ai-elements/open-in-chat.tsx +0 -370
- package/components/ai-elements/package-info.tsx +0 -239
- package/components/ai-elements/panel.tsx +0 -15
- package/components/ai-elements/persona.tsx +0 -306
- package/components/ai-elements/plan.tsx +0 -147
- package/components/ai-elements/prompt-input.tsx +0 -1463
- package/components/ai-elements/queue.tsx +0 -274
- package/components/ai-elements/reasoning.tsx +0 -228
- package/components/ai-elements/sandbox.tsx +0 -132
- package/components/ai-elements/schema-display.tsx +0 -471
- package/components/ai-elements/shimmer.tsx +0 -77
- package/components/ai-elements/snippet.tsx +0 -145
- package/components/ai-elements/sources.tsx +0 -77
- package/components/ai-elements/speech-input.tsx +0 -323
- package/components/ai-elements/stack-trace.tsx +0 -528
- package/components/ai-elements/suggestion.tsx +0 -57
- package/components/ai-elements/task.tsx +0 -87
- package/components/ai-elements/terminal.tsx +0 -273
- package/components/ai-elements/test-results.tsx +0 -496
- package/components/ai-elements/tool.tsx +0 -173
- package/components/ai-elements/toolbar.tsx +0 -16
- package/components/ai-elements/transcription.tsx +0 -125
- package/components/ai-elements/voice-selector.tsx +0 -524
- package/components/ai-elements/web-preview.tsx +0 -281
package/components/ui/card.tsx
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
|
|
3
|
-
import { cn } from "../../lib/utils"
|
|
4
|
-
|
|
5
|
-
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
-
return (
|
|
7
|
-
<div
|
|
8
|
-
data-slot="card"
|
|
9
|
-
className={cn(
|
|
10
|
-
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
|
|
11
|
-
className
|
|
12
|
-
)}
|
|
13
|
-
{...props}
|
|
14
|
-
/>
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
-
return (
|
|
20
|
-
<div
|
|
21
|
-
data-slot="card-header"
|
|
22
|
-
className={cn(
|
|
23
|
-
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
-
className
|
|
25
|
-
)}
|
|
26
|
-
{...props}
|
|
27
|
-
/>
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
-
return (
|
|
33
|
-
<div
|
|
34
|
-
data-slot="card-title"
|
|
35
|
-
className={cn("leading-none font-semibold", className)}
|
|
36
|
-
{...props}
|
|
37
|
-
/>
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
-
return (
|
|
43
|
-
<div
|
|
44
|
-
data-slot="card-description"
|
|
45
|
-
className={cn("text-sm text-muted-foreground", className)}
|
|
46
|
-
{...props}
|
|
47
|
-
/>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
-
return (
|
|
53
|
-
<div
|
|
54
|
-
data-slot="card-action"
|
|
55
|
-
className={cn(
|
|
56
|
-
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
57
|
-
className
|
|
58
|
-
)}
|
|
59
|
-
{...props}
|
|
60
|
-
/>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
65
|
-
return (
|
|
66
|
-
<div
|
|
67
|
-
data-slot="card-content"
|
|
68
|
-
className={cn("px-6", className)}
|
|
69
|
-
{...props}
|
|
70
|
-
/>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
75
|
-
return (
|
|
76
|
-
<div
|
|
77
|
-
data-slot="card-footer"
|
|
78
|
-
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
79
|
-
{...props}
|
|
80
|
-
/>
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export {
|
|
85
|
-
Card,
|
|
86
|
-
CardHeader,
|
|
87
|
-
CardFooter,
|
|
88
|
-
CardTitle,
|
|
89
|
-
CardAction,
|
|
90
|
-
CardDescription,
|
|
91
|
-
CardContent,
|
|
92
|
-
}
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils"
|
|
4
|
+
|
|
5
|
+
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="card"
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
data-slot="card-header"
|
|
22
|
+
className={cn(
|
|
23
|
+
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
data-slot="card-title"
|
|
35
|
+
className={cn("leading-none font-semibold", className)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
data-slot="card-description"
|
|
45
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-slot="card-action"
|
|
55
|
+
className={cn(
|
|
56
|
+
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
data-slot="card-content"
|
|
68
|
+
className={cn("px-6", className)}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
75
|
+
return (
|
|
76
|
+
<div
|
|
77
|
+
data-slot="card-footer"
|
|
78
|
+
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
Card,
|
|
86
|
+
CardHeader,
|
|
87
|
+
CardFooter,
|
|
88
|
+
CardTitle,
|
|
89
|
+
CardAction,
|
|
90
|
+
CardDescription,
|
|
91
|
+
CardContent,
|
|
92
|
+
}
|
|
@@ -1,241 +1,241 @@
|
|
|
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 "./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
|
-
function Carousel({
|
|
46
|
-
orientation = "horizontal",
|
|
47
|
-
opts,
|
|
48
|
-
setApi,
|
|
49
|
-
plugins,
|
|
50
|
-
className,
|
|
51
|
-
children,
|
|
52
|
-
...props
|
|
53
|
-
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
54
|
-
const [carouselRef, api] = useEmblaCarousel(
|
|
55
|
-
{
|
|
56
|
-
...opts,
|
|
57
|
-
axis: orientation === "horizontal" ? "x" : "y",
|
|
58
|
-
},
|
|
59
|
-
plugins
|
|
60
|
-
)
|
|
61
|
-
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
|
62
|
-
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
|
63
|
-
|
|
64
|
-
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
65
|
-
if (!api) return
|
|
66
|
-
setCanScrollPrev(api.canScrollPrev())
|
|
67
|
-
setCanScrollNext(api.canScrollNext())
|
|
68
|
-
}, [])
|
|
69
|
-
|
|
70
|
-
const scrollPrev = React.useCallback(() => {
|
|
71
|
-
api?.scrollPrev()
|
|
72
|
-
}, [api])
|
|
73
|
-
|
|
74
|
-
const scrollNext = React.useCallback(() => {
|
|
75
|
-
api?.scrollNext()
|
|
76
|
-
}, [api])
|
|
77
|
-
|
|
78
|
-
const handleKeyDown = React.useCallback(
|
|
79
|
-
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
80
|
-
if (event.key === "ArrowLeft") {
|
|
81
|
-
event.preventDefault()
|
|
82
|
-
scrollPrev()
|
|
83
|
-
} else if (event.key === "ArrowRight") {
|
|
84
|
-
event.preventDefault()
|
|
85
|
-
scrollNext()
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
[scrollPrev, scrollNext]
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
React.useEffect(() => {
|
|
92
|
-
if (!api || !setApi) return
|
|
93
|
-
setApi(api)
|
|
94
|
-
}, [api, setApi])
|
|
95
|
-
|
|
96
|
-
React.useEffect(() => {
|
|
97
|
-
if (!api) return
|
|
98
|
-
onSelect(api)
|
|
99
|
-
api.on("reInit", onSelect)
|
|
100
|
-
api.on("select", onSelect)
|
|
101
|
-
|
|
102
|
-
return () => {
|
|
103
|
-
api?.off("select", onSelect)
|
|
104
|
-
}
|
|
105
|
-
}, [api, onSelect])
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<CarouselContext.Provider
|
|
109
|
-
value={{
|
|
110
|
-
carouselRef,
|
|
111
|
-
api: api,
|
|
112
|
-
opts,
|
|
113
|
-
orientation:
|
|
114
|
-
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
115
|
-
scrollPrev,
|
|
116
|
-
scrollNext,
|
|
117
|
-
canScrollPrev,
|
|
118
|
-
canScrollNext,
|
|
119
|
-
}}
|
|
120
|
-
>
|
|
121
|
-
<div
|
|
122
|
-
onKeyDownCapture={handleKeyDown}
|
|
123
|
-
className={cn("relative", className)}
|
|
124
|
-
role="region"
|
|
125
|
-
aria-roledescription="carousel"
|
|
126
|
-
data-slot="carousel"
|
|
127
|
-
{...props}
|
|
128
|
-
>
|
|
129
|
-
{children}
|
|
130
|
-
</div>
|
|
131
|
-
</CarouselContext.Provider>
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
136
|
-
const { carouselRef, orientation } = useCarousel()
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
<div
|
|
140
|
-
ref={carouselRef}
|
|
141
|
-
className="overflow-hidden"
|
|
142
|
-
data-slot="carousel-content"
|
|
143
|
-
>
|
|
144
|
-
<div
|
|
145
|
-
className={cn(
|
|
146
|
-
"flex",
|
|
147
|
-
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
148
|
-
className
|
|
149
|
-
)}
|
|
150
|
-
{...props}
|
|
151
|
-
/>
|
|
152
|
-
</div>
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
157
|
-
const { orientation } = useCarousel()
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<div
|
|
161
|
-
role="group"
|
|
162
|
-
aria-roledescription="slide"
|
|
163
|
-
data-slot="carousel-item"
|
|
164
|
-
className={cn(
|
|
165
|
-
"min-w-0 shrink-0 grow-0 basis-full",
|
|
166
|
-
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
167
|
-
className
|
|
168
|
-
)}
|
|
169
|
-
{...props}
|
|
170
|
-
/>
|
|
171
|
-
)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function CarouselPrevious({
|
|
175
|
-
className,
|
|
176
|
-
variant = "outline",
|
|
177
|
-
size = "icon",
|
|
178
|
-
...props
|
|
179
|
-
}: React.ComponentProps<typeof Button>) {
|
|
180
|
-
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<Button
|
|
184
|
-
data-slot="carousel-previous"
|
|
185
|
-
variant={variant}
|
|
186
|
-
size={size}
|
|
187
|
-
className={cn(
|
|
188
|
-
"absolute size-8 rounded-full",
|
|
189
|
-
orientation === "horizontal"
|
|
190
|
-
? "top-1/2 -left-12 -translate-y-1/2"
|
|
191
|
-
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
192
|
-
className
|
|
193
|
-
)}
|
|
194
|
-
disabled={!canScrollPrev}
|
|
195
|
-
onClick={scrollPrev}
|
|
196
|
-
{...props}
|
|
197
|
-
>
|
|
198
|
-
<ArrowLeft />
|
|
199
|
-
<span className="sr-only">Previous slide</span>
|
|
200
|
-
</Button>
|
|
201
|
-
)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function CarouselNext({
|
|
205
|
-
className,
|
|
206
|
-
variant = "outline",
|
|
207
|
-
size = "icon",
|
|
208
|
-
...props
|
|
209
|
-
}: React.ComponentProps<typeof Button>) {
|
|
210
|
-
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
|
211
|
-
|
|
212
|
-
return (
|
|
213
|
-
<Button
|
|
214
|
-
data-slot="carousel-next"
|
|
215
|
-
variant={variant}
|
|
216
|
-
size={size}
|
|
217
|
-
className={cn(
|
|
218
|
-
"absolute size-8 rounded-full",
|
|
219
|
-
orientation === "horizontal"
|
|
220
|
-
? "top-1/2 -right-12 -translate-y-1/2"
|
|
221
|
-
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
222
|
-
className
|
|
223
|
-
)}
|
|
224
|
-
disabled={!canScrollNext}
|
|
225
|
-
onClick={scrollNext}
|
|
226
|
-
{...props}
|
|
227
|
-
>
|
|
228
|
-
<ArrowRight />
|
|
229
|
-
<span className="sr-only">Next slide</span>
|
|
230
|
-
</Button>
|
|
231
|
-
)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export {
|
|
235
|
-
type CarouselApi,
|
|
236
|
-
Carousel,
|
|
237
|
-
CarouselContent,
|
|
238
|
-
CarouselItem,
|
|
239
|
-
CarouselPrevious,
|
|
240
|
-
CarouselNext,
|
|
241
|
-
}
|
|
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 "./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
|
+
function Carousel({
|
|
46
|
+
orientation = "horizontal",
|
|
47
|
+
opts,
|
|
48
|
+
setApi,
|
|
49
|
+
plugins,
|
|
50
|
+
className,
|
|
51
|
+
children,
|
|
52
|
+
...props
|
|
53
|
+
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
54
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
55
|
+
{
|
|
56
|
+
...opts,
|
|
57
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
58
|
+
},
|
|
59
|
+
plugins
|
|
60
|
+
)
|
|
61
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
|
62
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
|
63
|
+
|
|
64
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
65
|
+
if (!api) return
|
|
66
|
+
setCanScrollPrev(api.canScrollPrev())
|
|
67
|
+
setCanScrollNext(api.canScrollNext())
|
|
68
|
+
}, [])
|
|
69
|
+
|
|
70
|
+
const scrollPrev = React.useCallback(() => {
|
|
71
|
+
api?.scrollPrev()
|
|
72
|
+
}, [api])
|
|
73
|
+
|
|
74
|
+
const scrollNext = React.useCallback(() => {
|
|
75
|
+
api?.scrollNext()
|
|
76
|
+
}, [api])
|
|
77
|
+
|
|
78
|
+
const handleKeyDown = React.useCallback(
|
|
79
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
80
|
+
if (event.key === "ArrowLeft") {
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
scrollPrev()
|
|
83
|
+
} else if (event.key === "ArrowRight") {
|
|
84
|
+
event.preventDefault()
|
|
85
|
+
scrollNext()
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
[scrollPrev, scrollNext]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (!api || !setApi) return
|
|
93
|
+
setApi(api)
|
|
94
|
+
}, [api, setApi])
|
|
95
|
+
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (!api) return
|
|
98
|
+
onSelect(api)
|
|
99
|
+
api.on("reInit", onSelect)
|
|
100
|
+
api.on("select", onSelect)
|
|
101
|
+
|
|
102
|
+
return () => {
|
|
103
|
+
api?.off("select", onSelect)
|
|
104
|
+
}
|
|
105
|
+
}, [api, onSelect])
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<CarouselContext.Provider
|
|
109
|
+
value={{
|
|
110
|
+
carouselRef,
|
|
111
|
+
api: api,
|
|
112
|
+
opts,
|
|
113
|
+
orientation:
|
|
114
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
115
|
+
scrollPrev,
|
|
116
|
+
scrollNext,
|
|
117
|
+
canScrollPrev,
|
|
118
|
+
canScrollNext,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<div
|
|
122
|
+
onKeyDownCapture={handleKeyDown}
|
|
123
|
+
className={cn("relative", className)}
|
|
124
|
+
role="region"
|
|
125
|
+
aria-roledescription="carousel"
|
|
126
|
+
data-slot="carousel"
|
|
127
|
+
{...props}
|
|
128
|
+
>
|
|
129
|
+
{children}
|
|
130
|
+
</div>
|
|
131
|
+
</CarouselContext.Provider>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
136
|
+
const { carouselRef, orientation } = useCarousel()
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
ref={carouselRef}
|
|
141
|
+
className="overflow-hidden"
|
|
142
|
+
data-slot="carousel-content"
|
|
143
|
+
>
|
|
144
|
+
<div
|
|
145
|
+
className={cn(
|
|
146
|
+
"flex",
|
|
147
|
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
148
|
+
className
|
|
149
|
+
)}
|
|
150
|
+
{...props}
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
157
|
+
const { orientation } = useCarousel()
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div
|
|
161
|
+
role="group"
|
|
162
|
+
aria-roledescription="slide"
|
|
163
|
+
data-slot="carousel-item"
|
|
164
|
+
className={cn(
|
|
165
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
166
|
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
167
|
+
className
|
|
168
|
+
)}
|
|
169
|
+
{...props}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function CarouselPrevious({
|
|
175
|
+
className,
|
|
176
|
+
variant = "outline",
|
|
177
|
+
size = "icon",
|
|
178
|
+
...props
|
|
179
|
+
}: React.ComponentProps<typeof Button>) {
|
|
180
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<Button
|
|
184
|
+
data-slot="carousel-previous"
|
|
185
|
+
variant={variant}
|
|
186
|
+
size={size}
|
|
187
|
+
className={cn(
|
|
188
|
+
"absolute size-8 rounded-full",
|
|
189
|
+
orientation === "horizontal"
|
|
190
|
+
? "top-1/2 -left-12 -translate-y-1/2"
|
|
191
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
192
|
+
className
|
|
193
|
+
)}
|
|
194
|
+
disabled={!canScrollPrev}
|
|
195
|
+
onClick={scrollPrev}
|
|
196
|
+
{...props}
|
|
197
|
+
>
|
|
198
|
+
<ArrowLeft />
|
|
199
|
+
<span className="sr-only">Previous slide</span>
|
|
200
|
+
</Button>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function CarouselNext({
|
|
205
|
+
className,
|
|
206
|
+
variant = "outline",
|
|
207
|
+
size = "icon",
|
|
208
|
+
...props
|
|
209
|
+
}: React.ComponentProps<typeof Button>) {
|
|
210
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<Button
|
|
214
|
+
data-slot="carousel-next"
|
|
215
|
+
variant={variant}
|
|
216
|
+
size={size}
|
|
217
|
+
className={cn(
|
|
218
|
+
"absolute size-8 rounded-full",
|
|
219
|
+
orientation === "horizontal"
|
|
220
|
+
? "top-1/2 -right-12 -translate-y-1/2"
|
|
221
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
222
|
+
className
|
|
223
|
+
)}
|
|
224
|
+
disabled={!canScrollNext}
|
|
225
|
+
onClick={scrollNext}
|
|
226
|
+
{...props}
|
|
227
|
+
>
|
|
228
|
+
<ArrowRight />
|
|
229
|
+
<span className="sr-only">Next slide</span>
|
|
230
|
+
</Button>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export {
|
|
235
|
+
type CarouselApi,
|
|
236
|
+
Carousel,
|
|
237
|
+
CarouselContent,
|
|
238
|
+
CarouselItem,
|
|
239
|
+
CarouselPrevious,
|
|
240
|
+
CarouselNext,
|
|
241
|
+
}
|