BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/cubby-ui/carousel

Carousel

cubby-ui/carousel
FreeComponent

A carousel component.

Live preview

live · rendered by the registry
Rendered by cubby-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://cubby-ui.dev/r/carousel.json

Source

registry/default/carousel/carousel.tsxcubby-ui.dev/r/carousel.json
1"use client";
2
3import * as React from "react";
4import useEmblaCarousel, {
5 type UseEmblaCarouselType,
6} from "embla-carousel-react";
7import { Button } from "@/registry/default/button/button";
8
9import { cn } from "@/lib/utils";
10
11import { HugeiconsIcon } from "@hugeicons/react";
12import { ArrowLeft01Icon, ArrowRight01Icon } from "@hugeicons/core-free-icons";
13type CarouselApi = UseEmblaCarouselType[1];
14type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
15type CarouselOptions = UseCarouselParameters[0];
16type CarouselPlugin = UseCarouselParameters[1];
17
18type CarouselProps = {
19 opts?: CarouselOptions;
20 plugins?: CarouselPlugin;
21 orientation?: "horizontal" | "vertical";
22 setApi?: (api: CarouselApi) => void;
23};
24
25type CarouselContextProps = {
26 carouselRef: ReturnType<typeof useEmblaCarousel>[0];
27 api: ReturnType<typeof useEmblaCarousel>[1];
28 scrollPrev: () => void;
29 scrollNext: () => void;
30 canScrollPrev: boolean;
31 canScrollNext: boolean;
32} & CarouselProps;
33
34const CarouselContext = React.createContext<CarouselContextProps | null>(null);
35
36function useCarousel() {
37 const context = React.useContext(CarouselContext);
38
39 if (!context) {
40 throw new Error("useCarousel must be used within a <Carousel />");
41 }
42
43 return context;
44}
45
46function Carousel({
47 orientation = "horizontal",
48 opts,
49 setApi,
50 plugins,
51 className,
52 children,
53 ...props
54}: React.ComponentProps<"div"> & CarouselProps) {
55 const [carouselRef, api] = useEmblaCarousel(
56 {
57 ...opts,
58 axis: orientation === "horizontal" ? "x" : "y",
59 },
60 plugins,
61 );
62 const [canScrollPrev, setCanScrollPrev] = React.useState(false);
63 const [canScrollNext, setCanScrollNext] = React.useState(false);
64
65 const onSelect = React.useCallback((api: CarouselApi) => {
66 if (!api) return;
67 setCanScrollPrev(api.canScrollPrev());
68 setCanScrollNext(api.canScrollNext());
69 }, []);
70
71 const scrollPrev = React.useCallback(() => {
72 api?.scrollPrev();
73 }, [api]);
74
75 const scrollNext = React.useCallback(() => {
76 api?.scrollNext();
77 }, [api]);
78
79 const handleKeyDown = React.useCallback(
80 (event: React.KeyboardEvent<HTMLDivElement>) => {
81 if (event.key === "ArrowLeft") {
82 event.preventDefault();
83 scrollPrev();
84 } else if (event.key === "ArrowRight") {
85 event.preventDefault();
86 scrollNext();
87 }
88 },
89 [scrollPrev, scrollNext],
90 );
91
92 React.useEffect(() => {
93 if (!api || !setApi) return;
94 setApi(api);
95 }, [api, setApi]);
96
97// … truncated

What it pulls in

npm packages

  • embla-carousel-react
  • @hugeicons/react
  • @hugeicons/core-free-icons

Other registry items

  • @cubby-ui/button

Files it writes

  • registry/default/carousel/carousel.tsx

Facts

Registry
cubby-ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-01
Last confirmed
today

Go to the source

Docs on cubby-ui cubby-ui.dev joncoronel/cubby-ui on GitHub Raw registry item This item as JSON

More from cubby-ui

All 79 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Accordionaccordioncubby-uiComponentsFree2 deps
Alertalertcubby-uiComponentsFree1 dep
Alert-dialogalert-dialogcubby-uiComponentsFree2 deps
Aspect-ratioaspect-ratiocubby-uiComponentsFreeno deps
Autocompleteautocompletecubby-uiComponentsFree2 deps
Avataravatarcubby-uiComponentsFree1 dep
Badgebadgecubby-uiComponentsFree1 dep
Base Drawerbase-drawercubby-uiComponentsFree2 deps
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