import { chordKeys, chordLabel, type Chord, type ChordPlatform } from "../../lib/actions/chords"; import { cn } from "../../lib/utils"; /** * A chord as small keycaps: ⌘ ⇧ O on Mac, Ctrl Shift O elsewhere. Screen * readers hear the whole chord once ("⌘⇧O") instead of each cap. */ export function Keycaps(props: { chord: Chord; platform: ChordPlatform; /** Shows this on the last cap instead of the chord's key, e.g. "1–9" for a range. */ keyLabel?: string | undefined; /** What screen readers hear instead of the chord's own label. */ ariaLabel?: string | undefined; className?: string | undefined; }) { const keys = chordKeys(props.chord, props.platform); if (props.keyLabel) keys[keys.length - 1] = props.keyLabel; return ( // role="img" makes the label count: browsers and screen readers ignore // aria-label on a plain span, and the caps themselves are hidden. {keys.map((key) => ( ))} ); } /** A tooltip's text with its key after it, quieter: "Search sessions ⌘K". */ export function TooltipWithKeys(props: { label: string; shortcut: { label: string } | null | undefined; }) { if (!props.shortcut) return <>{props.label}; return ( {props.label} {props.shortcut.label} ); }