Carousel

基于 scroll-snap 轨道、无任何依赖的幻灯片:上一张与下一张按钮、可选圆点、滑动与方向键、循环、每屏多张,以及在悬停和聚焦时暂停的可选自动播放,遵循 WAI-ARIA Carousel 模式。

可用框架
  • Angular: 可用
  • Vue: 可用
  • React: 可用
  • React Native: 可用

用法

Slide 1 of 4

导入

ts
import {
  SoneCarouselComponent,
  SoneCarouselContentDirective,
  SoneCarouselDotsComponent,
  SoneCarouselItemDirective,
  SoneCarouselNextComponent,
  SoneCarouselPreviousComponent,
} from "@surface-one/angular/carousel";

API 参考

SoneCarouselComponent组件

`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.

选择器
sone-carousel
导出为
soneCarousel
输入
名称类型 默认值
index双向

The current slide, two-way: `[(index)]`.

number0
orientationCarouselOrientation"horizontal"
loop

Wrap from the last slide to the first and back.

booleanfalse
autoplay

ms between automatic steps; 0 (the default) never moves on its own.

number0
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`

SoneCarouselContentDirective指令

`[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.

选择器
[soneCarouselContent]

SoneCarouselDotsComponent组件

`sone-carousel-dots` — one button per slide; the current one is `aria-current`.

选择器
sone-carousel-dots
输入
名称类型 默认值
label

The group's name, when no static `aria-label` gives one.

—$localize`:The group of a carousel's slide buttons:Choose slide`

SoneCarouselItemDirective指令

`[soneCarouselItem]` — one slide: a `group` with `aria-roledescription="slide"`, named "N of M".

选择器
[soneCarouselItem]
输入
名称类型 默认值
label

The slide's name (default: a static `aria-label`, else its position, "2 of 5").

string | nullnull

SoneCarouselNextComponent组件

`button[soneCarouselNext]` — steps on one slide; disabled on the last unless `loop`.

选择器
button[soneCarouselNext]
输入
名称类型 默认值
variantButtonVariant"outline"
sizeButtonSize"icon-sm"
label

The button's name, when no static `aria-label` gives one.

—$localize`:Shows the next carousel slide:Next slide`

SoneCarouselPreviousComponent组件

`button[soneCarouselPrevious]` — steps back one slide; disabled on the first unless `loop`.

选择器
button[soneCarouselPrevious]
输入
名称类型 默认值
variantButtonVariant"outline"
sizeButtonSize"icon-sm"
label

The button's name, when no static `aria-label` gives one.

—$localize`:Shows the previous carousel slide:Previous slide`