Halcyon Skyways
Boarding pass
On timeGate closes 18:50
PDXPortlandDeparts 19:05
toKEFReykjavíkArrives 06:40 +1
- Passenger
- Mara Okafor
- Date
- Dec 16
- Flight
- HS 214
- Gate
- C7
- Seat
- 14A
- Cabin
- Main
- Group
- 3
- Boards
- 18:25
Booking QX7M2K
A boarding pass for a fictional airline: a branded header, big airport codes with the flight path between them, the passenger and gate details, a perforated tear line and a stub with a barcode. Badge, Text, Stack, Button and toastSuccess come from the system; the pass itself is app-owned CSS on tokens.
'use client'
import { Badge, Button, Stack, Text, toastSuccess } from '@blocks/design-system'
import { Check, Plane, Wallet } from 'lucide-react'
import { useId, useState } from 'react'
import styles from './boarding-pass.module.css'
const flight = {
number: 'HS 214',
date: 'Dec 16',
passenger: 'Mara Okafor',
confirmation: 'QX7M2K',
from: { code: 'PDX', city: 'Portland', time: '19:05' },
to: { code: 'KEF', city: 'Reykjavík', time: '06:40', nextDay: true },
gate: 'C7',
seat: '14A',
group: '3',
boards: '18:25',
}
const details = [
{ label: 'Passenger', value: flight.passenger, wide: true },
{ label: 'Date', value: flight.date },
{ label: 'Flight', value: flight.number },
{ label: 'Gate', value: flight.gate },
{ label: 'Seat', value: flight.seat },
{ label: 'Cabin', value: 'Main' },
{ label: 'Group', value: flight.group },
{ label: 'Boards', value: flight.boards },
]
// Bar widths (1–3 units, alternating bar and gap) derived from the booking
// code, so the same pass always draws the same barcode.
function barcode(code: string) {
const widths: number[] = []
for (const char of `${code}${flight.number}${flight.seat}`.repeat(2)) {
const value = char.charCodeAt(0)
widths.push((value % 3) + 1, ((value >> 2) % 3) + 1, ((value >> 4) % 2) + 1)
}
let x = 0
const bars = widths.map((width, index) => {
const bar = { x, width, isBar: index % 2 === 0 }
x += width
return bar
})
return { bars: bars.filter((bar) => bar.isBar), length: x }
}
export default function BoardingPass() {
const [inWallet, setInWallet] = useState(false)
const id = useId()
const { bars, length } = barcode(flight.confirmation)
function addToWallet() {
if (inWallet) return
setInWallet(true)
toastSuccess('Boarding pass added to Wallet', { description: `${flight.number} · Seat ${flight.seat}` })
}
return (
<article aria-labelledby={`${id}-title`} className={styles.pass}>
<header className={styles.top}>
<Stack direction="row" align="center" gap="sm">
<span className={styles.logo} aria-hidden>
<Plane size={16} />
</span>
<span className={styles.airline}>Halcyon Skyways</span>
</Stack>
<Text
as="h3"
id={`${id}-title`}
fontSize="xs"
fontWeight="semibold"
color="accent-fg"
margin="none"
dangerouslySetClassName={styles.eyebrow}
>
Boarding<span className={styles.wideOnly}> pass</span>
</Text>
</header>
<div className={styles.main}>
<Stack direction="row" align="center" justify="space-between" gap="sm" wrap="wrap">
<Badge tone="success" variant="solid">
On time
</Badge>
<Text fontSize="sm" color="text-muted">
Gate closes 18:50
</Text>
</Stack>
<div className={styles.route}>
<div>
<span className={styles.code}>{flight.from.code}</span>
<span className={styles.city}>{flight.from.city}</span>
<span className={styles.time}>Departs {flight.from.time}</span>
</div>
<div className={styles.flightPath} aria-hidden>
<Plane size={20} />
</div>
<span className={styles.visuallyHidden}>to</span>
<div className={styles.arrival}>
<span className={styles.code}>{flight.to.code}</span>
<span className={styles.city}>{flight.to.city}</span>
<span className={styles.time}>
Arrives {flight.to.time}
{flight.to.nextDay && <abbr title="the next day"> +1</abbr>}
</span>
</div>
</div>
<dl className={styles.details}>
{details.map((detail) => (
<div key={detail.label} data-wide={detail.wide || undefined}>
<dt>{detail.label}</dt>
<dd>{detail.value}</dd>
</div>
))}
</dl>
</div>
<div className={styles.tear} aria-hidden />
<div className={styles.stub}>
<svg
viewBox={`0 0 ${length} 24`}
preserveAspectRatio="none"
role="img"
aria-label={`Barcode for booking ${flight.confirmation}`}
data-ds-theme="light"
className={styles.barcode}
>
{bars.map((bar) => (
<rect key={bar.x} x={bar.x} width={bar.width} height="24" />
))}
</svg>
<Stack direction="row" align="center" justify="space-between" gap="sm" wrap="wrap">
<Text fontSize="sm" color="text-muted">
Booking <span className={styles.confirmation}>{flight.confirmation}</span>
</Text>
<Button type="button" size="sm" variant={inWallet ? 'ghost' : 'primary'} aria-disabled={inWallet} onClick={addToWallet}>
{inWallet ? <Check aria-hidden size={14} /> : <Wallet aria-hidden size={14} />}
{inWallet ? 'In Wallet' : 'Add to wallet'}
</Button>
</Stack>
</div>
</article>
)
}role="img" and a label, and data-ds-theme="light" keeps it black bars on a white plate in either theme, as a scanner expects.aria-disabled rather than disabled, so keyboard focus stays on the button after the toast./*
* The pass is two panels with a tear strip between them. The strip's
* background stops short of two circles at its ends, so the page shows
* through as notches.
*/
.pass {
--paper: var(--ds-color-accent-subtle);
--notch: var(--ds-space-md);
container-type: inline-size;
max-width: calc(var(--ds-space-xxxl) * 3.5);
margin-inline: auto;
color: var(--ds-color-text);
}
.top {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--ds-space-md);
padding: var(--ds-space-md) var(--ds-space-lg);
color: var(--ds-color-accent-fg);
background-color: var(--ds-color-accent);
border-radius: var(--ds-border-radius-xl) var(--ds-border-radius-xl) 0 0;
}
.logo {
display: grid;
place-items: center;
width: var(--ds-control-height-sm);
aspect-ratio: 1;
background-color: color-mix(in srgb, var(--ds-color-accent-fg) 20%, transparent);
border-radius: var(--ds-border-radius-circle);
& svg {
rotate: -45deg;
}
}
.airline {
font-weight: var(--ds-font-weight-bold);
white-space: nowrap;
}
.eyebrow {
white-space: nowrap;
text-transform: uppercase;
opacity: 0.85;
}
.main {
display: flex;
flex-direction: column;
gap: var(--ds-space-lg);
padding: var(--ds-space-lg);
background-color: var(--paper);
}
/* Route: two airports and the flight path between them. */
.route {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: var(--ds-space-md);
& > div:not(.flightPath) {
display: flex;
flex-direction: column;
}
}
.arrival {
text-align: right;
}
.code {
font-size: var(--ds-font-size-xxxl);
font-weight: var(--ds-font-weight-bold);
line-height: var(--ds-line-height-heading);
font-variant-numeric: tabular-nums;
}
.city {
font-weight: var(--ds-font-weight-medium);
}
.time {
font-size: var(--ds-font-size-sm);
color: var(--ds-color-text-muted);
& abbr {
text-decoration: none;
color: var(--ds-color-accent-text);
font-weight: var(--ds-font-weight-semibold);
}
}
.flightPath {
position: relative;
display: grid;
place-items: center;
color: var(--ds-color-accent-text);
&::before {
content: "";
position: absolute;
inset: 50% 0 auto;
border-top: var(--ds-border-width-md) dotted var(--ds-color-border-strong);
}
& svg {
position: relative;
padding: var(--ds-space-sm);
background-color: var(--paper);
border-radius: var(--ds-border-radius-circle);
box-sizing: content-box;
rotate: 45deg;
}
}
.details {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--ds-space-md) var(--ds-space-lg);
margin: 0;
& [data-wide] {
grid-column: span 2;
}
& dt {
font-size: var(--ds-font-size-xs);
color: var(--ds-color-text-muted);
text-transform: uppercase;
}
& dd {
margin: 0;
font-size: var(--ds-font-size-lg);
font-weight: var(--ds-font-weight-semibold);
white-space: nowrap;
}
}
@container (max-width: 22rem) {
.code {
font-size: var(--ds-font-size-xxl);
}
.details dd {
font-size: var(--ds-font-size-md);
}
.airline {
font-size: var(--ds-font-size-sm);
}
/* "Boarding pass" reads "Boarding" here; the heading's name stays whole. */
.wideOnly {
position: absolute;
width: var(--ds-space-xxs);
height: var(--ds-space-xxs);
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
}
/* The perforation: notched ends and a dashed line across. */
.tear {
position: relative;
height: calc(var(--notch) * 2);
background:
radial-gradient(circle at 0 50%, transparent var(--notch), var(--paper) calc(var(--notch) + var(--ds-space-xxs))) left / 50% 100% no-repeat,
radial-gradient(circle at 100% 50%, transparent var(--notch), var(--paper) calc(var(--notch) + var(--ds-space-xxs))) right / 50% 100% no-repeat;
&::after {
content: "";
position: absolute;
inset: 50% calc(var(--notch) + var(--ds-space-sm)) auto;
border-top: var(--ds-border-width-md) dashed var(--ds-color-border);
}
}
.stub {
display: flex;
flex-direction: column;
gap: var(--ds-space-md);
padding: var(--ds-space-md) var(--ds-space-lg) var(--ds-space-lg);
background-color: var(--paper);
border-radius: 0 0 var(--ds-border-radius-xl) var(--ds-border-radius-xl);
}
.barcode {
display: block;
width: 100%;
height: calc(var(--ds-space-xl) + var(--ds-space-lg));
padding: var(--ds-space-sm);
/* The barcode keeps the light theme (data-ds-theme): black bars on a white plate. */
fill: var(--ds-color-text);
background-color: var(--ds-color-bg);
border-radius: var(--ds-border-radius-sm);
}
.confirmation {
font-family: var(--ds-font-monospace);
font-weight: var(--ds-font-weight-semibold);
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;
}