A row of slides you swipe, scroll or step through, with arrows, dots, the arrow keys and several in view.
Slide 1 of 4
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Carousel } from "./ui/uicontext/components/Carousel.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 34rem)" }, card: { display: "grid", alignContent: "end", gap: space.xs, aspectRatio: "16 / 10", padding: space.xl, borderRadius: radius.lg, color: "#ffffff", userSelect: "none", }, title: { margin: 0, fontSize: font.xl, fontWeight: 600, letterSpacing: "-0.02em" }, text: { margin: 0, fontSize: font.sm, opacity: 0.85, maxInlineSize: "40ch" }, s1: { backgroundImage: "linear-gradient(135deg, #1d4ed8, #6d3fd6)" }, s2: { backgroundImage: "linear-gradient(135deg, #13723a, #0e7490)" }, s3: { backgroundImage: "linear-gradient(135deg, #a34a0b, #c4302b)" }, s4: { backgroundImage: "linear-gradient(135deg, #27272a, #52525b)" },})const tour = [ { id: "inbox", title: "One inbox for the team", text: "Every email, chat and form lands in one queue you can split by team.", tone: styles.s1 }, { id: "assign", title: "Assign in a keystroke", text: "Press A to take a ticket, or let rules route it to whoever's free.", tone: styles.s2 }, { id: "sla", title: "Never miss a deadline", text: "Tickets close to their reply time move to the top and turn orange.", tone: styles.s3 }, { id: "macros", title: "Answer the same question once", text: "Save a reply as a macro and send it with two keys.", tone: styles.s4 },]// a product tour: swipe on a phone, the arrows or the arrow keys on a computer, or a dot to jumpexport const ProductTour = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( Carousel(h, { label: "Product tour", items: tour, itemKey: (s) => s.id, slide: (s) => h.div.attrs(sx(styles.card, s.tone)).children(h.h3.attrs(sx(styles.title)).children(s.title), h.p.attrs(sx(styles.text)).children(s.text)), }), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/carouselUsage
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.
Slide 1 of 6
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Carousel } from "./ui/uicontext/components/Carousel.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 44rem)" }, card: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", alignContent: "start", gap: space.sm, blockSize: "100%", boxSizing: "border-box", padding: space.lg, borderWidth: 1, borderStyle: "solid", borderColor: color.line, borderRadius: radius.lg, backgroundColor: color.panel, color: color.fg, textDecoration: "none", outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` }, }, preview: { boxSizing: "border-box", minInlineSize: 0, aspectRatio: "4 / 3", borderRadius: radius.md, backgroundColor: color.raised, borderWidth: 1, borderStyle: "solid", borderColor: color.line }, name: { fontSize: font.base, fontWeight: 500, overflowWrap: "anywhere" }, meta: { fontSize: font.sm, color: color.muted },})const templates = [ { id: "roadmap", name: "Product roadmap", meta: "Timeline · 4 views" }, { id: "bugs", name: "Bug tracker", meta: "Board · 3 views" }, { id: "crm", name: "Sales pipeline", meta: "Board · 5 views" }, { id: "content", name: "Content calendar", meta: "Calendar · 2 views" }, { id: "hiring", name: "Hiring pipeline with interview scorecards and offer approvals", meta: "Board · 6 views" }, { id: "okrs", name: "Quarterly goals", meta: "List · 2 views" },]// three at a time on a wide page, two on a tablet, one and a peek on a phone; each card is a linkexport const TemplateGallery = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( Carousel(h, { label: "Templates", items: templates, itemKey: (t) => t.id, perView: 3, slide: (t) => h.a.attrs({ href: `#template-${t.id}`, ...sx(styles.card) }).children( h.div.attrs({ "aria-hidden": "true", ...sx(styles.preview) }), h.span.attrs(sx(styles.name)).children(t.name), h.span.attrs(sx(styles.meta)).children(t.meta), ), }), )API reference
CarouselPartsComponent
Props
| Name | Type | Description |
|---|---|---|
countrequired | number | How many slides. |
labelrequired | string | What the slides are, for assistive technology: "Product photos". |
CarouselView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the carousel among others in the same view; needed for more than one. |
labelrequired | string | — | What the slides are: "Product photos", "Templates". |
itemsrequired | A[] | — | — |
itemKeyrequired | (item: A) => string | — | A stable key for each item. |
sliderequired | (item: A, index: number) => View.Content | — | — |
perView | 1 | 2 | 3 | 4 | 1 | Slides in view at once on a wide container; 1 by default. |
dots | boolean | on | Dots under the row, one per slide; on by default for one slide per view. |
style | Style | — | StyleX styles applied after the carousel's own. |