BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/carouselcn/carousel

Carousel

carouselcn/carousel
FreeComponent

A lightweight carousel component with CSS transitions.

Live preview

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

Install it

npx shadcn@latest add https://carouselcn.marcellonovelli.com/r/carousel.json

Source

registry/components/ui/carousel.tsxcarouselcn.marcellonovelli.com/r/carousel.json · first 6 KB
1"use client";
2import { cn } from "@/lib/utils";
3import {
4 ChevronDown,
5 ChevronLeft,
6 ChevronRight,
7 ChevronUp,
8} from "lucide-react";
9import {
10 Children,
11 ReactNode,
12 createContext,
13 useCallback,
14 useContext,
15 useEffect,
16 useMemo,
17 useRef,
18 useState,
19} from "react";
20
21export type CarouselContextType = {
22 index: number;
23 setIndex: (newIndex: number | ((prev: number) => number)) => void;
24 itemsCount: number;
25 setItemsCount: (newItemsCount: number) => void;
26 disableDrag: boolean;
27 loop: boolean;
28 orientation: "horizontal" | "vertical";
29};
30
31const CarouselContext = createContext<CarouselContextType | undefined>(
32 undefined,
33);
34function useCarousel() {
35 const context = useContext(CarouselContext);
36 if (!context) {
37 throw new Error("useCarousel must be used within an CarouselProvider");
38 }
39 return context;
40}
41
42export type CarouselProviderProps = {
43 children: ReactNode;
44 initialIndex?: number;
45 onIndexChange?: (newIndex: number) => void;
46 disableDrag?: boolean;
47 loop?: boolean;
48 orientation?: "horizontal" | "vertical";
49};
50
51function CarouselProvider({
52 children,
53 initialIndex = 0,
54 onIndexChange,
55 disableDrag = false,
56 loop = false,
57 orientation = "horizontal",
58}: CarouselProviderProps) {
59 const [index, setIndex] = useState<number>(initialIndex);
60 const [itemsCount, setItemsCount] = useState<number>(0);
61
62 const handleSetIndex = useCallback(
63 (newIndex: number | ((prev: number) => number)) => {
64 if (typeof newIndex === "function") {
65 setIndex((prev) => {
66 const next = newIndex(prev);
67 onIndexChange?.(next);
68 return next;
69 });
70 } else {
71 setIndex(newIndex);
72 onIndexChange?.(newIndex);
73 }
74 },
75 [onIndexChange],
76 );
77
78 useEffect(() => {
79 setIndex(initialIndex);
80 }, [initialIndex]);
81
82 const contextValue = useMemo(
83 () => ({
84 index,
85 setIndex: handleSetIndex,
86 itemsCount,
87 setItemsCount,
88 disableDrag,
89 loop,
90 orientation,
91 }),
92 [index, handleSetIndex, itemsCount, disableDrag, loop, orientation],
93 );
94
95 return (
96 <CarouselContext.Provider value={contextValue}>
97 {children}
98 </CarouselContext.Provider>
99 );
100}
101
102export type CarouselProps = {
103 children: ReactNode;
104 className?: string;
105 initialIndex?: number;
106 index?: number;
107 onIndexChange?: (newIndex: number) => void;
108 disableDrag?: boolean;
109 loop?: boolean;
110 orientation?: "horizontal" | "vertical";
111};
112
113function Carousel({
114 children,
115// … truncated

What it pulls in

npm packages

  • lucide-react

Files it writes

  • registry/components/ui/carousel.tsx

Facts

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

Go to the source

Docs on carouselcn carouselcn.marcellonovelli.com mnove/carouselcn on GitHub Raw registry item This item as JSON

More from carouselcn

All 2 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Carousel Motioncarousel-motioncarouselcnComponentsFree2 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