Carousel
Des diapositives dans une piste à scroll-snap, sans dépendance : Précédent et Suivant, points facultatifs, balayage et touches fléchées, boucle, plusieurs diapositives par vue et lecture automatique facultative mise en pause au survol et au focus, selon le modèle Carousel de WAI-ARIA.
Angular: disponible Vue: disponible React: disponible React Native: disponible
Utilisation
Slide 1 of 4
<div class="demo-stack" style="max-width: 24rem; width: 100%">
<sone-carousel aria-label="Release highlights" loop [(index)]="index">
<div soneCarouselContent>
@for (slide of slides; track slide.title) {
<div soneCarouselItem>
<div soneCard style="display: grid; place-content: center; gap: var(--space-1); aspect-ratio: 4 / 3; text-align: center">
<strong style="font-size: var(--font-size-2xl)">{{ slide.title }}</strong>
<span style="color: var(--text-secondary)">{{ slide.text }}</span>
</div>
</div>
}
</div>
<button soneCarouselPrevious></button>
<button soneCarouselNext></button>
<sone-carousel-dots />
</sone-carousel>
<p style="margin: 0; color: var(--text-secondary); text-align: center">Slide {{ index() + 1 }} of {{ slides.length }}</p>
</div>Importation
import {
SoneCarouselComponent,
SoneCarouselContentDirective,
SoneCarouselDotsComponent,
SoneCarouselItemDirective,
SoneCarouselNextComponent,
SoneCarouselPreviousComponent,
} from "@surface-one/angular/carousel";Référence de l’API
SoneCarouselComponentComposant
`sone-carousel` — a carousel (WAI-ARIA carousel pattern; shadcn/ui and spartan/ui Carousel) with no dependency: the slides (`soneCarouselItem`) sit in a CSS scroll-snap track (`soneCarouselContent`), so swiping, the trackpad and the wheel are the browser's own. `soneCarouselPrevious` / `soneCarouselNext` and `sone-carousel-dots` step it, ArrowLeft / ArrowRight (ArrowUp / ArrowDown when `vertical`) step it while focus is inside, and `[(index)]` is the current slide. `loop` wraps at the ends. It is a `region` with `aria-roledescription="carousel"` (name it with `aria-label`), each slide a `group` named "N of M". Nothing moves on its own unless `autoplay` (ms) is set: then it advances, holds while the pointer rests on it or focus is inside, starts stopped under reduced motion, and shows a rotation control to stop and restart it.
| Nom | Type | Par défaut |
|---|---|---|
indexbidirectionnelThe current slide, two-way: `[(index)]`. | number | 0 |
orientation | CarouselOrientation | "horizontal" |
loopWrap from the last slide to the first and back. | boolean | false |
autoplayms between automatic steps; 0 (the default) never moves on its own. | number | 0 |
roleDescription | — | $localize`:Role description of a carousel region:carousel` |
slideRoleDescription | — | $localize`:Role description of one slide of a carousel:slide` |
stopLabel | — | $localize`:Stops a carousel's automatic rotation:Stop automatic slide show` |
startLabel | — | $localize`:Starts a carousel's automatic rotation:Start automatic slide show` |
SoneCarouselContentDirectiveDirective
`[soneCarouselContent]` — the scroll-snap track of the slides. It is focusable (the arrow keys step the carousel from it) and a polite live region while nothing rotates.
SoneCarouselDotsComponentComposant
`sone-carousel-dots` — one button per slide; the current one is `aria-current`.
| Nom | Type | Par défaut |
|---|---|---|
labelThe group's name, when no static `aria-label` gives one. | — | $localize`:The group of a carousel's slide buttons:Choose slide` |
SoneCarouselItemDirectiveDirective
`[soneCarouselItem]` — one slide: a `group` with `aria-roledescription="slide"`, named "N of M".
| Nom | Type | Par défaut |
|---|---|---|
labelThe slide's name (default: a static `aria-label`, else its position, "2 of 5"). | string | null | null |
SoneCarouselNextComponentComposant
`button[soneCarouselNext]` — steps on one slide; disabled on the last unless `loop`.
| Nom | Type | Par défaut |
|---|---|---|
variant | ButtonVariant | "outline" |
size | ButtonSize | "icon-sm" |
labelThe button's name, when no static `aria-label` gives one. | — | $localize`:Shows the next carousel slide:Next slide` |
SoneCarouselPreviousComponentComposant
`button[soneCarouselPrevious]` — steps back one slide; disabled on the first unless `loop`.
| Nom | Type | Par défaut |
|---|---|---|
variant | ButtonVariant | "outline" |
size | ButtonSize | "icon-sm" |
labelThe button's name, when no static `aria-label` gives one. | — | $localize`:Shows the previous carousel slide:Previous slide` |