Carousel
A Carousel that is a 3D slide projector: Next turns the tray a slot, the next slide drops into the gate and your content lands on the wall. Built with ui-sdk (opens in a new tab).
Installation
pnpm dlx shadcn@latest add @alexandrejoly/carouselUsage
import { Carousel, CarouselContent, CarouselFocus, CarouselItem, CarouselNext, CarouselPlayToggle, CarouselPrevious, CarouselStage,} from "@/components/ui/literal-ui/carousel/carousel";import { CarouselAudio } from "@/components/ui/literal-ui/carousel/carousel-sound";<Carousel> <CarouselStage> <CarouselContent aria-label="Slides"> <CarouselItem> <img alt="Dunes at dusk" src="/dunes.jpg" /> </CarouselItem> <CarouselItem> <img alt="A forest in fog" src="/forest.jpg" /> </CarouselItem> </CarouselContent> <CarouselFocus /> <CarouselPlayToggle /> <CarouselPrevious /> <CarouselNext /> </CarouselStage> <CarouselAudio /></Carousel>Examples
Timer
defaultPlaying starts the timer, and interval sets how long each slide shows. The switch slides on, and Next or Previous turns it off, as on the projector. Pointing at the picture pauses it. It stays off for people who prefer reduced motion, until they slide the switch.
Controlled
Set page to show a slide from your own code. Here each button asks for its slide, and the tray turns to it. The keys still work by hand, and onPageChange reports every change with its reason.
API reference
Carousel
Holds the page, the timer and the focus. It loops: Next on the last slide turns the tray on round to the first.
Takes every prop of div.
| Prop | Type | Default |
|---|---|---|
defaultPageThe slide it starts on, from 1. Default: | number | 1 |
pageThe current slide, from 1, controlled. | number | None |
onPageChangeRuns when the slide wants to change. | (page: number, details: ChangeDetails) => void | None |
onPageChangeCompleteRuns once the carousel has settled on the new slide. | (page: number) => void | None |
defaultPlayingStarts with the timer on. It stays off for people who prefer reduced motion. Default: | boolean | false |
playingWhether the timer runs, controlled. | boolean | None |
onPlayingChangeRuns when the timer starts or stops, by the switch, by a key or by keyboard focus moving into the picture. | (playing: boolean, details: ChangeDetails) => void | None |
intervalHow long each slide shows while the timer runs, in ms. Default: | number | 5000 |
defaultFocusWhere the focus knob starts, from 0 to 100. The picture is sharp at 50 and blurs toward either end. Default: | number | 50 |
focusThe focus, controlled. | number | None |
onFocusChangeRuns when the focus knob turns. | (focus: number) => void | None |
CarouselStage
The projector in 3D, with the controls laid over its parts and the picture on the wall in front of it. It shows a still picture of the projector until the scene loads, and keeps it without WebGL 2: the slides still change.
Takes every prop of div.
CSS variables
Custom properties the stage reads from your CSS, set on it or on any element around it. The last one it sets itself, for your page to read.
| Variable | Type | Default |
|---|---|---|
--literal-lampThe lamp's bare light, shown on the wall between two slides. Default: | color | oklch(0.985 0.04 92 / 0.62) |
--literal-wallThe colour behind the picture. The picture's darkest parts rise to it, as projected light does on a wall. | color | None |
--literal-lightingSet to | dim | None |
--literal-filmSet by the stage: 1 while a slide shows, 0 while the lamp shines bare. Read it to light the page between two slides. | number | None |
CarouselContent
The picture on the wall: the slides, one to a view. Name it with aria-label. The arrow keys change slide once it has focus. It sets the layout itself, so it leaves out align, drag, dragFree, loop, orientation, skipSnaps and slidesPerPage.
Takes every prop of UI SDK Carousel (opens in a new tab).
CarouselItem
One slide. Each one also stands in the tray, from the slot over the gate on, up to 80 of them.
Takes every prop of UI SDK CarouselItem (opens in a new tab).
CarouselNext
The key on the right. The slide lifts, the tray turns a slot on and the next slide drops into the gate.
Takes every prop of UI SDK CarouselNext (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
aria-labelNames the key. Default: | string | "Next slide" |
CarouselPrevious
The key on the left. The tray turns a slot back.
Takes every prop of UI SDK CarouselPrevious (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
aria-labelNames the key. Default: | string | "Previous slide" |
CarouselPlayToggle
The timer's slide switch: on, the slides change by themselves.
Takes every prop of UI SDK CarouselPlayToggle (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
startLabelNames the switch while the timer is off. Default: | string | "Start the timer" |
stopLabelNames the switch while the timer runs. Default: | string | "Stop the timer" |
CarouselFocus
The focus knob. Drag up or down, or use the arrow keys: the lens moves in or out and the picture blurs. Its value and range are the carousel's focus, so it leaves out value, defaultValue, min, max and orientation.
Takes every prop of UI SDK Slider (opens in a new tab).
| Prop | Type | Default |
|---|---|---|
aria-labelNames the knob. Default: | string | "Focus" |
CarouselAudio
Plays the projector's recorded sounds, its fan included. It renders nothing, and loads nothing until the page is pressed. Import it from carousel-sound.
| Prop | Type | Default |
|---|---|---|
mutedSilences this projector alone. Default: | boolean | false |
CarouselAudioProvider
Mutes every CarouselAudio inside it, for a sound preference that covers the whole app or one part of it. It renders nothing of its own.
| Prop | Type |
|---|---|
mutedSilences the projectors below. Turned off during a press, their sounds unlock at once. | boolean |
useCarouselEvents
Follows what the projector does as it happens, as CarouselAudio does: the keys, the shutter, the slide lifting and dropping, the tray, the timer and the focus knob.
| Returns | Type |
|---|---|
subscribeCalls | (listener: (event: CarouselEvent) => void) => () => void |





