Carousel() — ui Function Reference
Architecture documentation for the Carousel() function in carousel.tsx from the ui codebase.
Entity Profile
Dependency Diagram
graph TD ca66b16c_e0a6_d107_f49a_985f3afdccb8["Carousel()"] 736f7ee1_27b9_e9b5_e0f3_5ccbcfe0a0bf["carousel.tsx"] ca66b16c_e0a6_d107_f49a_985f3afdccb8 -->|defined in| 736f7ee1_27b9_e9b5_e0f3_5ccbcfe0a0bf style ca66b16c_e0a6_d107_f49a_985f3afdccb8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/v4/registry/bases/base/ui/carousel.tsx lines 45–133
function Carousel({
orientation = "horizontal",
opts,
setApi,
plugins,
className,
children,
...props
}: React.ComponentProps<"div"> & CarouselProps) {
const [carouselRef, api] = useEmblaCarousel(
{
...opts,
axis: orientation === "horizontal" ? "x" : "y",
},
plugins
)
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
const [canScrollNext, setCanScrollNext] = React.useState(false)
const onSelect = React.useCallback((api: CarouselApi) => {
if (!api) return
setCanScrollPrev(api.canScrollPrev())
setCanScrollNext(api.canScrollNext())
}, [])
const scrollPrev = React.useCallback(() => {
api?.scrollPrev()
}, [api])
const scrollNext = React.useCallback(() => {
api?.scrollNext()
}, [api])
const handleKeyDown = React.useCallback(
(event: React.KeyboardEvent<HTMLDivElement>) => {
if (event.key === "ArrowLeft") {
event.preventDefault()
scrollPrev()
} else if (event.key === "ArrowRight") {
event.preventDefault()
scrollNext()
}
},
[scrollPrev, scrollNext]
)
React.useEffect(() => {
if (!api || !setApi) return
setApi(api)
}, [api, setApi])
React.useEffect(() => {
if (!api) return
onSelect(api)
api.on("reInit", onSelect)
api.on("select", onSelect)
return () => {
api?.off("select", onSelect)
}
}, [api, onSelect])
return (
<CarouselContext.Provider
value={{
carouselRef,
api: api,
opts,
orientation:
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
scrollPrev,
scrollNext,
canScrollPrev,
canScrollNext,
}}
>
<div
onKeyDownCapture={handleKeyDown}
className={cn("relative", className)}
role="region"
aria-roledescription="carousel"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Carousel() do?
Carousel() is a function in the ui codebase, defined in apps/v4/registry/bases/base/ui/carousel.tsx.
Where is Carousel() defined?
Carousel() is defined in apps/v4/registry/bases/base/ui/carousel.tsx at line 45.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free