Seat picker
A cinema seat map: the screen’s curve at the top, rows A to J split by an aisle, seats that are available, taken, wheelchair spaces or selected, and a summary that prices each seat by ticket type. Heading, Badge, Card, InputSelect, Separator, Button and toastSuccess come from the system; the map is app-owned CSS.
The Long Thaw
2h 14mLumen Cinema · Hall 3 · Sat, Dec 12 · 7:40 PM
Your seats
0 of 40 seats selected
Pick seats on the map. The best view is rows E to G, near the middle.
- Booking fee
- $0.00
- Total
- $0.00
Source · recipes/seat-picker.tsx
'use client'
import { Badge, BodySmall, Button, Card, Heading, InputSelect, Separator, Stack, Text, toastSuccess } from '@blocks/design-system'
import { Accessibility, Check } from 'lucide-react'
import { type ChangeEvent, useEffect, useId, useRef, useState } from 'react'
import styles from './seat-picker.module.css'
const rows = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
const seatsPerRow = 12
const seatNumbers = Array.from({ length: seatsPerRow }, (_, index) => index + 1)
const aisleAfter = 6
const maxSeats = 4
const taken = new Set(['A5', 'A6', 'B3', 'B4', 'C9', 'D5', 'D6', 'D7', 'D8', 'E1', 'E2', 'F6', 'F7', 'G10', 'G11', 'G12', 'H4', 'H5', 'I8'])
const wheelchair = new Set(['J1', 'J2', 'J11', 'J12'])
const tickets = {
adult: { label: 'Adult', price: 14.5 },
child: { label: 'Child', price: 9.5 },
senior: { label: 'Senior', price: 11 },
}
type Ticket = keyof typeof tickets
const bookingFee = 1.25
const money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
function seatLabel(seat: string) {
const status = taken.has(seat) ? 'taken' : wheelchair.has(seat) ? 'wheelchair space' : 'available'
return `Row ${seat[0]} seat ${seat.slice(1)}, ${status}`
}
// Which edges have seats scrolled past them, so they can fade as a scroll cue.
function scrollEdges(map: HTMLElement) {
return {
left: map.scrollLeft > 1,
right: map.scrollLeft + map.clientWidth < map.scrollWidth - 1,
}
}
// A cinema seat map from native checkboxes: Tab moves seat to seat, Space
// picks one, and each seat's name says where it is and whether it's free.
export default function SeatPicker() {
const [selected, setSelected] = useState<{ seat: string; ticket: Ticket }[]>([])
const [notice, setNotice] = useState('')
const [overflow, setOverflow] = useState({ left: false, right: false })
const seatMap = useRef<HTMLDivElement>(null)
const id = useId()
// On a phone the rows scroll sideways to keep seats a comfortable size.
useEffect(() => {
const map = seatMap.current
if (!map) return
const update = () => setOverflow(scrollEdges(map))
update()
window.addEventListener('resize', update)
return () => window.removeEventListener('resize', update)
}, [])
function toggle(seat: string, event: ChangeEvent<HTMLInputElement>) {
if (!event.target.checked) {
setSelected(selected.filter((choice) => choice.seat !== seat))
setNotice('')
return
}
if (selected.length >= maxSeats) {
setNotice(`You can pick up to ${maxSeats} seats. Deselect one to choose ${seat}.`)
return
}
setSelected([...selected, { seat, ticket: 'adult' }])
setNotice('')
}
function setTicket(seat: string, ticket: Ticket) {
setSelected(selected.map((choice) => (choice.seat === seat ? { ...choice, ticket } : choice)))
}
const byType = (Object.keys(tickets) as Ticket[])
.map((ticket) => ({ ticket, count: selected.filter((choice) => choice.ticket === ticket).length }))
.filter((group) => group.count > 0)
const subtotal = selected.reduce((sum, choice) => sum + tickets[choice.ticket].price, 0)
const total = subtotal + selected.length * bookingFee
return (
<section aria-labelledby={`${id}-title`} className={styles.picker}>
<Stack gap="xs">
<Stack direction="row" align="center" gap="sm" wrap="wrap">
<Heading as="h3" id={`${id}-title`} fontSize="lg">
The Long Thaw
</Heading>
<Badge>2h 14m</Badge>
</Stack>
<BodySmall margin="none" color="text-muted">
Lumen Cinema · Hall 3 · Sat, Dec 12 · 7:40 PM
</BodySmall>
</Stack>
<fieldset className={styles.map}>
<legend className={styles.legendText}>Choose up to {maxSeats} seats</legend>
<div className={styles.screen} aria-hidden>
<svg viewBox="0 0 400 40" preserveAspectRatio="none" aria-hidden>
<path d="M8 34 Q200 -2 392 34" className={styles.glow} />
<path d="M8 34 Q200 -2 392 34" className={styles.curve} />
</svg>
<span>Screen</span>
</div>
<div
ref={seatMap}
className={styles.seats}
data-fade-left={overflow.left || undefined}
data-fade-right={overflow.right || undefined}
onScroll={(event) => setOverflow(scrollEdges(event.currentTarget))}
>
<div className={styles.row} aria-hidden>
<span className={styles.rowLabel} />
{seatNumbers.map((number) => (
<SeatNumber key={number} number={number} />
))}
<span className={styles.rowLabel} data-end />
</div>
{rows.map((row) => (
<fieldset key={row} className={styles.row}>
<legend className={styles.visuallyHidden}>Row {row}</legend>
<span className={styles.rowLabel} aria-hidden>
{row}
</span>
{seatNumbers.map((number) => {
const seat = `${row}${number}`
const isSelected = selected.some((choice) => choice.seat === seat)
return (
<label
key={seat}
className={styles.seat}
data-aisle={number === aisleAfter || undefined}
data-wheelchair={wheelchair.has(seat) || undefined}
>
<input
type="checkbox"
aria-label={seatLabel(seat)}
checked={isSelected}
disabled={taken.has(seat)}
onChange={(event) => toggle(seat, event)}
/>
{isSelected ? (
<Check aria-hidden size={14} />
) : (
wheelchair.has(seat) && <Accessibility aria-hidden size={14} />
)}
</label>
)
})}
<span className={styles.rowLabel} data-end aria-hidden>
{row}
</span>
</fieldset>
))}
</div>
<ul className={styles.key} aria-label="Seat key">
<li>
<span className={styles.swatch} aria-hidden />
Available
</li>
<li>
<span className={styles.swatch} data-state="selected" aria-hidden>
<Check size={10} />
</span>
Selected
</li>
<li>
<span className={styles.swatch} data-state="taken" aria-hidden />
Taken
</li>
<li>
<span className={styles.swatch} data-state="wheelchair" aria-hidden>
<Accessibility size={10} />
</span>
Wheelchair space
</li>
</ul>
</fieldset>
<Card as="section" aria-labelledby={`${id}-summary`} padding="lg" backgroundColor="bg-subtle">
<Stack gap="md">
<Stack direction="row" justify="space-between" align="baseline" gap="sm">
<Heading as="h4" id={`${id}-summary`} fontSize="md">
Your seats
</Heading>
<Text fontSize="sm" color="text-muted">
{selected.length} of {maxSeats}
</Text>
</Stack>
<p role="status" className={notice ? styles.notice : styles.visuallyHidden}>
{notice || `${selected.length} ${selected.length === 1 ? 'seat' : 'seats'} selected`}
</p>
{selected.length === 0 ? (
<BodySmall margin="none" color="text-muted">
Pick seats on the map. The best view is rows E to G, near the middle.
</BodySmall>
) : (
<ul className={styles.choices}>
{selected.map((choice) => (
<li key={choice.seat}>
<span className={styles.seatName}>{choice.seat}</span>
<InputSelect
size="sm"
aria-label={`Ticket for seat ${choice.seat}`}
value={choice.ticket}
onChange={(event) => setTicket(choice.seat, event.target.value as Ticket)}
>
{(Object.keys(tickets) as Ticket[]).map((ticket) => (
<option key={ticket} value={ticket}>
{tickets[ticket].label}
</option>
))}
</InputSelect>
<Text fontSize="sm" dangerouslySetClassName={styles.amount}>
{money.format(tickets[choice.ticket].price)}
</Text>
</li>
))}
</ul>
)}
<Separator />
<dl className={styles.totals}>
{byType.map(({ ticket, count }) => (
<div key={ticket}>
<dt>
{count} × {tickets[ticket].label}
</dt>
<dd>{money.format(count * tickets[ticket].price)}</dd>
</div>
))}
<div>
<dt>Booking fee</dt>
<dd>{money.format(selected.length * bookingFee)}</dd>
</div>
<div className={styles.total}>
<dt>Total</dt>
<dd>{money.format(total)}</dd>
</div>
</dl>
<Button
type="button"
variant="primary"
disabled={selected.length === 0}
onClick={() =>
toastSuccess(`Holding ${selected.map((choice) => choice.seat).join(', ')}`, {
description: 'Your seats are held for 10 minutes while you pay.',
})
}
>
Continue · {money.format(total)}
</Button>
</Stack>
</Card>
</section>
)
}
function SeatNumber({ number }: { number: number }) {
return (
<span className={styles.seatNumber} data-aisle={number === aisleAfter || undefined}>
{number}
</span>
)
}How it works
- Every seat is a native checkbox, invisible and covering its seat, inside a
<label>that draws the seat with:has(:checked),:has(:disabled)and:has(:focus-visible). Tab moves seat to seat (taken seats are disabled and skipped) and Space picks one. - Each seat’s accessible name says where it is and what it is (“Row C seat 7, available”), and each row is a labelled group inside a fieldset whose legend states the limit. Taken seats are struck through and selected seats show a check, so no state relies on color alone.
- The fifth seat isn’t checked; a status message explains the four-seat limit instead, and it clears when you deselect.
- The summary lists seats in the order you picked them, each with a native ticket-type select, then totals per ticket type, the booking fee and the total, which also labels the Continue button.
- Seats never drop below a 24px target. On a phone the rows scroll sideways inside the map under sticky row letters, settle on whole seats with scroll snapping, and fade at whichever edge has more seats past it; a container query gives a wider column roomier seats, a wider aisle and letters on both sides.
App-owned CSS
.picker {
container-type: inline-size;
display: flex;
flex-direction: column;
gap: var(--ds-space-lg);
}
.map {
--seat: var(--ds-space-xl);
--seat-min: calc(var(--ds-space-lg) + var(--ds-space-md));
--gap: var(--ds-space-xs);
--label: var(--ds-space-lg);
--aisle: var(--ds-space-md);
display: flex;
flex-direction: column;
gap: var(--ds-space-md);
min-width: 0;
margin: 0;
padding: var(--ds-space-lg) var(--ds-space-md);
background-color: var(--ds-color-bg-subtle);
border: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
border-radius: var(--ds-border-radius-xl);
}
.legendText {
float: left;
width: 100%;
padding: 0;
font-size: var(--ds-font-size-sm);
font-weight: var(--ds-font-weight-semibold);
text-align: center;
}
/* The screen: a glowing arc with its label under it. */
.screen {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: var(--ds-space-md);
font-size: var(--ds-font-size-xxs);
color: var(--ds-color-text-muted);
text-transform: uppercase;
& svg {
display: block;
width: 90%;
height: var(--ds-space-xl);
overflow: visible;
}
}
.curve,
.glow {
fill: none;
stroke-linecap: round;
vector-effect: non-scaling-stroke;
}
.curve {
stroke: var(--ds-color-accent);
stroke-width: 3;
}
.glow {
stroke: color-mix(in srgb, var(--ds-color-accent) 20%, transparent);
stroke-width: 14;
}
/*
* Rows: a label, six seats, the aisle, six seats, a label. Seats never drop
* below a 24px target; when the rows don't fit they scroll under a sticky
* row letter, and the right-hand letters go.
*/
.seats {
--fade: var(--ds-space-xl);
/* Masks only read alpha, so any opaque token works as "visible". */
--solid: var(--ds-color-text);
display: flex;
flex-direction: column;
gap: var(--gap);
overflow-x: auto;
padding-block: var(--ds-space-xs);
/* Scrolling settles on whole seats, just after the sticky row letters. */
scroll-snap-type: x proximity;
scroll-padding-inline-start: calc(var(--label) + var(--gap));
&[data-fade-right] {
mask-image: linear-gradient(to right, var(--solid) calc(100% - var(--fade)), transparent);
}
/* The left fade starts after the row letters, which stay sharp. */
&[data-fade-left] {
mask-image: linear-gradient(
to right,
var(--solid) var(--label),
transparent var(--label),
var(--solid) calc(var(--label) + var(--fade))
);
}
&[data-fade-left][data-fade-right] {
mask-image: linear-gradient(
to right,
var(--solid) var(--label),
transparent var(--label),
var(--solid) calc(var(--label) + var(--fade)),
var(--solid) calc(100% - var(--fade)),
transparent
);
}
}
.row {
display: flex;
justify-content: safe center;
min-width: max-content;
gap: var(--gap);
margin: 0;
padding: 0;
border: none;
}
.rowLabel {
position: sticky;
left: 0;
z-index: 1;
flex: 0 0 var(--label);
align-self: stretch;
display: grid;
place-items: center;
background-color: var(--ds-color-bg-subtle);
font-size: var(--ds-font-size-xs);
font-weight: var(--ds-font-weight-semibold);
color: var(--ds-color-text-muted);
text-align: center;
}
.rowLabel[data-end] {
display: none;
}
.seatNumber {
scroll-snap-align: start;
flex: 1 0 var(--seat-min);
max-width: var(--seat);
min-width: 0;
font-size: var(--ds-font-size-xxs);
color: var(--ds-color-text-muted);
text-align: center;
font-variant-numeric: tabular-nums;
}
.seat {
position: relative;
display: grid;
flex: 1 0 var(--seat-min);
max-width: var(--seat);
min-width: 0;
aspect-ratio: 1;
place-items: center;
color: var(--ds-color-text-muted);
background-color: var(--ds-color-bg);
border: var(--ds-border-width-sm) solid var(--ds-color-border-strong);
border-radius: var(--ds-border-radius-md) var(--ds-border-radius-md) var(--ds-border-radius-sm) var(--ds-border-radius-sm);
cursor: pointer;
transition-property: background-color, border-color;
transition-duration: var(--ds-duration-fast);
transition-timing-function: var(--ds-easing-standard);
/* The native checkbox covers the seat, invisible, so clicks and focus are real. */
& input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: inherit;
}
&:hover {
border-color: var(--ds-color-accent);
background-color: var(--ds-color-accent-subtle);
}
&:has(:focus-visible) {
outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
outline-offset: var(--ds-space-xxs);
}
&[data-wheelchair] {
color: var(--ds-color-info-text);
border-color: var(--ds-color-info);
background-color: var(--ds-color-info-subtle);
}
&:has(:checked) {
color: var(--ds-color-accent-fg);
background-color: var(--ds-color-accent);
border-color: var(--ds-color-accent);
}
/* Taken seats are filled and struck through, so the state isn't color alone. */
&:has(:disabled) {
background: linear-gradient(to top right, transparent calc(50% - var(--ds-space-xxs)), var(--ds-color-text-muted) 50%, transparent calc(50% + var(--ds-space-xxs))),
var(--ds-color-border);
border-color: transparent;
cursor: not-allowed;
}
}
.seat[data-aisle],
.seatNumber[data-aisle] {
margin-inline-end: var(--aisle);
}
/* Wider columns get roomier seats; the seats themselves stay flexible up to --seat. */
@container (min-width: 30rem) {
.map {
--gap: var(--ds-space-sm);
--aisle: var(--ds-space-lg);
padding: var(--ds-space-lg);
}
.rowLabel[data-end] {
display: grid;
}
}
/* Key */
.key {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: var(--ds-space-sm) var(--ds-space-lg);
margin: var(--ds-space-md) 0 0;
padding: 0;
font-size: var(--ds-font-size-xs);
color: var(--ds-color-text-muted);
list-style: none;
& li {
display: flex;
align-items: center;
gap: var(--ds-space-sm);
}
}
.swatch {
display: grid;
place-items: center;
width: var(--ds-space-lg);
aspect-ratio: 1;
background-color: var(--ds-color-bg);
border: var(--ds-border-width-sm) solid var(--ds-color-border-strong);
border-radius: var(--ds-border-radius-sm);
&[data-state="selected"] {
color: var(--ds-color-accent-fg);
background-color: var(--ds-color-accent);
border-color: var(--ds-color-accent);
}
&[data-state="taken"] {
background: linear-gradient(to top right, transparent calc(50% - var(--ds-space-xxs)), var(--ds-color-text-muted) 50%, transparent calc(50% + var(--ds-space-xxs))),
var(--ds-color-border);
border-color: transparent;
}
&[data-state="wheelchair"] {
color: var(--ds-color-info-text);
background-color: var(--ds-color-info-subtle);
border-color: var(--ds-color-info);
}
}
/* Summary */
.notice {
margin: 0;
padding: var(--ds-space-sm) var(--ds-space-md);
font-size: var(--ds-font-size-sm);
color: var(--ds-color-warning-text);
background-color: var(--ds-color-warning-subtle);
border-radius: var(--ds-border-radius-md);
}
.choices {
display: flex;
flex-direction: column;
gap: var(--ds-space-sm);
margin: 0;
padding: 0;
list-style: none;
& li {
display: grid;
grid-template-columns: var(--ds-space-xl) minmax(0, 1fr) auto;
align-items: center;
gap: var(--ds-space-md);
}
}
.seatName {
font-weight: var(--ds-font-weight-semibold);
}
.amount {
font-variant-numeric: tabular-nums;
}
.totals {
display: flex;
flex-direction: column;
gap: var(--ds-space-xs);
margin: 0;
font-size: var(--ds-font-size-sm);
& div {
display: flex;
justify-content: space-between;
gap: var(--ds-space-md);
}
& dt {
color: var(--ds-color-text-muted);
}
& dd {
margin: 0;
font-variant-numeric: tabular-nums;
}
}
.total {
margin-top: var(--ds-space-sm);
font-size: var(--ds-font-size-md);
font-weight: var(--ds-font-weight-semibold);
& dt {
color: var(--ds-color-text);
}
}
.visuallyHidden {
position: absolute;
width: var(--ds-space-xxs);
height: var(--ds-space-xxs);
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
.seat {
transition: none;
}
}