Departures board
A train station's next departures on a dark board: split-flap tiles for times and platforms, destinations in amber, and status as Badge tones. A Select filters by line and Refresh sends the first train on its way, flipping the board.
Larch Street
Departures · updated| Time | Destination | Plat. | Status |
|---|---|---|---|
| 08:41 | Harbor PointPlat. 2 · Coastal line via Mill Bridge, Saltmarsh | 2 | Boarding |
| 08:44 | AirportPlat. 4 · Airport line via Exhibition Hall, Terminal 1 | 4 | On time |
| 08:47 | Cedar FallsPlat. 1 · Valley line via Orchard Road, Hollins | 1 | Exp. |
| 08:52 | Gull IslandPlat. – · Coastal line via Saltmarsh, Lighthouse | None | Cancelled |
| 08:59 | AirportPlat. 4 · Airport line via Exhibition Hall, Terminal 1 | 4 | On time |
| 09:03 | Pine SummitPlat. 1 · Valley line via Hollins, Upper Ridge | 1 | On time |
Coastal line: buses replace trains between Saltmarsh and Gull Island until 10:00. Allow 20 extra minutes.
Source · recipes/departures-board.tsx
'use client'
import { Badge, Button, Select, Stack, Text } from '@blocks/design-system'
import { Info, RefreshCw, TrainFront } from 'lucide-react'
import { useState } from 'react'
import styles from './departures-board.module.css'
type Status = { kind: 'on-time' } | { kind: 'boarding' } | { kind: 'delayed'; expected: string } | { kind: 'cancelled' }
interface Departure {
id: string
time: string
destination: string
line: 'Coastal' | 'Valley' | 'Airport'
via: string
platform: string
status: Status
}
// The day's departures from a fictional station, in order. The board shows
// the next six; Refresh sends the first one on its way.
const timetable: Departure[] = [
{ id: 'c214', time: '08:41', destination: 'Harbor Point', line: 'Coastal', via: 'Mill Bridge, Saltmarsh', platform: '2', status: { kind: 'boarding' } },
{ id: 'a102', time: '08:44', destination: 'Airport', line: 'Airport', via: 'Exhibition Hall, Terminal 1', platform: '4', status: { kind: 'on-time' } },
{ id: 'v330', time: '08:47', destination: 'Cedar Falls', line: 'Valley', via: 'Orchard Road, Hollins', platform: '1', status: { kind: 'delayed', expected: '08:55' } },
{ id: 'c216', time: '08:52', destination: 'Gull Island', line: 'Coastal', via: 'Saltmarsh, Lighthouse', platform: '3', status: { kind: 'cancelled' } },
{ id: 'a104', time: '08:59', destination: 'Airport', line: 'Airport', via: 'Exhibition Hall, Terminal 1', platform: '4', status: { kind: 'on-time' } },
{ id: 'v332', time: '09:03', destination: 'Pine Summit', line: 'Valley', via: 'Hollins, Upper Ridge', platform: '1', status: { kind: 'on-time' } },
{ id: 'c218', time: '09:10', destination: 'Harbor Point', line: 'Coastal', via: 'Mill Bridge, Saltmarsh', platform: '2', status: { kind: 'on-time' } },
{ id: 'v334', time: '09:14', destination: 'Cedar Falls', line: 'Valley', via: 'Orchard Road, Hollins', platform: '3', status: { kind: 'delayed', expected: '09:18' } },
{ id: 'a106', time: '09:16', destination: 'Airport', line: 'Airport', via: 'Exhibition Hall, Terminal 1', platform: '4', status: { kind: 'on-time' } },
]
const lines = ['All lines', 'Coastal', 'Valley', 'Airport'] as const
type LineFilter = (typeof lines)[number]
const visible = 6
/** One character per tile, like a split-flap display. The row's text is read once, not per letter. */
function Flaps({ text, tone }: { text: string; tone?: 'muted' }) {
return (
<span className={tone ? `${styles.flaps} ${styles.muted}` : styles.flaps} aria-hidden>
{[...text].map((character, i) =>
// A time's colon sits between the tiles, as on a real board.
character === ':' ? (
// biome-ignore lint/suspicious/noArrayIndexKey: characters of a fixed string, in place
<span key={i} className={styles.colon}>
:
</span>
) : (
// biome-ignore lint/suspicious/noArrayIndexKey: characters of a fixed string, in place
<span key={i} className={styles.flap} style={{ animationDelay: `${i * 35}ms` }}>
{character}
</span>
),
)}
</span>
)
}
function StatusCell({ status }: { status: Status }) {
switch (status.kind) {
case 'boarding':
return <Badge tone="success" variant="solid">Boarding</Badge>
case 'on-time':
return <Badge tone="success">On time</Badge>
case 'delayed':
return (
<Badge tone="warning">
Exp. <time>{status.expected}</time>
</Badge>
)
case 'cancelled':
return <Badge tone="danger">Cancelled</Badge>
}
}
export default function DeparturesBoard() {
const [departed, setDeparted] = useState(0)
const [line, setLine] = useState<LineFilter>('All lines')
// Bumped on every change so the rows remount and flip again.
const [flip, setFlip] = useState(0)
// The Select's list mounts inside the board so it keeps the dark theme.
const [board, setBoard] = useState<HTMLDivElement | null>(null)
const upcoming = timetable.slice(departed).filter((departure) => line === 'All lines' || departure.line === line)
const rows = upcoming.slice(0, visible)
function refresh() {
setDeparted((count) => (count + 1) % (timetable.length - visible + 1))
setFlip((count) => count + 1)
}
return (
<div ref={setBoard} className={styles.board} data-ds-theme="dark">
<Stack direction="row" gap="sm" align="center" justify="space-between" wrap="wrap">
<Stack direction="row" gap="sm" align="center">
<TrainFront aria-hidden size={22} className={styles.icon} />
<Stack gap="none">
<h3 className={styles.station}>Larch Street</h3>
<Text fontSize="sm" color="text-muted">
Departures · updated <time>{timetable[departed]?.time}</time>
</Text>
</Stack>
</Stack>
<Stack direction="row" gap="xs" align="center">
<Select
value={line}
onValueChange={(value) => {
setLine(value as LineFilter)
setFlip((count) => count + 1)
}}
>
<Select.Trigger aria-label="Line" size="sm" />
<Select.Content container={board}>
{lines.map((name) => (
<Select.Item key={name} value={name}>
{name}
</Select.Item>
))}
</Select.Content>
</Select>
<Button size="sm" variant="ghost" onClick={refresh} aria-label="Refresh departures">
<RefreshCw aria-hidden size={16} />
</Button>
</Stack>
</Stack>
<table className={styles.table} aria-describedby="departures-board-notice">
<caption className={styles.caption}>Next departures, {line.toLowerCase()}</caption>
<thead>
<tr>
<th scope="col">Time</th>
<th scope="col">Destination</th>
<th scope="col" className={styles.platform}>
<abbr title="Platform">Plat.</abbr>
</th>
<th scope="col" className={styles.status}>
Status
</th>
</tr>
</thead>
<tbody key={flip}>
{rows.map((departure) => {
const cancelled = departure.status.kind === 'cancelled'
return (
<tr key={departure.id} className={cancelled ? styles.cancelled : undefined}>
<th scope="row">
<span className={styles.visuallyHidden}>{departure.time}</span>
<Flaps text={departure.time} tone={cancelled ? 'muted' : undefined} />
</th>
<td>
<span className={styles.destination}>{departure.destination}</span>
<span className={styles.via}>
{/* On a phone the platform moves here from its own column. */}
<span className={styles.platformInline}>Plat. {cancelled ? '–' : departure.platform} · </span>
{departure.line}
<span className={styles.stops}> line via {departure.via}</span>
</span>
</td>
<td className={styles.platform}>
<span className={styles.visuallyHidden}>{cancelled ? 'None' : departure.platform}</span>
<Flaps text={cancelled ? '–' : departure.platform} tone={cancelled ? 'muted' : undefined} />
</td>
<td className={styles.status}>
<StatusCell status={departure.status} />
</td>
</tr>
)
})}
{rows.length === 0 && (
<tr>
<td colSpan={4} className={styles.empty}>
No more {line} departures this hour.
</td>
</tr>
)}
</tbody>
</table>
<p id="departures-board-notice" className={styles.notice}>
<Info aria-hidden size={16} />
<span>
Coastal line: buses replace trains between Saltmarsh and Gull Island until 10:00. Allow 20 extra minutes.
</span>
</p>
</div>
)
}How it works
- It is a real
<table>with a caption and row headers, so a screen reader hears "08:41, Harbor Point, platform 2, Boarding". The tiles are decoration (aria-hidden); each cell also carries its text once, visually hidden. data-ds-theme="dark"makes the board dark on any page, and theSelectmounts its list inside the board (container) so the list is dark too.- Status is never color alone: each
Badgesays On time, Exp. 08:55 or Cancelled, and a cancelled row is also struck through. - Remounting the rows replays the flip. The animation stops under
prefers-reduced-motion. - On a phone a container query drops the platform column and shortens the route line to the platform and line ("Plat. 2 · Coastal"), so destinations keep their width and wrap whole rather than truncate.
App-owned CSS
/* A station departures board: the dark theme's tokens, split-flap tiles for times and platforms. */
.board {
container-type: inline-size;
display: grid;
gap: var(--ds-space-md);
padding: var(--ds-space-lg);
border-radius: var(--ds-border-radius-xl);
background: var(--ds-color-bg);
color: var(--ds-color-text);
box-shadow: var(--ds-shadow-lg);
}
.icon {
color: var(--ds-color-warning);
flex: none;
}
.station {
margin: 0;
font: var(--ds-font-weight-bold) var(--ds-font-size-lg) / 1.2 var(--ds-font-heading);
letter-spacing: -0.01em;
}
.caption {
text-align: start;
padding-bottom: var(--ds-space-xs);
font-size: var(--ds-font-size-xs);
font-weight: var(--ds-font-weight-semibold);
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ds-color-text-muted);
}
.table {
width: 100%;
border-collapse: collapse;
}
.table thead th {
padding: 0 var(--ds-space-xs) var(--ds-space-xs);
white-space: nowrap;
font-size: var(--ds-font-size-xs);
font-weight: var(--ds-font-weight-medium);
color: var(--ds-color-text-muted);
text-align: start;
}
.table abbr {
text-decoration: none;
}
.table tbody th,
.table tbody td {
padding: var(--ds-space-sm) var(--ds-space-xs);
border-top: 1px solid var(--ds-color-border-subtle);
vertical-align: middle;
text-align: start;
font-weight: inherit;
}
.platform {
text-align: center;
}
.table .platform {
text-align: center;
}
.table .status {
text-align: end;
white-space: nowrap;
}
.flaps {
display: inline-flex;
gap: 2px;
font: var(--ds-font-weight-semibold) var(--ds-font-size-md) / 1 var(--ds-font-monospace);
}
.flap {
display: inline-grid;
place-items: center;
min-width: 1.15em;
padding: 0.28em 0.12em;
border-radius: var(--ds-border-radius-sm);
/* The split: a hairline across the middle of each tile. */
background:
linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--ds-color-bg) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
linear-gradient(to bottom, var(--ds-color-surface-hover), var(--ds-color-surface));
color: var(--ds-color-warning-text);
box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--ds-color-bg) 60%, transparent);
animation: flip 360ms cubic-bezier(0.3, 0.7, 0.4, 1) both;
transform-origin: 50% 50%;
}
.colon {
align-self: center;
color: var(--ds-color-warning-text);
}
.muted .flap,
.muted .colon {
color: var(--ds-color-text-muted);
}
@keyframes flip {
from {
transform: perspective(200px) rotateX(-90deg);
opacity: 0.2;
}
}
@media (prefers-reduced-motion: reduce) {
.flap {
animation: none;
}
}
.destination {
display: block;
font-size: var(--ds-font-size-md);
font-weight: var(--ds-font-weight-semibold);
color: var(--ds-color-warning-text);
}
.via {
display: block;
margin-top: 2px;
font-size: var(--ds-font-size-xs);
color: var(--ds-color-text-muted);
}
.cancelled .destination {
color: var(--ds-color-text-muted);
text-decoration: line-through;
}
.empty {
padding: var(--ds-space-lg) var(--ds-space-xs);
color: var(--ds-color-text-muted);
text-align: center;
}
.notice {
display: flex;
gap: var(--ds-space-xs);
align-items: flex-start;
margin: 0;
padding: var(--ds-space-sm) var(--ds-space-md);
border-radius: var(--ds-border-radius-md);
background: var(--ds-color-warning-subtle);
color: var(--ds-color-warning-text);
font-size: var(--ds-font-size-sm);
}
.notice svg {
flex: none;
margin-top: 2px;
}
.visuallyHidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/* Shown only on a phone, where the platform column is dropped. */
.platformInline {
display: none;
}
/* A phone: the platform joins the route line, so destinations keep the width and wrap whole. */
@container (max-width: 420px) {
.board {
padding: var(--ds-space-md);
}
.flaps {
gap: 1px;
font-size: var(--ds-font-size-sm);
}
.flap {
min-width: 1em;
padding-inline: 0.06em;
}
.table .platform {
display: none;
}
.platformInline {
display: inline;
color: var(--ds-color-text);
font-weight: var(--ds-font-weight-medium);
}
.destination {
font-size: var(--ds-font-size-sm);
}
.stops {
display: none;
}
.via {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table tbody td:nth-child(2) {
max-width: 0;
width: 100%;
}
}