Carousel

Drag or flick: slides coast then snap to centre on a spring while the neighbours shrink and dim. Layout.

Open playground
Slide 1
Slide 2
Slide 3
Slide 4
Slide 5

About

Carousel is a React component in the Layout category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { Carousel } from "@ashutoshswamy/smoui" and set items, slideWidth, onChange.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { Carousel } from "@ashutoshswamy/smoui";

<Carousel slideWidth={240} items={[<Card key="a" />, <Card key="b" />]} onChange={(i) => setIndex(i)} />

Props 3

items

Slides.

ReactNode[]
slideWidth / gap

Px.

numberdefault 240 / 14
onChange

Called on settle. Arrow keys, buttons and dots also navigate.

(index: number) => void