BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/Pixelact UI/carousel

Pixelact Carousel

pixelact-ui/carousel
FreeComponent

A simple carousel component.

Live preview

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

Install it

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

Source

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

What it pulls in

Other registry items

  • button

Files it writes

  • components/ui/pixelact-ui/carousel.tsx
  • components/ui/pixelact-ui/styles/styles.css

Facts

Registry
Pixelact UI
Type
registry:component
Access
Free
Files written
2
Licence
MIT
First indexed
2026-08-03
Last confirmed
today

Go to the source

Docs on Pixelact UI pixelactui.com pixelact-ui/pixelact-ui on GitHub Raw registry item This item as JSON

More from Pixelact UI

All 28 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Pixelact AccordionaccordionPixelact UIComponentsFreeno deps · 2 files
Pixelact AlertalertPixelact UIComponentsFreeno deps · 2 files
Pixelact Alert Dialogalert-dialogPixelact UIComponentsFreeno deps · 2 files
Pixelact AvataravatarPixelact UIComponentsFreeno deps · 2 files
Pixelact BadgebadgePixelact UIComponentsFreeno deps · 2 files
Pixelact BreadcrumbbreadcrumbPixelact UIComponentsFreeno deps · 2 files
Pixelact ButtonbuttonPixelact UIComponentsFreeno deps · 3 files
Pixelact CalendarcalendarPixelact UIComponentsFreeno deps · 2 files
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