BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn/ui/carousel

carousel

yyc3-knowledge-base/carousel
UnverifiedComponent

shadcn/ui publishes no description for this item.

Install it

npx shadcn@latest add https://raw.githubusercontent.com/YYC-Cube/YYC3-Knowledge-Base/main/YYC3-D/ui/apps/v4/carousel.json

Source

registry/new-york-v4/ui/carousel.tsxraw.githubusercontent.com/YYC-Cube/YYC3-Knowledge-Base/main/YYC3-D/ui/apps/v4/carousel.json · first 6 KB
1"use client"
2
3import * as React from "react"
4import useEmblaCarousel, {
5 type UseEmblaCarouselType,
6} from "embla-carousel-react"
7import { ArrowLeft, ArrowRight } from "lucide-react"
8
9import { cn } from "@/lib/utils"
10import { Button } from "@/registry/new-york/ui/button"
11
12type CarouselApi = UseEmblaCarouselType[1]
13type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
14type CarouselOptions = UseCarouselParameters[0]
15type CarouselPlugin = UseCarouselParameters[1]
16
17type CarouselProps = {
18 opts?: CarouselOptions
19 plugins?: CarouselPlugin
20 orientation?: "horizontal" | "vertical"
21 setApi?: (api: CarouselApi) => void
22}
23
24type 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
33const CarouselContext = React.createContext<CarouselContextProps | null>(null)
34
35function 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
45const 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// … truncated

What it pulls in

npm packages

  • embla-carousel-react

Other registry items

  • button

Files it writes

  • registry/new-york-v4/ui/carousel.tsx

Facts

Registry
shadcn/ui
Type
registry:ui
Access
Unverified
Files written
1
Licence
the repository states none
First indexed
2026-08-01
Last confirmed
yesterday

Go to the source

ui.shadcn.com YYC-Cube/YYC3-Knowledge-Base on GitHub Raw registry item This item as JSON

More from shadcn/ui

All 411 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
accordionaccordionshadcn/uiComponentsUnverified1 dep
alertalertshadcn/uiComponentsUnverifiedno deps
alert-dialogalert-dialogshadcn/uiComponentsUnverified1 dep
aspect-ratioaspect-ratioshadcn/uiComponentsUnverified1 dep
avataravatarshadcn/uiComponentsUnverified1 dep
badgebadgeshadcn/uiComponentsUnverified1 dep
breadcrumbbreadcrumbshadcn/uiComponentsUnverified1 dep
buttonbuttonshadcn/uiComponentsUnverified1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex