import { Carousel } from "@senvenli/react/display";
// Flat placeholder photos drawn in the file, so the example needs no network.
const photo = (label: string, hue: number) =>
`data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900"><rect width="100%" height="100%" fill="hsl(${hue} 30% 62%)"/><text x="50%" y="50%" fill="hsl(${hue} 30% 20%)" font-family="system-ui" font-size="72" text-anchor="middle" dominant-baseline="middle">${label}</text></svg>`,
)}`;
const PHOTOS = [
{ src: photo("Front view", 210), alt: "Front view" },
{ src: photo("Side view", 150), alt: "Side view" },
{ src: photo("Detail", 30), alt: "Detail of the oak top" },
];
export default function Example() {
return (
<div className="max-w-xl">
<Carousel aria-label="Product photos" items={PHOTOS} />
</div>
);
}import { Carousel, CarouselSlide } from "@senvenli/react/display";Examples
With thumbnails
A strip under the frame picks an image directly; the dots then only indicate.import { Carousel } from "@senvenli/react/display";
// Flat placeholder photos drawn in the file, so the example needs no network.
const photo = (label: string, hue: number) =>
`data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900"><rect width="100%" height="100%" fill="hsl(${hue} 30% 62%)"/><text x="50%" y="50%" fill="hsl(${hue} 30% 20%)" font-family="system-ui" font-size="72" text-anchor="middle" dominant-baseline="middle">${label}</text></svg>`,
)}`;
const PHOTOS = [
{ src: photo("Front view", 210), alt: "Front view" },
{ src: photo("Side view", 150), alt: "Side view" },
{ src: photo("Detail", 30), alt: "Detail of the oak top" },
];
export default function Example() {
return (
<div className="max-w-xl">
<Carousel aria-label="Product photos" items={PHOTOS} showThumbnails aspectRatio="4/3" />
</div>
);
}Controlled
The page owns the shown image, here to caption it.import { Carousel, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { useState } from "react";
// Flat placeholder photos drawn in the file, so the example needs no network.
const photo = (label: string, hue: number) =>
`data:image/svg+xml,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900"><rect width="100%" height="100%" fill="hsl(${hue} 30% 62%)"/><text x="50%" y="50%" fill="hsl(${hue} 30% 20%)" font-family="system-ui" font-size="72" text-anchor="middle" dominant-baseline="middle">${label}</text></svg>`,
)}`;
const PHOTOS = [
{ src: photo("Front view", 210), alt: "Front view" },
{ src: photo("Side view", 150), alt: "Side view" },
{ src: photo("Detail", 30), alt: "Detail of the oak top" },
];
export default function Example() {
const [index, setIndex] = useState(1);
return (
<div className="max-w-xl">
<Stack space="space-100">
<Carousel aria-label="Product photos" items={PHOTOS} index={index} onIndexChange={setIndex} />
<Text tone="subtle">{PHOTOS[index]?.alt}</Text>
</Stack>
</div>
);
}Any content per slide
`CarouselSlide` children: cards with a heading and text instead of photos.import { Carousel, CarouselSlide, Heading, Text } from "@senvenli/react/display";
const QUOTES = [
{ id: "ada", quote: "We closed the month two days earlier than before.", name: "Ada Lovelace, Finance lead" },
{ id: "grace", quote: "Our support queue finally fits on one screen.", name: "Grace Hopper, Support" },
{ id: "alan", quote: "Setting it up took one afternoon.", name: "Alan Turing, Operations" },
];
export default function Example() {
return (
<div className="w-full max-w-lg">
<Carousel aria-label="What customers say" aspectRatio="16/9">
{QUOTES.map((item) => (
<CarouselSlide key={item.id} id={item.id}>
<div className="flex size-full flex-col items-center justify-center gap-ds-150 px-ds-600 text-center">
<Heading level={3} size="heading-medium">
“{item.quote}”
</Heading>
<Text tone="subtle">{item.name}</Text>
</div>
</CarouselSlide>
))}
</Carousel>
</div>
);
}Guidelines
When to use it
- A few photos of one item.
Use something else when
- Photos need to be seen full screen. Image viewer
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow left / right | Move to the previous or next image. |
Built in
- The position is announced as "Image N of M".
You provide
- Meaningful alt text for each image.
- With CarouselSlide children: real alt text on images inside slides, and a label per slide when thumbnails are shown.
API reference
Carousel
| Prop | Type | Default | Description |
|---|---|---|---|
items | CarouselItem[] | – | Images as data. Leave it out to compose |
children | React.ReactNode | – | With no |
aria-labelRequired | string | – | Names the carousel ("Product photos"). |
index | number | – | The shown image, controlled. The carousel calls |
defaultIndex | number | – | The first image shown when uncontrolled. |
onIndexChange | (index: number) => void | – | |
showThumbnails | boolean | – | A strip of thumbnails under the frame; the current one outlined. The dots then only indicate. With |
aspectRatio | "16/9" | "4/3" | – | |
isLandmark | boolean | – | A |
motion | ComponentMotion | – |
|
itemsCarouselItem[]Images as data. Leave it out to compose
CarouselSlides as children instead (any content: a card, a quote).childrenReact.ReactNodeWith no
items:CarouselSlides, one per page.aria-labelRequiredstringNames the carousel ("Product photos").
indexnumberThe shown image, controlled. The carousel calls
onIndexChangeand expects the new value back.defaultIndexnumberThe first image shown when uncontrolled.
onIndexChange(index: number) => voidshowThumbnailsbooleanA strip of thumbnails under the frame; the current one outlined. The dots then only indicate. With
CarouselSlides, shown only when every slide has athumbnail.aspectRatio"16/9" | "4/3"isLandmarkbooleanA
regionlandmark (default) for a gallery that is part of the page's outline;falseinside repeated cards, so a listing does not fill the landmark list.motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.
CarouselSlide
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | – | Stable key; the position by default. |
label | string | – | The slide's name for its thumbnail ("Front view"); the position by default. |
thumbnail | string | – | An image URL for the thumbnail strip. |
childrenRequired | React.ReactNode | – | What the page shows: an image, a card, a quote. It fills the frame. |
idstringStable key; the position by default.
labelstringThe slide's name for its thumbnail ("Front view"); the position by default.
thumbnailstringAn image URL for the thumbnail strip.
childrenRequiredReact.ReactNodeWhat the page shows: an image, a card, a quote. It fills the frame.