Carousel

A horizontally scrolling row of slides, built on CSS scroll-snap rather than a transform track — so touch swiping, momentum and keyboard scrolling all keep working.

src/components/ui/carousel.tsx

About

From the component's own source, where it was written.

Default label formatters, hoisted out of the parameter list.

An arrow function written inline as a default parameter is a value the React Compiler cannot safely reorder, so it bails on the whole component and none of it gets auto-memoised. At module scope it is a stable reference and the component compiles.

Install

npx astralyx-ui add carousel

Usage

import { Carousel } from '@/components/ui/carousel'

<Carousel slidesToShow={2}>
  {slides.map((s) => <Slide key={s.id} {...s} />)}
</Carousel>

Composer

Change the props and the source below follows.

Slide 1
Slide 2
Slide 3
Slide 4
Slide 5
Slide 6
Props
tsx
<Carousel slidesToShow={2}>
  {slides}
</Carousel>

Examples

Two at a time

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.