外观
Carousel 轮播
在同一区域浏览一组连续内容,可以拖动切换,也可以使用前后按钮或方向键。
import { SCarousel } from '@icecreamqaq/shadcn/carousel'使用示例
常用 API
| 成员 | 类型 | 用法 |
|---|---|---|
SCarousel.orientation | "horizontal" | "vertical" | 默认为 horizontal。垂直模式使用上下方向键切换。 |
SCarousel.opts | Embla 选项 | 传入 loop、align 等轮播选项。 |
SCarousel.@init-api | (api: CarouselApi) => void | 挂载并初始化后获取 Embla 实例。 |
SCarouselContent.default | slot | 每个独立页面使用一个 SCarouselItem。 |
前后按钮默认定位在内容区两侧,示例的外部宽度为两个按钮预留了空间。
完整 API
Carousel11 个成员
属性
| 名称 | 类型 |
|---|---|
index | number |
defaultIndex | number |
opts | MaybeRef<Partial<OptionsType>> |
plugins | MaybeRef<CreatePluginType<LoosePluginType, {}>[]> |
orientation | "vertical" | "horizontal" |
class | ClassValue |
items | readonly CollectionItem<string | number>[] |
事件
| 名称 | 类型 |
|---|---|
update:index | ((index: number) => any) |
init-api | ((payload: EmblaCarouselType | undefined) => any) |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: { canScrollNext: boolean; canScrollPrev: boolean; carouselApi: EmblaCarouselType | undefined; carouselRef: HTMLElement | undefined; orientation: "vertical" | "horizontal"; scrollNext: () => void; scrollPrev: () => void; index: number; }) => any) |
item | ((props: { item: CollectionItem<string | number>; }) => any) |
CarouselContent2 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
CarouselItem2 个成员
属性
| 名称 | 类型 |
|---|---|
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
CarouselNext4 个成员
属性
| 名称 | 类型 |
|---|---|
variant | "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null |
size | "default" | "icon" | "xs" | "sm" | "lg" | "icon-xs" | "icon-sm" | "icon-lg" | null |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
CarouselPrevious4 个成员
属性
| 名称 | 类型 |
|---|---|
variant | "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null |
size | "default" | "icon" | "xs" | "sm" | "lg" | "icon-xs" | "icon-sm" | "icon-lg" | null |
class | ClassValue |
插槽
| 名称 | 类型 |
|---|---|
default | ((props: {}) => any) |
分组导出
模板标签为 <s-carousel>。
组件 SCarousel、SCarouselContent、SCarouselItem、SCarouselNext、SCarouselPrevious
函数与常量 useCarousel
类型 CarouselApi