Departures
import { useId, useRef, useState } from 'react';
const ITEMS = [
{ label: 'Lisbon', dest: 'LISBON', time: '09:40', gate: 'B12', note: 'Boarding' },
{ label: 'Kyoto', dest: 'KYOTO', time: '11:15', gate: 'C04', note: 'On time' },
{ label: 'Oslo', dest: 'OSLO', time: '13:05', gate: 'A21', note: 'Delayed 10 min' },
];
const W = 6;
const cells = (s: string) => s.padEnd(W, ' ').slice(0, W).split('');
const css = `
/* A cell flaps down from the top half: hinged at the middle, a beat after the cell to its left. */
@keyframes tabs-departures-flap { 0% { transform: rotateX(-90deg); filter: brightness(1.6); } 70% { transform: rotateX(8deg); } 100% { transform: none; } }
.tabs-departures { display: grid; gap: 12px; width: 260px; }
.tabs-departures__list { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.tabs-departures__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-departures__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-departures__tab { flex: 1; padding: 6px 0; border-radius: 7px; color: light-dark(#5f626a, #a7abb2); font-size: 12.5px; font-weight: 500; transition: background-color 0.2s, color 0.2s; }
.tabs-departures__tab[aria-selected='true'] { background: light-dark(#373a40, #f1f2f3); color: light-dark(#fbfcfd, #121417); }
.tabs-departures__panel { display: grid; gap: 6px; padding: 12px; border-radius: 10px; background: light-dark(#fbfcfd, #121417); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.tabs-departures__row { display: flex; align-items: center; gap: 2px; perspective: 200px; }
.tabs-departures__key { width: 36px; color: light-dark(#5f626a, #a7abb2); font-size: 9px; letter-spacing: 0.12em; }
.tabs-departures__cell {
position: relative;
display: grid;
place-items: center;
width: 22px;
height: 26px;
border-radius: 3px;
background: linear-gradient(light-dark(#ebedf0, #232529) 0 49%, light-dark(#fbfcfd, #121417) 49% 51%, light-dark(#ebedf0, #232529) 51%);
color: light-dark(#373a40, #f1f2f3);
font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
transform-origin: 50% 50%;
}
.tabs-departures[data-armed] .tabs-departures__cell { animation: tabs-departures-flap 0.38s cubic-bezier(0.3, 0, 0.4, 1.3) backwards; animation-delay: calc(var(--k) * 45ms); }
.tabs-departures__note { margin-top: 2px; color: light-dark(#50535b, #c6c8cd); font-size: 11.5px; }
@media (prefers-reduced-motion: reduce) {
.tabs-departures__cell { animation: none !important; }
}
`;
export function DeparturesTabs() {
const id = useId();
const [state, setState] = useState({ sel: 0, prev: -1, flip: 0 });
const tabs = useRef<(HTMLButtonElement | null)[]>([]);
const { sel, prev, flip } = state;
const select = (i: number) => {
if (i !== sel) setState((s) => ({ sel: i, prev: s.sel, flip: s.flip + 1 }));
};
const onKeyDown = (e: React.KeyboardEvent) => {
const n = ITEMS.length;
const next = ({ ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 } as Record<string, number>)[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs.current[next]?.focus();
};
return (
<>
<style>
{css}
</style>
<div
className="tabs-departures"
data-armed={flip ? '' : undefined}
data-flip={flip ? (flip % 2 ? 'a' : 'b') : undefined}
style={{ '--i': sel, '--p': prev < 0 ? sel : prev } as React.CSSProperties}
>
<div className="tabs-departures__list" role="tablist" aria-label="Destinations" onKeyDown={onKeyDown}>
{ITEMS.map((t, i) => (
<button
key={t.label}
ref={(el) => {
tabs.current[i] = el;
}}
className="tabs-departures__tab"
type="button"
role="tab"
id={`${id}-tab-${i}`}
aria-selected={sel === i}
aria-controls={`${id}-panel-${i}`}
tabIndex={sel === i ? 0 : -1}
onClick={() => select(i)}
>
{t.label}
</button>
))}
</div>
{ITEMS.map((t, i) => (
<div key={t.label} className="tabs-departures__panel" role="tabpanel" id={`${id}-panel-${i}`} aria-labelledby={`${id}-tab-${i}`} hidden={sel !== i}>
{(
[
['DEST', t.dest],
['TIME', t.time],
['GATE', t.gate],
] as const
).map(([k, val], r) => (
<div key={k} className="tabs-departures__row" aria-hidden="true">
<span className="tabs-departures__key">{k}</span>
{cells(val).map((c, j) => (
<span key={j} className="tabs-departures__cell" style={{ '--k': r * W + j } as React.CSSProperties}>
{c}
</span>
))}
</div>
))}
<span className="tabs-departures__note">
{t.dest[0]}{t.dest.slice(1).toLowerCase()}, {t.time}, gate {t.gate}. {t.note}.
</span>
</div>
))}
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initTabsDepartures(el) on the mounted element instead.
<div class="tabs-departures" style="--i:0;--p:0">
<div class="tabs-departures__list" role="tablist" aria-label="Destinations">
<button class="tabs-departures__tab" type="button" role="tab" id="tabs-departures-tab-0" aria-selected="true" aria-controls="tabs-departures-panel-0" tabindex="0">Lisbon</button>
<button class="tabs-departures__tab" type="button" role="tab" id="tabs-departures-tab-1" aria-selected="false" aria-controls="tabs-departures-panel-1" tabindex="-1">Kyoto</button>
<button class="tabs-departures__tab" type="button" role="tab" id="tabs-departures-tab-2" aria-selected="false" aria-controls="tabs-departures-panel-2" tabindex="-1">Oslo</button>
</div>
<div class="tabs-departures__panel" role="tabpanel" id="tabs-departures-panel-0" aria-labelledby="tabs-departures-tab-0">
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">DEST</span>
<span class="tabs-departures__cell" style="--k:0">L</span>
<span class="tabs-departures__cell" style="--k:1">I</span>
<span class="tabs-departures__cell" style="--k:2">S</span>
<span class="tabs-departures__cell" style="--k:3">B</span>
<span class="tabs-departures__cell" style="--k:4">O</span>
<span class="tabs-departures__cell" style="--k:5">N</span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">TIME</span>
<span class="tabs-departures__cell" style="--k:6">0</span>
<span class="tabs-departures__cell" style="--k:7">9</span>
<span class="tabs-departures__cell" style="--k:8">:</span>
<span class="tabs-departures__cell" style="--k:9">4</span>
<span class="tabs-departures__cell" style="--k:10">0</span>
<span class="tabs-departures__cell" style="--k:11"> </span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">GATE</span>
<span class="tabs-departures__cell" style="--k:12">B</span>
<span class="tabs-departures__cell" style="--k:13">1</span>
<span class="tabs-departures__cell" style="--k:14">2</span>
<span class="tabs-departures__cell" style="--k:15"> </span>
<span class="tabs-departures__cell" style="--k:16"> </span>
<span class="tabs-departures__cell" style="--k:17"> </span>
</div>
<span class="tabs-departures__note">Lisbon, 09:40, gate B12. Boarding.</span>
</div>
<div class="tabs-departures__panel" role="tabpanel" id="tabs-departures-panel-1" aria-labelledby="tabs-departures-tab-1" hidden="">
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">DEST</span>
<span class="tabs-departures__cell" style="--k:0">K</span>
<span class="tabs-departures__cell" style="--k:1">Y</span>
<span class="tabs-departures__cell" style="--k:2">O</span>
<span class="tabs-departures__cell" style="--k:3">T</span>
<span class="tabs-departures__cell" style="--k:4">O</span>
<span class="tabs-departures__cell" style="--k:5"> </span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">TIME</span>
<span class="tabs-departures__cell" style="--k:6">1</span>
<span class="tabs-departures__cell" style="--k:7">1</span>
<span class="tabs-departures__cell" style="--k:8">:</span>
<span class="tabs-departures__cell" style="--k:9">1</span>
<span class="tabs-departures__cell" style="--k:10">5</span>
<span class="tabs-departures__cell" style="--k:11"> </span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">GATE</span>
<span class="tabs-departures__cell" style="--k:12">C</span>
<span class="tabs-departures__cell" style="--k:13">0</span>
<span class="tabs-departures__cell" style="--k:14">4</span>
<span class="tabs-departures__cell" style="--k:15"> </span>
<span class="tabs-departures__cell" style="--k:16"> </span>
<span class="tabs-departures__cell" style="--k:17"> </span>
</div>
<span class="tabs-departures__note">Kyoto, 11:15, gate C04. On time.</span>
</div>
<div class="tabs-departures__panel" role="tabpanel" id="tabs-departures-panel-2" aria-labelledby="tabs-departures-tab-2" hidden="">
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">DEST</span>
<span class="tabs-departures__cell" style="--k:0">O</span>
<span class="tabs-departures__cell" style="--k:1">S</span>
<span class="tabs-departures__cell" style="--k:2">L</span>
<span class="tabs-departures__cell" style="--k:3">O</span>
<span class="tabs-departures__cell" style="--k:4"> </span>
<span class="tabs-departures__cell" style="--k:5"> </span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">TIME</span>
<span class="tabs-departures__cell" style="--k:6">1</span>
<span class="tabs-departures__cell" style="--k:7">3</span>
<span class="tabs-departures__cell" style="--k:8">:</span>
<span class="tabs-departures__cell" style="--k:9">0</span>
<span class="tabs-departures__cell" style="--k:10">5</span>
<span class="tabs-departures__cell" style="--k:11"> </span>
</div>
<div class="tabs-departures__row" aria-hidden="true">
<span class="tabs-departures__key">GATE</span>
<span class="tabs-departures__cell" style="--k:12">A</span>
<span class="tabs-departures__cell" style="--k:13">2</span>
<span class="tabs-departures__cell" style="--k:14">1</span>
<span class="tabs-departures__cell" style="--k:15"> </span>
<span class="tabs-departures__cell" style="--k:16"> </span>
<span class="tabs-departures__cell" style="--k:17"> </span>
</div>
<span class="tabs-departures__note">Oslo, 13:05, gate A21. Delayed 10 min.</span>
</div>
</div>/* A cell flaps down from the top half: hinged at the middle, a beat after the cell to its left. */
@keyframes tabs-departures-flap { 0% { transform: rotateX(-90deg); filter: brightness(1.6); } 70% { transform: rotateX(8deg); } 100% { transform: none; } }
.tabs-departures { display: grid; gap: 12px; width: 260px; }
.tabs-departures__list { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.tabs-departures__tab { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.tabs-departures__tab:focus-visible { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; border-radius: 8px; }
.tabs-departures__tab { flex: 1; padding: 6px 0; border-radius: 7px; color: light-dark(#5f626a, #a7abb2); font-size: 12.5px; font-weight: 500; transition: background-color 0.2s, color 0.2s; }
.tabs-departures__tab[aria-selected='true'] { background: light-dark(#373a40, #f1f2f3); color: light-dark(#fbfcfd, #121417); }
.tabs-departures__panel { display: grid; gap: 6px; padding: 12px; border-radius: 10px; background: light-dark(#fbfcfd, #121417); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
.tabs-departures__row { display: flex; align-items: center; gap: 2px; perspective: 200px; }
.tabs-departures__key { width: 36px; color: light-dark(#5f626a, #a7abb2); font-size: 9px; letter-spacing: 0.12em; }
.tabs-departures__cell {
position: relative;
display: grid;
place-items: center;
width: 22px;
height: 26px;
border-radius: 3px;
background: linear-gradient(light-dark(#ebedf0, #232529) 0 49%, light-dark(#fbfcfd, #121417) 49% 51%, light-dark(#ebedf0, #232529) 51%);
color: light-dark(#373a40, #f1f2f3);
font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
transform-origin: 50% 50%;
}
.tabs-departures[data-armed] .tabs-departures__cell { animation: tabs-departures-flap 0.38s cubic-bezier(0.3, 0, 0.4, 1.3) backwards; animation-delay: calc(var(--k) * 45ms); }
.tabs-departures__note { margin-top: 2px; color: light-dark(#50535b, #c6c8cd); font-size: 11.5px; }
@media (prefers-reduced-motion: reduce) {
.tabs-departures__cell { animation: none !important; }
}function initTabsDepartures(root) {
var list = root.querySelector('[role="tablist"]');
var tabs = Array.prototype.slice.call(list.querySelectorAll('[role="tab"]'));
var panels = root.querySelectorAll('[role="tabpanel"]');
var sel = tabs.findIndex(function (tab) { return tab.getAttribute('aria-selected') === 'true'; });
var flip = 0;
function select(i) {
if (i === sel) return;
var prev = sel;
sel = i;
// Armed on the first change, so nothing animates on load; each change flips data-flip
// between a and b, so the keyframes restart every time.
flip += 1;
root.setAttribute('data-armed', '');
root.setAttribute('data-flip', flip % 2 ? 'a' : 'b');
root.style.setProperty('--i', i);
root.style.setProperty('--p', prev);
tabs.forEach(function (tab, k) {
tab.setAttribute('aria-selected', String(k === i));
tab.tabIndex = k === i ? 0 : -1;
});
panels.forEach(function (panel, k) { panel.hidden = k !== i; });
}
function onClick(e) {
var tab = e.target.closest('[role="tab"]');
if (tab) select(tabs.indexOf(tab));
}
function onKeyDown(e) {
var n = tabs.length;
var next = { ArrowRight: (sel + 1) % n, ArrowLeft: (sel + n - 1) % n, Home: 0, End: n - 1 }[e.key];
if (next === undefined) return;
e.preventDefault();
select(next);
tabs[next].focus();
}
list.addEventListener('click', onClick);
list.addEventListener('keydown', onKeyDown);
return function () {
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKeyDown);
};
}
document.querySelectorAll('.tabs-departures').forEach(initTabsDepartures);Goal: Create a "Departures" tab set.
Visual behavior: Destination tabs on a split-flap board: pick a city and every letter of the destination, time and gate flaps over to the new one, cell by cell from left to right.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- Each row is six character cells inside a perspective; each cell flaps down from rotateX(-90deg) with a brief brightness flash, delayed by its index (--k) so the board settles left to right and row by row.
- The visual board is aria-hidden and a plain sentence under it carries the same information for screen readers.
- A data-armed attribute is set on the first change, so nothing plays on page load; a panel that is shown again restarts its entrance because it comes back from display: none.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the letters change without flapping.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Departures" tab set.
Visual behavior: Destination tabs on a split-flap board: pick a city and every letter of the destination, time and gate flaps over to the new one, cell by cell from left to right.
Technique:
- The ARIA tabs pattern: a role="tablist" with an aria-label, buttons with role="tab", aria-selected and aria-controls, and role="tabpanel" panels labelled by their tab. Only the selected tab is in the Tab order (roving tabindex); the arrow keys, Home and End move between tabs and select as they go.
- Each row is six character cells inside a perspective; each cell flaps down from rotateX(-90deg) with a brief brightness flash, delayed by its index (--k) so the board settles left to right and row by row.
- The visual board is aria-hidden and a plain sentence under it carries the same information for screen readers.
- A data-armed attribute is set on the first change, so nothing plays on page load; a panel that is shown again restarts its entrance because it comes back from display: none.
Accessibility: Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the letters change without flapping.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Destination tabs on a split-flap board: pick a city and every letter of the destination, time and gate flaps over to the new one, cell by cell from left to right.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, 3d, delay stagger
- Techniques
- keyframes, 3d transform, perspective, stagger
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
Real ARIA tabs: arrow keys, Home and End move between tabs, only the selected tab is in the Tab order, and each panel is labelled by its tab. Decoration is aria-hidden. Under prefers-reduced-motion the letters change without flapping.