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
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>Options
| Option | Type | What it does |
|---|---|---|
bleed | boolean | string | Let 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 | ReactNode | What goes inside. |
className | string | More classes on the outer element, for layout around it (margins, grid placement), not to restyle it. |
controls | boolean | Previous and next buttons under the row. |
indicators | boolean | A dot for each page. |
item | string | The width of one item: "80%", "18rem". |
style | CSSProperties | Inline 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.cssIn the examples
Small screens made with it and the rest of the kit. They work: click, type and choose in them.
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
Tableturn into blocks on a phone; give itscrollonly 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,CalendarorEmpty: 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.