# Carousel

A row of slides that scrolls sideways one page at a time.

A row of slides that scrolls sideways one page at a time, with the pager below ("2 of 5", previous, next) and optional dots. Every page change (the pager, the dots, a page set from outside, the slides advancing by themselves) travels on one fast animator, the same in every browser; a finger, a trackpad or a wheel scroll the slides themselves, and a mouse can drag them: let go while still moving (a flick), they go on to the next page at the pointer's speed. It never holds the page's vertical scroll. How a slide arrives is the effect: it slides (the default), comes forward (depth), cross-fades in place (fade) or carries a picture that lags it (parallax); the effects are drawn from where the slides are, so every way of paging draws the same thing, in every browser. With autoplay the slides advance by themselves, pausing while someone points at, focuses or cannot see them, with a pause / play button and the current dot filling as the time runs. Behaviour by Ark UI's carousel (Zag); the controls are the real Pager and Button. Controlled or uncontrolled.

Kind: component · Category: Display · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `carousel` machine, through Ark UI

## Add

```bash
npx fndn add carousel
```

It writes the folder `carousel/` into the project's ui folder (`index.ts`, `carousel.tsx`, `Carousel.vue`, `Carousel.svelte`, `carousel.recipe.ts`), and what it is built from: [Button](/components/button.md), [Pager](/components/pager.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Carousel } from "@/components/ui/carousel";
```

```vue
import { Carousel } from "@/components/ui/carousel";
```

```svelte
import { Carousel } from "$lib/components/ui/carousel";
```

## Parts

In the DOM the root carries `data-slot="carousel"` and each part `data-slot="carousel-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `carousel` |  | Ark's carousel root: role=region, aria-roledescription=carousel; a column, the slides above the control row (12px apart). As wide as its container. |
| `item-group` | `div` | `carousel-item-group` |  | The scroller (the engine's grid of columns, overflow-x auto, scroll-snap x mandatory, no scrollbar), with the slides' radius (card) so its focus ring follows their corners. When a mouse can drag it (mouseDrag), the grab cursor, grabbing while dragged. It keeps only sideways overscroll in (overscroll-x contain, from the engine), never scrolls vertically, so a vertical wheel or swipe over it moves the page. aria-live polite announces the slide that arrives. |
| `item` | `div` | `carousel-item` | repeats | One slide: role=group, aria-roledescription=slide, named "n of count" by the engine; aria-hidden while out of view. Radius card, clipped. A slide whose content is plain text is a 160px-high inset panel (inset with the hairline drawn inside it, an inset ring in color.line: the scroller clips anything outside a slide) with the text centred in text.sm ink-2, wrapping. With an effect, a slide crossing an edge of the scroller carries data-moving and the custom properties that say where it is (--fndn-carousel-out, -lag, -shift, -show): depth scales it towards motion.carousel-depth-scale and dims it towards motion.carousel-depth-opacity the further out it is; fade keeps it on the scroller's box (translated back by its own travel) and fades the later slide in over the earlier one, coming forward by half the depth scale; parallax moves the element the slide marks data-carousel="picture" (which it makes wider by motion.carousel-parallax-shift on each side) by up to that shift against the slide's travel. A slide at rest carries none of it: no transform, no property. |
| `control` | `div` | `carousel-control` |  | The row under the slides: the pause / play button and the dots at the start, the pager at the end. Hidden when there is nothing to page (one page). With autoplay it is shown even when controls is off, holding the button alone. |
| `autoplay` | `button` | `carousel-autoplay` | optional | With autoplay: the real Button (ghost, square, muted, sm, like the pager's), marked data-carousel="autoplay", first in the control row: "Pause" (Phosphor pause) while the slides are meant to advance, "Play" (play) once paused or stopped. It has a tooltip with its name, and controls the slide group (aria-controls). |
| `indicator-group` | `div` | `carousel-indicator-group` | optional | The dots (indicators prop); they wrap when there are many. Arrow keys on a dot page too (the engine's keys). |
| `indicator` | `button` | `carousel-indicator` | optional, repeats | One dot per page: a round 24px button (40px on a coarse pointer; its focus ring is round) drawing a 6px dot in line-strong; the current page's dot is ink (data-current). Named "Go to slide n" by the engine. Hovered by a mouse: ink-3. The dots are one tab stop: only the current one is in the tab order (tabIndex), and the arrow keys move between them, focus following. With autoplay, the current dot is a 16px track in line-strong that an ink bar fills from the start edge, linear, over the time a page stays; it holds while the slides are held or paused and starts over when they start again. |
| `pager` | `div` | `carousel-pager` |  | The real Pager (layout start: "2 of 5" then previous and next), marked data-carousel="pager": the position is announced as "Slide 2 of 5", the buttons have tooltips, and its arrow keys page too. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ content: node (a string is a text slide); label: string? (the slide's name, instead of "n of count") }[]` |  | The slides in order. Strings are accepted as text slides. |
| `page` | `number` | `0` | Bindable (React: `defaultPage` and `onPageChange`; Vue: `v-model:page`; Svelte: `bind:page`). Current page, 0-based. Controlled: page with onPageChange. Uncontrolled: defaultPage. |
| `slidesPerPage` | `number` | `1` | Slides shown at once; a page moves by that many. |
| `spacing` | `number` | `12` | Pixels between slides. |
| `loop` | `"none" \| "rewind" \| "endless"` | `"none"` | What follows the last page. none: nothing, the pager's Next disables there. rewind: the first page again, the slides running back to it past the others (and Previous on the first runs on to the last). endless: the first slide follows the last on a strip with no end, so Next always goes on the same way and Previous back; the pager's buttons never disable with either. Endless copies no slide (each is drawn where the strip needs it) and needs more slides than one page shows; with fewer it behaves as none. In fade, endless cross-fades straight from the last slide to the first. |
| `indicators` | `boolean` | `false` | Show the dots at the start of the control row. |
| `controls` | `boolean` | `true` | Show the control row (pager and dots). |
| `mouseDrag` | `boolean` | `true` | A mouse can drag the slides (touch and trackpads always can). |
| `dragReach` | `"page" \| "free"` | `"page"` | How far one drag takes the slides. page: the slides follow the pointer as far as the neighbouring page and stop there, however far or fast the drag is, so one drag turns one page. free: they go as far as they are dragged, and a flick adds one page more. In fade nothing follows the pointer and a drag always turns one page. |
| `effect` | `"slide" \| "depth" \| "fade" \| "parallax" \| "none"` | `"slide"` | How a slide arrives. slide: it travels sideways. depth: a slide crossing an edge is a little smaller and dimmer. fade: the slides stay in place and the later one fades in over the earlier, coming forward a little (one slide per page; with more it is slide); a sideways drag of 40px turns the page there. parallax: the element a slide marks data-carousel="picture" lags the slide, by a fifth of the width of its frame (it is made that much wider on each side, so give the slide a picture that fills its width). A slide may mark several pictures, one over the other, and give each its share of the lag with --fndn-carousel-parallax (1 by default; more for a layer further back, less for a nearer one): the layers then slide past each other. none: no animation, the page changes at once, whatever turns it (the pager, a dot, a swipe of 40px, autoplay). The others are drawn from where the slides are, so they are the same in every browser and in both directions. |
| `autoplay` | `number` | `0` | Milliseconds a page stays before the next comes by itself; 0 is off. It wraps from the last page to the first whatever loop says, holds while the pointer is over the carousel, focus is inside it, the page is hidden or it is off screen, stops for good once the user turns a page by hand or presses Pause, and does not start under reduced motion (Play starts it). |
| `label` | `string` | `"Slides"` | The pager's accessible name. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `pageChange` | (page: number) when the page changes: at once for the pager, a dot, a key and a drag that is let go (before the slides have arrived); when the scroll ends for a swipe or a wheel |

## States

`hover`, `press`, `dragging`, `focus-visible`, `playing`

## Keyboard and accessibility

Role: region.

Keyboard:

- Tab reaches the slides, the dots (one tab stop: the current dot) when shown, then the pager's buttons; Enter or Space on previous / next pages, at once
- With autoplay, the pause / play button is first in the control row (Tab, then Enter or Space); focus anywhere in the carousel holds the slides
- Arrow Left / Right on the pager or on a dot: previous / next page (mirrored right-to-left), focus following to the new current dot; Home / End on a dot: first / last page
- With focus on the slides (Tab, or a press on a slide, which focuses the scroller like any focusable thing): Arrow Left / Right previous / next page, Home / End first / last page; the pager and the dots follow at once. With focus inside a slide the arrows page too (the engine's keys)
- Slides the browser scrolls by itself (to a control that takes the focus in another slide, to a match of find-in-page) take the page with them: the pager and the dots say where the slides are

Notes:

- The root is a region with aria-roledescription=carousel; each slide is a group named "n of count" (or its label), aria-hidden while out of view so a screen reader stays on the visible page.
- The slide group is aria-live=polite: the slide that arrives is announced.
- A page changed from the keyboard, while the focus is in the carousel, is instant; under reduced motion every page change is instant.
- Autoplay: the slide group is aria-live off while the slides advance by themselves (polite again once held or paused). The pause / play button is always there while autoplay is on, even with controls off: content that moves by itself for more than five seconds needs a control to stop it (WCAG 2.2.2), and holding on hover or focus is no help to someone on a touch screen. The slides hold while the pointer is over the carousel or focus is inside it, so a reader is never paged away; a page turned by hand, or Pause, stops them until Play.
- Under prefers-reduced-motion autoplay does not start, and depth and parallax do nothing; the fade stays (opacity, not travel).

## Motion

- page changes (pager, dots, a page set from outside, autoplay): the slides travel on one animator, a critically damped spring that comes to rest in about 0.3s; never the browser's own smooth scroll, which differs between browsers. A swipe, a trackpad or a wheel scroll the slides themselves and snap
- drag: the slides follow the pointer 1:1, as far as the neighbouring page (dragReach page, the default) or as far as they are dragged (free). Let go while the pointer is still moving (a flick, however short), they go on to the next page in its direction; let go at rest, to the nearest. The spring starts at the speed they had under the pointer, never goes back first and never past the page, and the pager and the dots change at the release. With loop rewind, a drag or a flick past the last page goes round to the first, and one before the first to the last; with loop endless there is no last page, and the drag simply goes on to the next slide. In fade nothing follows the pointer: a sideways drag of 40px (mouse or finger) turns the page, once a drag
- loop endless: the first slide follows the last on a strip with no end. Next on the last page travels on to the first the same way, Previous on the first comes from the other side, a dot goes the shorter way round, and the slides advancing by themselves always go on. No slide is copied: each is drawn on the turn of the strip nearest the scroller (an offset along the strip, --fndn-carousel-round), and at rest the slides are put back one turn in, a whole number of turns away, which nothing shows. loop rewind: the slides run back to the first past the others
- from the keyboard with the focus in the carousel, or under reduced motion: the page changes at once
- dot: colour over duration.base; a press gives to motion.press-scale-sm over duration.press (pointer only)
- nothing at first paint: the initial page is shown without scrolling to it
- effects (depth, fade, parallax): drawn from where each slide is, after every change of the scroll position (custom properties on the slide, carousel.logic.ts), so the pager, a swipe and a drag all draw the same thing, in every browser and right-to-left; a slide at rest carries no transform and no property
- depth: an entering slide grows from motion.carousel-depth-scale (0.94) and motion.carousel-depth-opacity (0.5) at the edge to full size; a leaving one does the reverse
- fade: both slides stay on the scroller's box; the arriving one fades in (opacity, a 2px blur while faint) over the leaving one, so the two never dip to the background
- parallax: the marked picture lags its slide by motion.carousel-parallax-shift, a share of the width of the picture's frame (0.2: a fifth): that far behind as the slide enters, that far ahead as it leaves, and wider than its frame by as much on each side. --fndn-carousel-parallax on a picture multiplies its lag (several pictures in one slide: the further back, the more)
- autoplay: a page change by itself scrolls smoothly, even after a key was pressed (it is not a keyboard action; instant under reduced motion); the current dot's fill is linear over the dwell, holds while paused, and starts over when the slides start again, as the engine's timer does
- reduced motion: depth and parallax become the plain slide (their tokens), the fade stays, autoplay does not start
- effect none: nothing is animated. The page changes at once from the pager, the dots, a key, autoplay and a sideways drag of 40px; the scroller does not scroll under a wheel or a finger

## Tokens

`color.inset`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.line-strong`, `color.line`, `radius.card`, `radius.pill`, `text.sm`, `duration.base`, `duration.press`, `motion.press-scale-sm`, `motion.carousel-depth-scale`, `motion.carousel-depth-opacity`, `motion.carousel-parallax-shift`

## Dependencies

- [Button](/components/button.md)
- [Pager](/components/pager.md)
- [Tooltip](/components/tooltip.md)

## Examples

### What’s new, one card at a time

React · `whats-new.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const features = [
  { title: "Usage alerts", text: "Get an email when a project reaches 80% of its build minutes.", tint: "bg-accent-tint" },
  { title: "Webhook retries", text: "Failed deliveries now retry five times with exponential backoff.", tint: "bg-green-tint" },
  { title: "Preview comments", text: "Every pull request gets its preview URL as a comment.", tint: "bg-orange-tint" },
  { title: "Single sign-on", text: "Business workspaces can sign in with their identity provider.", tint: "bg-inset" },
];

export default function WhatsNew() {
  return (
    <Carousel
      className="w-80 max-w-full"
      label="What’s new"
      indicators
      items={features.map((feature) => ({
        label: feature.title,
        content: (
          <div className={`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${feature.tint}`}>
            <p className="font-medium text-ink">{feature.title}</p>
            <p className="text-ink-2">{feature.text}</p>
          </div>
        ),
      }))}
    />
  );
}
```

Vue · `whats-new.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const features = [
  { title: "Usage alerts", text: "Get an email when a project reaches 80% of its build minutes.", tint: "bg-accent-tint" },
  { title: "Webhook retries", text: "Failed deliveries now retry five times with exponential backoff.", tint: "bg-green-tint" },
  { title: "Preview comments", text: "Every pull request gets its preview URL as a comment.", tint: "bg-orange-tint" },
  { title: "Single sign-on", text: "Business workspaces can sign in with their identity provider.", tint: "bg-inset" },
];
</script>

<template>
  <Carousel class="w-80 max-w-full" label="What’s new" indicators :items="features.map((feature) => ({ label: feature.title }))">
    <template #slide="{ index }">
      <div :class="`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${features[index]!.tint}`">
        <p class="font-medium text-ink">{{ features[index]!.title }}</p>
        <p class="text-ink-2">{{ features[index]!.text }}</p>
      </div>
    </template>
  </Carousel>
</template>
```

Svelte · `whats-new.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const features = [
    { title: "Usage alerts", text: "Get an email when a project reaches 80% of its build minutes.", tint: "bg-accent-tint" },
    { title: "Webhook retries", text: "Failed deliveries now retry five times with exponential backoff.", tint: "bg-green-tint" },
    { title: "Preview comments", text: "Every pull request gets its preview URL as a comment.", tint: "bg-orange-tint" },
    { title: "Single sign-on", text: "Business workspaces can sign in with their identity provider.", tint: "bg-inset" },
  ];
</script>

<Carousel class="w-80 max-w-full" label="What’s new" indicators items={features.map((feature) => ({ label: feature.title }))}>
  {#snippet slide({ index })}
    <div class={`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${features[index]!.tint}`}>
      <p class="font-medium text-ink">{features[index]!.title}</p>
      <p class="text-ink-2">{features[index]!.text}</p>
    </div>
  {/snippet}
</Carousel>
```

### Getting started, step by step

React · `getting-started.tsx`

```tsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Carousel } from "@/components/ui/carousel";

const steps = [
  "Connect the northwind/web-app repository",
  "Pick the branch that deploys to Production",
  "Add the environment variables from your .env file",
  "Deploy, and get a URL for every pull request",
];

export default function GettingStarted() {
  const [page, setPage] = useState(0);
  return (
    <div className="flex w-full max-w-sm flex-col items-start gap-2">
      <Carousel label="Getting started" items={steps} page={page} onPageChange={setPage} />
      <Button size="sm" variant="ghost" disabled={page === steps.length - 1} onClick={() => setPage(steps.length - 1)}>Skip to deploy</Button>
    </div>
  );
}
```

Vue · `getting-started.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Button } from "@/components/ui/button";
import { Carousel } from "@/components/ui/carousel";

const steps = [
  "Connect the northwind/web-app repository",
  "Pick the branch that deploys to Production",
  "Add the environment variables from your .env file",
  "Deploy, and get a URL for every pull request",
];
const page = ref(0);
</script>

<template>
  <div class="flex w-full max-w-sm flex-col items-start gap-2">
    <Carousel v-model:page="page" label="Getting started" :items="steps" />
    <Button size="sm" variant="ghost" :disabled="page === steps.length - 1" @click="page = steps.length - 1">Skip to deploy</Button>
  </div>
</template>
```

Svelte · `getting-started.svelte`

```svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button";
  import { Carousel } from "$lib/components/ui/carousel";

  const steps = [
    "Connect the northwind/web-app repository",
    "Pick the branch that deploys to Production",
    "Add the environment variables from your .env file",
    "Deploy, and get a URL for every pull request",
  ];
  let page = $state(0);
</script>

<div class="flex w-full max-w-sm flex-col items-start gap-2">
  <Carousel bind:page label="Getting started" items={steps} />
  <Button size="sm" variant="ghost" disabled={page === steps.length - 1} onclick={() => (page = steps.length - 1)}>Skip to deploy</Button>
</div>
```

### Projects, three per page

React · `projects.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const projects = [
  { name: "web-app", detail: "Deployed 2 min ago" },
  { name: "billing-api", detail: "Deployed 1 h ago" },
  { name: "mobile", detail: "Building" },
  { name: "docs-site", detail: "Deployed yesterday" },
  { name: "data-pipeline", detail: "Failed on Staging" },
];

export default function Projects() {
  return (
    <Carousel
      className="w-full max-w-lg"
      label="Projects"
      slidesPerPage={3}
      spacing={8}
      indicators
      items={projects.map((project) => ({
        label: project.name,
        content: (
          <div className="flex h-20 flex-col justify-end gap-0.5 bg-inset p-3 text-sm">
            <p className="truncate font-medium text-ink">{project.name}</p>
            <p className="truncate text-xs text-ink-2">{project.detail}</p>
          </div>
        ),
      }))}
    />
  );
}
```

Vue · `projects.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const projects = [
  { name: "web-app", detail: "Deployed 2 min ago" },
  { name: "billing-api", detail: "Deployed 1 h ago" },
  { name: "mobile", detail: "Building" },
  { name: "docs-site", detail: "Deployed yesterday" },
  { name: "data-pipeline", detail: "Failed on Staging" },
];
</script>

<template>
  <Carousel class="w-full max-w-lg" label="Projects" :slides-per-page="3" :spacing="8" indicators :items="projects.map((project) => ({ label: project.name }))">
    <template #slide="{ index }">
      <div class="flex h-20 flex-col justify-end gap-0.5 bg-inset p-3 text-sm">
        <p class="truncate font-medium text-ink">{{ projects[index]!.name }}</p>
        <p class="truncate text-xs text-ink-2">{{ projects[index]!.detail }}</p>
      </div>
    </template>
  </Carousel>
</template>
```

Svelte · `projects.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const projects = [
    { name: "web-app", detail: "Deployed 2 min ago" },
    { name: "billing-api", detail: "Deployed 1 h ago" },
    { name: "mobile", detail: "Building" },
    { name: "docs-site", detail: "Deployed yesterday" },
    { name: "data-pipeline", detail: "Failed on Staging" },
  ];
</script>

<Carousel class="w-full max-w-lg" label="Projects" slidesPerPage={3} spacing={8} indicators items={projects.map((project) => ({ label: project.name }))}>
  {#snippet slide({ index })}
    <div class="flex h-20 flex-col justify-end gap-0.5 bg-inset p-3 text-sm">
      <p class="truncate font-medium text-ink">{projects[index]!.name}</p>
      <p class="truncate text-xs text-ink-2">{projects[index]!.detail}</p>
    </div>
  {/snippet}
</Carousel>
```

### Tips that run back to the first

React · `tips.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const tips = [
  "Press ⌘K to search projects, people and deploys.",
  "Type # in a comment to link a pull request.",
  "Hold Shift with an arrow key to resize a panel by 10%.",
];

export default function Tips() {
  return <Carousel className="w-full max-w-sm" label="Tips" loop="rewind" items={tips} />;
}
```

Vue · `tips.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const tips = [
  "Press ⌘K to search projects, people and deploys.",
  "Type # in a comment to link a pull request.",
  "Hold Shift with an arrow key to resize a panel by 10%.",
];
</script>

<template>
  <Carousel class="w-full max-w-sm" label="Tips" loop="rewind" :items="tips" />
</template>
```

Svelte · `tips.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const tips = [
    "Press ⌘K to search projects, people and deploys.",
    "Type # in a comment to link a pull request.",
    "Hold Shift with an arrow key to resize a panel by 10%.",
  ];
</script>

<Carousel class="w-full max-w-sm" label="Tips" loop="rewind" items={tips} />
```

### Starter templates that come forward as they arrive

React · `templates.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const templates = [
  { name: "Storefront", stack: "Next.js · Postgres", text: "Product pages, a cart and checkout, ready for your catalogue.", tint: "bg-accent-tint" },
  { name: "Docs site", stack: "Astro · MDX", text: "Versioned documentation with search and a changelog.", tint: "bg-green-tint" },
  { name: "Admin dashboard", stack: "SvelteKit · SQLite", text: "Tables, filters and sign-in for an internal tool.", tint: "bg-orange-tint" },
  { name: "API starter", stack: "Hono · Redis", text: "Typed routes, rate limiting and a health check.", tint: "bg-inset" },
];

export default function Templates() {
  return (
    <Carousel
      className="w-80 max-w-full"
      label="Templates"
      effect="depth"
      indicators
      items={templates.map((template) => ({
        label: template.name,
        content: (
          <div className="flex h-full flex-col rounded-card bg-surface inset-ring inset-ring-line">
            <div className={`flex h-24 items-end px-6 pt-4 ${template.tint}`}>
              <div className="flex h-full w-full flex-col gap-1.5 rounded-t-chip bg-surface p-2 shadow-hairline">
                <div className="h-1.5 w-10 rounded-pill bg-line-strong" />
                <div className="h-1.5 w-24 rounded-pill bg-line" />
                <div className="mt-auto h-6 rounded-chip bg-inset" />
              </div>
            </div>
            <div className="flex flex-col gap-0.5 p-4 text-sm">
              <p className="font-medium text-ink">{template.name}</p>
              <p className="text-xs text-ink-2">{template.stack}</p>
              <p className="mt-1 text-ink-2">{template.text}</p>
            </div>
          </div>
        ),
      }))}
    />
  );
}
```

Vue · `templates.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const templates = [
  { name: "Storefront", stack: "Next.js · Postgres", text: "Product pages, a cart and checkout, ready for your catalogue.", tint: "bg-accent-tint" },
  { name: "Docs site", stack: "Astro · MDX", text: "Versioned documentation with search and a changelog.", tint: "bg-green-tint" },
  { name: "Admin dashboard", stack: "SvelteKit · SQLite", text: "Tables, filters and sign-in for an internal tool.", tint: "bg-orange-tint" },
  { name: "API starter", stack: "Hono · Redis", text: "Typed routes, rate limiting and a health check.", tint: "bg-inset" },
];
</script>

<template>
  <Carousel class="w-80 max-w-full" label="Templates" effect="depth" indicators :items="templates.map((template) => ({ label: template.name }))">
    <template #slide="{ index }">
      <div class="flex h-full flex-col rounded-card bg-surface inset-ring inset-ring-line">
        <div :class="`flex h-24 items-end px-6 pt-4 ${templates[index]!.tint}`">
          <div class="flex h-full w-full flex-col gap-1.5 rounded-t-chip bg-surface p-2 shadow-hairline">
            <div class="h-1.5 w-10 rounded-pill bg-line-strong" />
            <div class="h-1.5 w-24 rounded-pill bg-line" />
            <div class="mt-auto h-6 rounded-chip bg-inset" />
          </div>
        </div>
        <div class="flex flex-col gap-0.5 p-4 text-sm">
          <p class="font-medium text-ink">{{ templates[index]!.name }}</p>
          <p class="text-xs text-ink-2">{{ templates[index]!.stack }}</p>
          <p class="mt-1 text-ink-2">{{ templates[index]!.text }}</p>
        </div>
      </div>
    </template>
  </Carousel>
</template>
```

Svelte · `templates.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const templates = [
    { name: "Storefront", stack: "Next.js · Postgres", text: "Product pages, a cart and checkout, ready for your catalogue.", tint: "bg-accent-tint" },
    { name: "Docs site", stack: "Astro · MDX", text: "Versioned documentation with search and a changelog.", tint: "bg-green-tint" },
    { name: "Admin dashboard", stack: "SvelteKit · SQLite", text: "Tables, filters and sign-in for an internal tool.", tint: "bg-orange-tint" },
    { name: "API starter", stack: "Hono · Redis", text: "Typed routes, rate limiting and a health check.", tint: "bg-inset" },
  ];
</script>

<Carousel class="w-80 max-w-full" label="Templates" effect="depth" indicators items={templates.map((template) => ({ label: template.name }))}>
  {#snippet slide({ index })}
    <div class="flex h-full flex-col rounded-card bg-surface inset-ring inset-ring-line">
      <div class={`flex h-24 items-end px-6 pt-4 ${templates[index]!.tint}`}>
        <div class="flex h-full w-full flex-col gap-1.5 rounded-t-chip bg-surface p-2 shadow-hairline">
          <div class="h-1.5 w-10 rounded-pill bg-line-strong"></div>
          <div class="h-1.5 w-24 rounded-pill bg-line"></div>
          <div class="mt-auto h-6 rounded-chip bg-inset"></div>
        </div>
      </div>
      <div class="flex flex-col gap-0.5 p-4 text-sm">
        <p class="font-medium text-ink">{templates[index]!.name}</p>
        <p class="text-xs text-ink-2">{templates[index]!.stack}</p>
        <p class="mt-1 text-ink-2">{templates[index]!.text}</p>
      </div>
    </div>
  {/snippet}
</Carousel>
```

### Customer quotes that cross-fade

React · `customer-quotes.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const quotes = [
  { quote: "Preview links on every pull request changed how we review design. Nobody asks for screenshots any more.", name: "Hana Ito", role: "Design lead, Fieldnote" },
  { quote: "Our deploys went from twenty minutes to two.", name: "Marcus Bell", role: "Staff engineer, Larkspur Health" },
  { quote: "We deleted four hundred lines of release scripts in the first week.", name: "Elena Petrova", role: "CTO, Tidewater" },
];

export default function CustomerQuotes() {
  return (
    <Carousel
      className="w-80 max-w-full"
      label="What teams say"
      effect="fade"
      indicators
      loop="endless"
      items={quotes.map((quote) => ({
        label: quote.name,
        content: (
          <figure className="flex h-full min-h-40 flex-col justify-between gap-4 bg-inset p-4 text-sm">
            <blockquote className="text-ink">“{quote.quote}”</blockquote>
            <figcaption className="text-xs text-ink-2">
              <span className="font-medium text-ink-2">{quote.name}</span> · {quote.role}
            </figcaption>
          </figure>
        ),
      }))}
    />
  );
}
```

Vue · `customer-quotes.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const quotes = [
  { quote: "Preview links on every pull request changed how we review design. Nobody asks for screenshots any more.", name: "Hana Ito", role: "Design lead, Fieldnote" },
  { quote: "Our deploys went from twenty minutes to two.", name: "Marcus Bell", role: "Staff engineer, Larkspur Health" },
  { quote: "We deleted four hundred lines of release scripts in the first week.", name: "Elena Petrova", role: "CTO, Tidewater" },
];
</script>

<template>
  <Carousel class="w-80 max-w-full" label="What teams say" effect="fade" indicators loop="endless" :items="quotes.map((quote) => ({ label: quote.name }))">
    <template #slide="{ index }">
      <figure class="flex h-full min-h-40 flex-col justify-between gap-4 bg-inset p-4 text-sm">
        <blockquote class="text-ink">“{{ quotes[index]!.quote }}”</blockquote>
        <figcaption class="text-xs text-ink-2">
          <span class="font-medium text-ink-2">{{ quotes[index]!.name }}</span> · {{ quotes[index]!.role }}
        </figcaption>
      </figure>
    </template>
  </Carousel>
</template>
```

Svelte · `customer-quotes.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const quotes = [
    { quote: "Preview links on every pull request changed how we review design. Nobody asks for screenshots any more.", name: "Hana Ito", role: "Design lead, Fieldnote" },
    { quote: "Our deploys went from twenty minutes to two.", name: "Marcus Bell", role: "Staff engineer, Larkspur Health" },
    { quote: "We deleted four hundred lines of release scripts in the first week.", name: "Elena Petrova", role: "CTO, Tidewater" },
  ];
</script>

<Carousel class="w-80 max-w-full" label="What teams say" effect="fade" indicators loop="endless" items={quotes.map((quote) => ({ label: quote.name }))}>
  {#snippet slide({ index })}
    <figure class="flex h-full min-h-40 flex-col justify-between gap-4 bg-inset p-4 text-sm">
      <blockquote class="text-ink">“{quotes[index]!.quote}”</blockquote>
      <figcaption class="text-xs text-ink-2">
        <span class="font-medium text-ink-2">{quotes[index]!.name}</span> · {quotes[index]!.role}
      </figcaption>
    </figure>
  {/snippet}
</Carousel>
```

### Announcements that advance by themselves, without end

React · `announcements.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

const announcements = [
  { title: "Scheduled maintenance", text: "Builds pause on Sunday, Nov 29, from 02:00 to 02:30 UTC.", tint: "bg-orange-tint" },
  { title: "Usage-based billing is live", text: "Team plans now pay for build minutes past 6,000 a month.", tint: "bg-accent-tint" },
  { title: "New region: São Paulo", text: "Deploy web-app closer to your users in South America.", tint: "bg-green-tint" },
];

export default function Announcements() {
  return (
    <Carousel
      className="w-80 max-w-full"
      label="Announcements"
      autoplay={6000}
      loop="endless"
      indicators
      items={announcements.map((announcement) => ({
        label: announcement.title,
        content: (
          <div className={`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${announcement.tint}`}>
            <p className="font-medium text-ink">{announcement.title}</p>
            <p className="text-ink-2">{announcement.text}</p>
          </div>
        ),
      }))}
    />
  );
}
```

Vue · `announcements.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

const announcements = [
  { title: "Scheduled maintenance", text: "Builds pause on Sunday, Nov 29, from 02:00 to 02:30 UTC.", tint: "bg-orange-tint" },
  { title: "Usage-based billing is live", text: "Team plans now pay for build minutes past 6,000 a month.", tint: "bg-accent-tint" },
  { title: "New region: São Paulo", text: "Deploy web-app closer to your users in South America.", tint: "bg-green-tint" },
];
</script>

<template>
  <Carousel class="w-80 max-w-full" label="Announcements" :autoplay="6000" loop="endless" indicators :items="announcements.map((announcement) => ({ label: announcement.title }))">
    <template #slide="{ index }">
      <div :class="`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${announcements[index]!.tint}`">
        <p class="font-medium text-ink">{{ announcements[index]!.title }}</p>
        <p class="text-ink-2">{{ announcements[index]!.text }}</p>
      </div>
    </template>
  </Carousel>
</template>
```

Svelte · `announcements.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  const announcements = [
    { title: "Scheduled maintenance", text: "Builds pause on Sunday, Nov 29, from 02:00 to 02:30 UTC.", tint: "bg-orange-tint" },
    { title: "Usage-based billing is live", text: "Team plans now pay for build minutes past 6,000 a month.", tint: "bg-accent-tint" },
    { title: "New region: São Paulo", text: "Deploy web-app closer to your users in South America.", tint: "bg-green-tint" },
  ];
</script>

<Carousel class="w-80 max-w-full" label="Announcements" autoplay={6000} loop="endless" indicators items={announcements.map((announcement) => ({ label: announcement.title }))}>
  {#snippet slide({ index })}
    <div class={`flex h-24 flex-col justify-end gap-1 p-4 text-sm ${announcements[index]!.tint}`}>
      <p class="font-medium text-ink">{announcements[index]!.title}</p>
      <p class="text-ink-2">{announcements[index]!.text}</p>
    </div>
  {/snippet}
</Carousel>
```

### Workspace covers, layers in parallax

React · `covers.tsx`

```tsx
import type { CSSProperties } from "react";
import { Carousel } from "@/components/ui/carousel";

/* A cover is a landscape in four layers. Each is a picture of its own (data-carousel="picture")
 * with its share of the lag (--fndn-carousel-parallax): the sun stays behind the longest, then the
 * far range, then the hills, and the pines in front hardly at all, so they slide past each other
 * as the slide crosses, as a landscape does from a train window. With a photo, mark the <img> the
 * same way. Every layer is drawn 960 wide around one centre: a slide shows the middle of it, and
 * the lag brings the rest into view. Each ridge is painted twice, the slide's colour under its own,
 * so nothing behind shows through it. Drawn in the theme's colours. */
const PINE = "l9 16h-5l8 14h-24l8 -14h-5z";
const TALL = "l11 20h-6l10 18h-30l10 -18h-6z";
const LAYERS = [
  { share: 2, d: "M0 208V140L60 118L110 132L180 84L230 120L290 70L350 126L400 104L460 60L530 122L590 92L650 130L720 76L790 124L850 98L910 128L960 110V208Z" },
  { share: 1, d: "M0 208V150C60 120 120 120 180 146S300 176 360 150S470 112 540 140S660 172 720 146S840 116 900 140L960 150V208Z" },
  { share: 0.4, d: `M0 208V176C80 158 160 162 240 178S400 196 480 176S640 150 720 172S880 190 960 170V208ZM96 137${PINE}M132 130${TALL}M404 162${PINE}M548 136${PINE}M580 124${TALL}M618 131${PINE}M800 159${PINE}M836 152${TALL}` },
];
const covers = [
  { name: "Alpine dawn", by: "Mara Lindqvist", sky: "from-orange/35 to-orange-tint", sun: "fill-red/70", at: [404, 88], tones: ["fill-orange/30", "fill-orange/60", "fill-orange"], flip: false },
  { name: "Glacier noon", by: "Tomás Oyelaran", sky: "from-accent/35 to-accent-tint", sun: "fill-orange", at: [566, 50], tones: ["fill-accent/30", "fill-accent/60", "fill-accent"], flip: true },
  { name: "Fern valley", by: "Hana Ito", sky: "from-green/35 to-green-tint", sun: "fill-orange", at: [470, 66], tones: ["fill-green/30", "fill-green/60", "fill-green"], flip: false },
  { name: "Red desert", by: "Priya Raman", sky: "from-red/35 to-red-tint", sun: "fill-orange", at: [600, 92], tones: ["fill-red/30", "fill-red/60", "fill-red"], flip: true },
];
const layer = "absolute inset-y-0 start-0 h-full";
const share = (of: number) => ({ "--fndn-carousel-parallax": of }) as CSSProperties;

export default function Covers() {
  return (
    <Carousel
      className="w-96 max-w-full"
      label="Workspace covers"
      effect="parallax"
      loop="endless"
      indicators
      items={covers.map((cover) => ({
        label: cover.name,
        content: (
          <div className="flex h-full flex-col bg-inset">
            <div className={`relative h-52 overflow-hidden bg-linear-to-b ${cover.sky}`} aria-hidden>
              <svg data-carousel="picture" style={share(3)} viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" className={layer}>
                <circle cx={cover.at[0]} cy={cover.at[1]} r="26" className={cover.sun} />
              </svg>
              {LAYERS.map((ridge, i) => (
                <svg key={i} data-carousel="picture" style={share(ridge.share)} viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" className={layer}>
                  <g transform={cover.flip ? "translate(960 0) scale(-1 1)" : undefined}>
                    <path d={ridge.d} className="fill-inset" />
                    <path d={ridge.d} className={cover.tones[i]} />
                  </g>
                </svg>
              ))}
            </div>
            <div className="flex flex-col gap-0.5 p-3 text-sm">
              <p className="font-medium text-ink">{cover.name}</p>
              <p className="text-xs text-ink-2">Illustration by {cover.by}</p>
            </div>
          </div>
        ),
      }))}
    />
  );
}
```

Vue · `covers.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

/* A cover is a landscape in four layers. Each is a picture of its own (data-carousel="picture")
 * with its share of the lag (--fndn-carousel-parallax): the sun stays behind the longest, then the
 * far range, then the hills, and the pines in front hardly at all, so they slide past each other
 * as the slide crosses, as a landscape does from a train window. With a photo, mark the <img> the
 * same way. Every layer is drawn 960 wide around one centre: a slide shows the middle of it, and
 * the lag brings the rest into view. Each ridge is painted twice, the slide's colour under its own,
 * so nothing behind shows through it. Drawn in the theme's colours. */
const PINE = "l9 16h-5l8 14h-24l8 -14h-5z";
const TALL = "l11 20h-6l10 18h-30l10 -18h-6z";
const LAYERS = [
  { share: 2, d: "M0 208V140L60 118L110 132L180 84L230 120L290 70L350 126L400 104L460 60L530 122L590 92L650 130L720 76L790 124L850 98L910 128L960 110V208Z" },
  { share: 1, d: "M0 208V150C60 120 120 120 180 146S300 176 360 150S470 112 540 140S660 172 720 146S840 116 900 140L960 150V208Z" },
  { share: 0.4, d: `M0 208V176C80 158 160 162 240 178S400 196 480 176S640 150 720 172S880 190 960 170V208ZM96 137${PINE}M132 130${TALL}M404 162${PINE}M548 136${PINE}M580 124${TALL}M618 131${PINE}M800 159${PINE}M836 152${TALL}` },
];
const covers = [
  { name: "Alpine dawn", by: "Mara Lindqvist", sky: "from-orange/35 to-orange-tint", sun: "fill-red/70", at: [404, 88], tones: ["fill-orange/30", "fill-orange/60", "fill-orange"], flip: false },
  { name: "Glacier noon", by: "Tomás Oyelaran", sky: "from-accent/35 to-accent-tint", sun: "fill-orange", at: [566, 50], tones: ["fill-accent/30", "fill-accent/60", "fill-accent"], flip: true },
  { name: "Fern valley", by: "Hana Ito", sky: "from-green/35 to-green-tint", sun: "fill-orange", at: [470, 66], tones: ["fill-green/30", "fill-green/60", "fill-green"], flip: false },
  { name: "Red desert", by: "Priya Raman", sky: "from-red/35 to-red-tint", sun: "fill-orange", at: [600, 92], tones: ["fill-red/30", "fill-red/60", "fill-red"], flip: true },
];
const layer = "absolute inset-y-0 start-0 h-full";
</script>

<template>
  <Carousel class="w-96 max-w-full" label="Workspace covers" effect="parallax" loop="endless" indicators :items="covers.map((cover) => ({ label: cover.name }))">
    <template #slide="{ index }">
      <div class="flex h-full flex-col bg-inset">
        <div :class="['relative h-52 overflow-hidden bg-linear-to-b', covers[index]!.sky]" aria-hidden="true">
          <svg data-carousel="picture" style="--fndn-carousel-parallax: 3" viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" :class="layer">
            <circle :cx="covers[index]!.at[0]" :cy="covers[index]!.at[1]" r="26" :class="covers[index]!.sun" />
          </svg>
          <svg v-for="(ridge, i) in LAYERS" :key="i" data-carousel="picture" :style="{ '--fndn-carousel-parallax': ridge.share }" viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" :class="layer">
            <g :transform="covers[index]!.flip ? 'translate(960 0) scale(-1 1)' : undefined">
              <path :d="ridge.d" class="fill-inset" />
              <path :d="ridge.d" :class="covers[index]!.tones[i]" />
            </g>
          </svg>
        </div>
        <div class="flex flex-col gap-0.5 p-3 text-sm">
          <p class="font-medium text-ink">{{ covers[index]!.name }}</p>
          <p class="text-xs text-ink-2">Illustration by {{ covers[index]!.by }}</p>
        </div>
      </div>
    </template>
  </Carousel>
</template>
```

Svelte · `covers.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  /* A cover is a landscape in four layers. Each is a picture of its own (data-carousel="picture")
   * with its share of the lag (--fndn-carousel-parallax): the sun stays behind the longest, then the
   * far range, then the hills, and the pines in front hardly at all, so they slide past each other
   * as the slide crosses, as a landscape does from a train window. With a photo, mark the <img> the
   * same way. Every layer is drawn 960 wide around one centre: a slide shows the middle of it, and
   * the lag brings the rest into view. Each ridge is painted twice, the slide's colour under its own,
   * so nothing behind shows through it. Drawn in the theme's colours. */
  const PINE = "l9 16h-5l8 14h-24l8 -14h-5z";
  const TALL = "l11 20h-6l10 18h-30l10 -18h-6z";
  const LAYERS = [
    { share: 2, d: "M0 208V140L60 118L110 132L180 84L230 120L290 70L350 126L400 104L460 60L530 122L590 92L650 130L720 76L790 124L850 98L910 128L960 110V208Z" },
    { share: 1, d: "M0 208V150C60 120 120 120 180 146S300 176 360 150S470 112 540 140S660 172 720 146S840 116 900 140L960 150V208Z" },
    { share: 0.4, d: `M0 208V176C80 158 160 162 240 178S400 196 480 176S640 150 720 172S880 190 960 170V208ZM96 137${PINE}M132 130${TALL}M404 162${PINE}M548 136${PINE}M580 124${TALL}M618 131${PINE}M800 159${PINE}M836 152${TALL}` },
  ];
  const covers = [
    { name: "Alpine dawn", by: "Mara Lindqvist", sky: "from-orange/35 to-orange-tint", sun: "fill-red/70", at: [404, 88], tones: ["fill-orange/30", "fill-orange/60", "fill-orange"], flip: false },
    { name: "Glacier noon", by: "Tomás Oyelaran", sky: "from-accent/35 to-accent-tint", sun: "fill-orange", at: [566, 50], tones: ["fill-accent/30", "fill-accent/60", "fill-accent"], flip: true },
    { name: "Fern valley", by: "Hana Ito", sky: "from-green/35 to-green-tint", sun: "fill-orange", at: [470, 66], tones: ["fill-green/30", "fill-green/60", "fill-green"], flip: false },
    { name: "Red desert", by: "Priya Raman", sky: "from-red/35 to-red-tint", sun: "fill-orange", at: [600, 92], tones: ["fill-red/30", "fill-red/60", "fill-red"], flip: true },
  ];
  const layer = "absolute inset-y-0 start-0 h-full";
</script>

<Carousel class="w-96 max-w-full" label="Workspace covers" effect="parallax" loop="endless" indicators items={covers.map((cover) => ({ label: cover.name }))}>
  {#snippet slide({ index })}
    {@const cover = covers[index]!}
    <div class="flex h-full flex-col bg-inset">
      <div class="relative h-52 overflow-hidden bg-linear-to-b {cover.sky}" aria-hidden="true">
        <svg data-carousel="picture" style="--fndn-carousel-parallax: 3" viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" class={layer}>
          <circle cx={cover.at[0]} cy={cover.at[1]} r="26" class={cover.sun} />
        </svg>
        {#each LAYERS as ridge, i (i)}
          <svg data-carousel="picture" style="--fndn-carousel-parallax: {ridge.share}" viewBox="0 0 960 208" preserveAspectRatio="xMidYMax slice" class={layer}>
            <g transform={cover.flip ? "translate(960 0) scale(-1 1)" : undefined}>
              <path d={ridge.d} class="fill-inset" />
              <path d={ridge.d} class={cover.tones[i]} />
            </g>
          </svg>
        {/each}
      </div>
      <div class="flex flex-col gap-0.5 p-3 text-sm">
        <p class="font-medium text-ink">{cover.name}</p>
        <p class="text-xs text-ink-2">Illustration by {cover.by}</p>
      </div>
    </div>
  {/snippet}
</Carousel>
```

### Editor shortcuts, changed at once with no animation

React · `shortcuts.tsx`

```tsx
import { Carousel } from "@/components/ui/carousel";

/* a dense tool, where nothing should move: the tip changes at once */
const shortcuts = [
  "⌘P opens any file by name.",
  "⌘⇧F searches every file in the workspace.",
  "⌥↑ and ⌥↓ move the current line.",
  "⌘/ comments out the selection.",
];

export default function Shortcuts() {
  return <Carousel className="w-full max-w-sm" label="Shortcuts" effect="none" indicators loop="rewind" items={shortcuts} />;
}
```

Vue · `shortcuts.vue`

```vue
<script setup lang="ts">
import { Carousel } from "@/components/ui/carousel";

/* a dense tool, where nothing should move: the tip changes at once */
const shortcuts = [
  "⌘P opens any file by name.",
  "⌘⇧F searches every file in the workspace.",
  "⌥↑ and ⌥↓ move the current line.",
  "⌘/ comments out the selection.",
];
</script>

<template>
  <Carousel class="w-full max-w-sm" label="Shortcuts" effect="none" indicators loop="rewind" :items="shortcuts" />
</template>
```

Svelte · `shortcuts.svelte`

```svelte
<script lang="ts">
  import { Carousel } from "$lib/components/ui/carousel";

  /* a dense tool, where nothing should move: the tip changes at once */
  const shortcuts = [
    "⌘P opens any file by name.",
    "⌘⇧F searches every file in the workspace.",
    "⌥↑ and ⌥↓ move the current line.",
    "⌘/ comments out the selection.",
  ];
</script>

<Carousel class="w-full max-w-sm" label="Shortcuts" effect="none" indicators loop="rewind" items={shortcuts} />
```

## Recipe

`carousel.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* carousel — a row of slides that moves sideways a page at a time (Ark UI carousel).
 *
 * The engine owns the scroller's layout (a grid of columns sized from --slides-per-page and
 * --slide-spacing, overflow-x auto, scroll-snap x mandatory, overscroll-behavior-x contain, no
 * scrollbar), the pages and the keyboard. How the slides move is carousel.logic.ts: one animator
 * for every page change (a spring, never the browser's own smooth scroll, which differs between
 * browsers), the drag, and where each slide is. Here: the scroller never scrolls vertically (a
 * vertical wheel or swipe goes on to the page); slides are clipped to the card radius; a slide of
 * plain text is an inset panel. While a drag or the animator moves the slides the scroller carries
 * data-dragging or data-settling, and scroll snapping is off: it would pull every frame back.
 *
 * The scroller has the slides' radius, so its focus ring follows their corners. A mouse that can
 * drag the slides (`draggable`, the mouseDrag prop) sees the grab cursor, grabbing while it drags,
 * as on the slider's thumb. A text slide's hairline is drawn inside it (an inset ring): the
 * scroller clips anything outside a slide, which left only the corners of an outer ring.
 *
 * Effects (how a slide arrives) are drawn from where the slide is. A slide crossing an edge of the
 * scroller carries data-moving and four custom properties (--fndn-carousel-out, -lag, -shift, -show:
 * carousel.logic.ts), set after every change of the scroll position, so the pager, the dots, a
 * wheel, a swipe, a drag and a flick all draw the same thing, in every browser and in both
 * directions. A slide at rest carries nothing: no transform, so its text is never on one.
 *   depth     the slide shrinks and dims the further out it is (`scale`, opacity)
 *   fade      nothing travels: the two slides sit on the scroller's box (`translate` takes their
 *             travel back) and the later one fades in over the earlier. The scroller does not
 *             scroll under a wheel or a finger then (a drag turns the page: the logic)
 *   none      no animation at all: the page changes at once, whatever turns it
 *   parallax  the picture a slide marks (data-carousel="picture") lags its slide, by a share of
 *             its frame's width; several pictures in one slide can each take a different share
 *             (--fndn-carousel-parallax: the further back, the more)
 * The amounts are tokens; under reduced motion depth and parallax are still.
 *
 * On an endless strip (loop "endless") the first slide follows the last. No slide is copied: the
 * logic draws each one on the turn of the strip nearest the scroller, by an offset along the
 * strip (--fndn-carousel-round), so an effect still sees every slide once, where it is drawn.
 *
 * The control row holds, at the start, the pause / play button when the slides advance by
 * themselves (the real Button, marked data-carousel="autoplay"), then the dots, and the real Pager
 * at the end (marked data-carousel="pager"; its classes are the `pager` slot, passed as
 * className). A dot is a 24px button (40px under a finger), round so its focus ring is, whose
 * ::before is the 6px dot: line-strong, ink when current. The dots are one tab stop (the current
 * one; the adapter's tabIndex), and the arrow keys move between them. While the slides advance by
 * themselves the current dot is a 16px track (::before) that an ink bar (::after) fills, linear,
 * over the time a page stays (--fndn-carousel-dwell, set by the adapter); paused, the fill holds. */
export const carousel = tv({
  slots: {
    base: "flex flex-col gap-3 min-w-0 w-full",
    itemGroup: "min-w-0 overflow-y-hidden rounded-card [&::-webkit-scrollbar]:hidden data-dragging:[scroll-snap-type:none]! data-settling:[scroll-snap-type:none]!",
    item: "min-w-0 overflow-hidden rounded-card",
    control: "flex items-center gap-3 min-w-0",
    autoplay: "shrink-0",
    indicatorGroup: "flex flex-wrap items-center min-w-0",
    indicator: [
      "relative grid place-items-center size-6 rounded-pill pointer-coarse:size-10",
      "before:content-[''] before:size-1.5 before:rounded-pill before:bg-line-strong",
      "before:motion-colors-base before:motion-transform-press",
      "hover:before:bg-ink-3 data-current:before:bg-ink",
      "[:root:not([data-fndn-input=keyboard])_&:active]:before:scale-press-sm",
    ],
    pager: "ms-auto",
  },
  variants: {
    /* how a slide arrives (the effect prop) */
    effect: {
      /* the slides travel sideways with the scroll, nothing more */
      slide: {},
      /* no animation: the page changes at once (the logic never lets it travel). Nothing travels,
       * so, as in fade, the scroller does not scroll by itself and a sideways drag turns the page */
      none: { itemGroup: "overflow-x-hidden! touch-pan-y" },
      /* a slide crossing an edge is smaller and dimmer, the more the further out it is */
      depth: {
        item: [
          "data-moving:[scale:calc(1-(1-var(--fndn-motion-carousel-depth-scale))*var(--fndn-carousel-out))]",
          "data-moving:opacity-[calc(1-(1-var(--fndn-motion-carousel-depth-opacity))*var(--fndn-carousel-out))]",
        ],
      },
      /* the slides stay on the scroller's box and cross-fade (one slide per page: the adapter
       * passes slide otherwise). Nothing travels, so the scroller does not scroll by itself (its
       * overflow is hidden, over the engine's own style) and a sideways finger is the drag's */
      fade: {
        itemGroup: "overflow-x-hidden! touch-pan-y",
        item: [
          "data-moving:[translate:var(--fndn-carousel-shift)_0] data-moving:opacity-(--fndn-carousel-show)",
          /* the slide fading in comes forward a little as it does (half the depth effect's scale) */
          "data-moving:[scale:calc(1-(1-var(--fndn-motion-carousel-depth-scale))*0.5*(1-var(--fndn-carousel-show)))]",
        ],
      },
      /* the picture a slide marks (data-carousel="picture") lags the slide: by a share of its
       * frame's width (the token), so it reads the same in a small slide and a wide one. It is
       * wider than its frame by that much on each side, so the slide's clip never shows its edge.
       * A slide may mark several, one over the other: --fndn-carousel-parallax on a picture is its
       * share of the lag (1 by default; more for a layer further back, which stays behind longer,
       * less for a nearer one), so the layers slide past each other. `translate` counts in the
       * picture's own width, which is wider than the frame: hence the division */
      parallax: {
        item: [
          "[&_[data-carousel=picture]]:max-w-none [&_[data-carousel=picture]]:shrink-0",
          "[&_[data-carousel=picture]]:w-[calc(100%*(1+2*var(--fndn-motion-carousel-parallax-shift)*var(--fndn-carousel-parallax,1)))]",
          "[&_[data-carousel=picture]]:mx-[calc(-100%*var(--fndn-motion-carousel-parallax-shift)*var(--fndn-carousel-parallax,1))]",
          "data-moving:[&_[data-carousel=picture]]:[translate:calc(var(--fndn-carousel-lag)*-100%*var(--fndn-motion-carousel-parallax-shift)*var(--fndn-carousel-parallax,1)/(1+2*var(--fndn-motion-carousel-parallax-shift)*var(--fndn-carousel-parallax,1)))_0]",
        ],
      },
    },
    /* the slides advance by themselves (the autoplay prop): the current dot is a track that fills */
    autoplay: {
      true: {
        indicator: [
          "before:[grid-area:1/1] data-current:before:w-4 data-current:before:bg-line-strong",
          "data-current:after:content-[''] data-current:after:[grid-area:1/1] data-current:after:h-1.5 data-current:after:w-4 data-current:after:rounded-pill data-current:after:bg-ink",
          "data-current:after:origin-left [&:dir(rtl)]:data-current:after:origin-right data-current:after:animate-[fndn-carousel-progress_var(--fndn-carousel-dwell)_linear_both]",
        ],
      },
    },
    /* the strip has no end (loop "endless"): a slide can be drawn a whole number of turns further
     * along it, by the offset the logic gives it (--fndn-carousel-round; none at its own place) */
    endless: {
      true: {
        /* the scrollable width is the whole strip (--fndn-carousel-strip), held open by a 1px
         * box at its far end, so it does not change as slides are drawn further along */
        itemGroup: "relative after:content-[''] after:absolute after:top-0 after:start-(--fndn-carousel-strip) after:size-px after:pointer-events-none",
        item: "relative start-(--fndn-carousel-round)",
      },
    },
    /* the slides are advancing now; otherwise the current dot's fill holds where it is */
    playing: { true: {}, false: {} },
    /* a mouse can drag the slides (the mouseDrag prop) */
    draggable: {
      true: { itemGroup: "cursor-grab data-dragging:cursor-grabbing data-settling:cursor-grabbing" },
    },
    /* a slide whose content is plain text */
    plain: {
      true: {
        item: "flex items-center justify-center min-h-40 p-4 bg-inset inset-ring inset-ring-line text-sm leading-normal text-ink-2 text-center wrap-anywhere [unicode-bidi:plaintext]",
      },
    },
  },
  /* any after: class gives the dot an ::after, which would push its ::before off centre: only a
   * dot that has the fill is told to hold it */
  compoundVariants: [{ autoplay: true, playing: false, class: { indicator: "data-current:after:[animation-play-state:paused]" } }],
  defaultVariants: { effect: "slide" },
});

export type CarouselRecipeProps = VariantProps<typeof carousel>;
```
