import { Fragment, useRef, type KeyboardEvent } from 'react'; import '../../../styles/studio-panels.css'; import { rovingTarget } from '../studioRoving'; import { RAIL_IDS, RAIL_SECTIONS, type RailSection } from './railSections'; /** * The rail down the side of Studio: one tab per section, each an icon over its * name. * * A list of tabs to a screen reader and to the keyboard, as it is to the eye: * Tab reaches the open section, the arrows move up and down the rail, Home and * End jump to its ends, and Enter or Space opens a section (studioRoving.ts). * A name longer than the rail is wide wraps onto a second line, only ever * between words: where one word alone is wider, the rail grows to fit it * (studio.css) instead of cutting it. The title carries the name whole. */ export function StudioRail({ section, onSection, t, }: { section: RailSection; onSection: (id: RailSection) => void; t: (k: string) => string; }) { const tabs = useRef<(HTMLButtonElement | null)[]>([]); const onKeyDown = (e: KeyboardEvent, index: number) => { const next = rovingTarget(e.key, index, RAIL_SECTIONS.length, { vertical: true, rtl: false }); if (next === null) return; e.preventDefault(); tabs.current[next]?.focus(); }; return (
{RAIL_SECTIONS.map((entry, i) => { const on = entry.id === section; const label = t(entry.labelKey); const Icon = entry.icon; return ( {entry.startsGroup && } ); })}
); }