Carousel

A row of slides you swipe, scroll or step through, with arrows, dots, the arrow keys and several in view.

Installation

Usage

import { Carousel } from "./ui/uicontext/components/Carousel.ts"
const photos = [	{ id: "front", src: "/photos/front.jpg", alt: "The chair from the front" },	{ id: "side", src: "/photos/side.jpg", alt: "The chair from the side" },]export const ProductPhotos = <M>(h: Html.H<M>) =>	Carousel(h, {		label: "Product photos",		items: photos,		itemKey: (p) => p.id,		slide: (p) => h.img.attrs({ src: p.src, alt: p.alt }),	})

Examples

Several in view

perView: 3 on a wide container; fewer as it narrows, with a peek of the next.

API reference

CarouselPartsComponent

Props

CarouselParts props
NameTypeDescription
countrequirednumberHow many slides.
labelrequiredstringWhat the slides are, for assistive technology: "Product photos".

Options

Carousel options
NameTypeDefaultDescription
keystring—Names the carousel among others in the same view; needed for more than one.
labelrequiredstring—What the slides are: "Product photos", "Templates".
itemsrequiredA[]——
itemKeyrequired(item: A) => string—A stable key for each item.
sliderequired(item: A, index: number) => View.Content——
perView1 | 2 | 3 | 41Slides in view at once on a wide container; 1 by default.
dotsbooleanonDots under the row, one per slide; on by default for one slide per view.
styleStyle—StyleX styles applied after the carousel's own.

Source