Carousel
Slides in a row that scroll and snap.
Default
{component carousel,
per: 3,
label: 'Titles',
items: [
['title' => 'Dune', 'description' => 'Frank Herbert', 'href' => '#'],
['title' => 'Emma', 'description' => 'Jane Austen', 'href' => '#'],
['title' => 'Ulysses', 'description' => 'James Joyce', 'href' => '#'],
['title' => 'Beloved', 'description' => 'Toni Morrison', 'href' => '#'],
['title' => 'Middlemarch', 'description' => 'George Eliot', 'href' => '#'],
['title' => 'Kindred', 'description' => 'Octavia Butler', 'href' => '#'],
],
/}
Each slide is an item: title, description and href, drawn the way a list row is. The track scrolls with touch, the mouse wheel and a trackpad, and snaps each slide to its start edge. It is a focusable region, so the arrow keys scroll it, and label is the name a screen reader announces.
On a screen 1024px wide or more, previous and next buttons sit at the edges. They are data-scroll buttons handled by the shared ui.js, which also lets a mouse drag the track sideways (data-drag). Without the script the track still scrolls and snaps.
Your own slides
Red
Orange
Yellow
Green
Blue
Indigo
Violet
{component carousel,
per: 4,
label: 'Colours',
items: ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet'],
}
{block slide}
{ui card, title: $item['title'], body: 'A card in each slide.' /}
{/block}
{/component}
{block slide} replaces what each slide holds, with $item in scope. That suits a cover, a card or a product, where a title and description are not enough.
Slides in view
{component carousel,
per: 3,
class: 'lg:[--per:5]',
label: 'Numbers',
items: ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'],
/}
per is how many slides show on a wide screen. Narrower screens show fewer: 2, then 3, then 4 at most. A --per utility on the carousel sets it where those steps are wrong, and it wins at any size it applies to: [--per:3] for 3 everywhere, md:[--per:6] from md up. Here per is 3, and lg:[--per:5] shows 5 from lg up.