Carousel
Carousel presents content one slide at a time, navigated with previous / next buttons, dots, thumbnails or the arrow keys.
Import
Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.
// npm install yugen-uiimport { Carousel, CarouselViewport, CarouselCard, CarouselNavContainer, CarouselThumbnails, CarouselThumbnail,} from "yugen-ui";Variants
Each tile is a standalone example: hover to copy, or press Code to see the source.
Peek & loop
slidesPerView={1.15} reveals 15% of the next slide, gap="medium" widens the spacing; loop wraps around at both ends.
Autoplay with progress
The active dot grows longer and fills up over autoplayInterval; hovering or focusing a slide, or hiding the tab, pauses it.
Thumbnails
CarouselThumbnails replaces the dots: a tablist of small images that scrolls to the active one. Give each image an aria-label.
Usage
- Give the Carousel an aria-label. Each slide is labeled “Slide x / n” automatically; thumbnails should have their own aria-label.
- Keep 3–6 slides of the same kind; use a fractional slidesPerView (1.15, 2.5) to hint that more content follows.
- When autoplay is on, always show the pause button (CarouselNavContainer showAutoplayToggle).
- Don't put important information only in a hidden slide.
- Don't turn autoplay on by default for content people need to read carefully.
- Don't use both dots and thumbnails in the same Carousel.
Props
| Prop · Type | Default | Description |
|---|---|---|
| loopboolean | Default: false | Wraps around at both ends. The old name circular is deprecated (removed in 1.0). |
| slidesPerViewnumber | Default: — | Number of slides visible at once; a fraction reveals the next slide (1.15, 2.5). Leave it empty for 100%. |
| gap"none" | "extra-small" | "small" | "medium" | "large" | "extra-large" | Default: "small" | Spacing between slides (spacing token). The short names "XS" … "XL" are deprecated (removed in 1.0). |
| autoplay / defaultAutoplay / onAutoplayChangeboolean / boolean / (value) => void | Default: — / false | Autoplay (controlled / uncontrolled). defaultAutoplay is ignored under prefers-reduced-motion. |
| autoplayIntervalnumber | Default: 4000 | Time per slide (ms); progress shows in the active dot / thumbnail. |
| activeIndex / defaultActiveIndex / onActiveIndexChangenumber / number / (index: number) => void | Default: — / 0 | Current slide, counted from 0 (controlled / uncontrolled); called when the current slide changes. |
| CarouselCard | Default: — | basis-full by default; basis-4/5 or basis-1/2 when slidesPerView isn't used. |
| CarouselNavContainer | Default: false | Shows the button that turns autoplay on / off. The old name autoplay is deprecated (removed in 1.0). |
| CarouselNavContainer | Default: "Previous slide" / "Next slide" | aria-label of the navigation buttons. The old name prevLabel is deprecated (removed in 1.0). |
| CarouselThumbnails / CarouselThumbnailHTMLAttributes / ButtonHTMLAttributes | Default: — | Thumbnail tablist; each CarouselThumbnail matches the slide at the same position. |
Messages
Text built into the component: labels, aria-labels, screen reader announcements.
English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.
messages.carousel
| Key · Type | Default (English) | messagesVi |
|---|---|---|
| slide(index: number, count: number) => string Tên từng slide / chấm / thumbnail và thông báo slide hiện tại; | Default (English)(index, count) => `Slide ${index} of ${count}` | messagesVi(index, count) => `Slide ${index} / ${count}` |
| roleDescriptionstring aria-roledescription của vùng carousel. | Default (English)"carousel" | messagesVi"carousel" |
| slideRoleDescriptionstring aria-roledescription của từng slide. | Default (English)"slide" | messagesVi"slide" |
| previousstring aria-label nút slide trước. | Default (English)"Previous slide" | messagesVi"Slide trước" |
| nextstring aria-label nút slide sau. | Default (English)"Next slide" | messagesVi"Slide tiếp theo" |
| autoplaystring aria-label nút bật / tắt tự chạy. | Default (English)"Autoplay" | messagesVi"Tự động chạy" |
| chooseSlidestring aria-label dãy chấm / thumbnail (tablist). | Default (English)"Choose slide" | messagesVi"Chọn slide" |