Skip to the page
Supply UI

Carousel

A row to swipe through. Each child is one item. It swipes, drags with a mouse (an open hand shows it can) and scrolls like any row, pages with the arrow keys, and can show buttons (controls), dots (indicators), go round (loop) or turn by itself (defaultPlaying). Name it: aria-label="Photos".

Preview

Use

The code of the preview above
import { Carousel, Picture } from '@/components/ui';

<div className="ui-grow">
  <Carousel item="62%" controls indicators aria-label="The studio">
    {['Front window', 'Chair by the mirror', 'Reception desk', 'The courtyard'].map((room) => (
      <Picture key={room} seed={room} />
    ))}
  </Carousel>
</div>

This page as text, for an AI

Options

OptionTypeWhat it does
bleed boolean | stringLet the row run past the padding of the box it sits in, to its edges, instead of being cut at the padding line. The first item still lines up with the text. Inside a card or a dialog it always does this, by itself; use bleed for any other box, with its padding as a length ("var(--ui-pad-lg)", "2rem").
children ReactNodeWhat goes inside.
className stringMore classes on the outer element, for layout around it (margins, grid placement), not to restyle it.
controls booleanPrevious and next buttons under the row.
indicators booleanA dot for each page.
item stringThe width of one item: "80%", "18rem".
style CSSPropertiesInline styles on the outer element; for CSS variables such as a height, not for colours.

It also takes the 295 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.

Without React

The same look on any HTML, with the classes ui-carousel + --item.

With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:

components/carousel.cssparts/carousel.css

In the examples

Small screens made with it and the rest of the kit. They work: click, type and choose in them.

Flat 4, after the workFive rooms, finished in OctoberDone
Room by room Swipe through the finished rooms, or use the arrows

Showing things: states, do and don’t

A row to swipe through; each child is one item. controls adds previous and next buttons, indicators a dot for each page. Inside a card or a dialog it runs to the box's edges by itself (the first item still lines up with the text, and the last keeps the same room); bleed="2rem" does the same in a box of your own. Where more slides continue, the row fades into whatever is behind it (a transparency mask, so it works on any background), on the side that has more, and clears at the ends.

States. Lists, tables and boards have three more states besides their content: empty (Empty, with the first action inside), loading (Skeleton) and failed (Alert tone="danger"). A chosen row shows in ink, never in the brand colour.

Do

  • Put numbers, dates and codes in ui-mono (in a table cell, ui-num, which also aligns them).
  • Let a Table turn into blocks on a phone; give it scroll only when it is read down its columns.
  • Show a status in words and colour together (Badge tone="success" with "Paid"), never colour alone.

Don't

  • Don't put a card round a Table, List, Cells, Calendar or Empty: they draw their own box.
  • Don't truncate a name or a price to fit; let it wrap. Truncate only file names and addresses.
  • Don't use the status colours (success, warning, danger, info) for anything but those meanings.