Lane board
Lanes of cards you drag within a lane and between lanes, or move with the keyboard.
Demo
Usage
import { LaneBoard, type LaneBoardLane } from '@tuttn/slant'
const lanes: LaneBoardLane[] = [
{ id: 'backlog', title: 'Backlog', cards: [
{ id: 'TASK-41', title: 'Export frames as PNG', description: 'At 1× and 2×.', meta: 'TASK-41 · Noa' },
] },
{ id: 'doing', title: 'In progress', tone: 'accent', cards: [
{ id: 'TASK-38', title: 'Colour fields', tone: 'accent' },
{ id: 'TASK-27', title: 'Release 0.4.0', disabled: true },
] },
{ id: 'review', title: 'Review', cards: [] },
]
// Uncontrolled: the board keeps its own lanes and reports each drop.
<LaneBoard label="Sprint 14" defaultLanes={lanes} onMove={move => save(move)} />
// Controlled: you hold the lanes. onLanesChange fires once per drop that
// moved a card, never while a card is lifted or on a cancel.
const [board, setBoard] = useState(lanes)
<LaneBoard label="Sprint 14" lanes={board} onLanesChange={setBoard} />
// Your own card content; the card element, its keys and its dragging stay
// the board's. Give such cards a text, the name screen readers hear.
<LaneBoard label="Sprint 14" defaultLanes={lanes}
renderCard={(card, { lifted }) => <TaskSummary task={card.id} raised={lifted} />} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
lanes | readonly LaneBoardLane[] | — | The lanes and their cards, when controlled. Pass `onLanesChange` too and keep what it reports. |
defaultLanes | readonly LaneBoardLane[] | [] | The lanes an uncontrolled board starts with; it keeps its own after that. |
onLanesChange | (lanes: LaneBoardLane[]) => void | — | Called with every lane, in the new arrangement, once per drop that moved a card. Not called while a card is lifted, on a cancel, or on a drop where the card started. |
onMove | (move: LaneBoardMove) => void | — | Called with the move once per drop that changed a card's position, after `onLanesChange`. |
label | string | — | The board's accessible name. |
renderCard | (card: LaneBoardCard, state: { lifted: boolean }) => ReactNode | — | Draws a card's content in place of its title, description and meta. The card element (focus, keys, dragging, its look) stays the board's, and is named by this content, which must not be interactive. Give such cards a `text` for the announcements. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref go on the board, the root group element. |
A lane is { id, title, cards, tone? }; a card is { id, title, text?, description?, meta?, tone?, disabled? }. A drop that moved a card calls onLanesChange with every lane in the new arrangement and then onMove with { card, from, to }, each lane and index as it is after the move. A drop where the card started, and a cancel, call neither. A disabled card can't be picked up; it stays focusable, and other cards move past it.
Keyboard
The board is one tab stop, the last card focused. Up and Down move focus within a lane, Left and Right to the nearest card in the next lane with cards, Home and End to the lane's first and last card. Space or Enter picks the card up. While it's lifted, Up and Down move it within its lane, Left and Right into the next lane (an empty one too) at the same position, Home and End to the top and bottom; focus stays on the card. Space or Enter drops it, and Escape, or moving focus away, puts it back where it started. Left and Right swap under right-to-left text.
Pointer
Press a card and move it a few pixels to carry it: it lifts, tilts and follows the pointer, and a dashed slot shows where it will land, found from the lane under the pointer and the midpoints of that lane's cards. Releasing drops it; Escape or a cancelled pointer puts it back. A press that doesn't move only focuses the card. Cards don't scroll the page on touch, so swipe the lane headers or the gaps to scroll.
Screen readers
The board and each lane are groups named by the board's label and the lane's title; each lane's count is read as "3 cards". A card is a button with the role description "movable card", named by its content (title, description and meta, or what renderCard draws, which must not be interactive) and described by the instructions; it reads as pressed while lifted, and a disabled card as unavailable. Picking up, each keyboard move, dropping and cancelling are announced assertively through the root's live region, with the card's name, its lane and its position, such as "Export frames as PNG: In progress, position 1 of 3." The words come from the root's messages; a card whose title isn't plain text, or one drawn by renderCard, needs a text to be named in them. A pointer drag announces the pick-up, the drop and a cancel, not every slot it passes.
Reduced motion
Cards move without the lift and tilt transitions, and nothing waits on an animation: a lifted or carried card is drawn in its final state at once.