| 39 | * Single key cap (styled <kbd>) |
| 40 | */ |
| 41 | export const Keycap: React.FC<KeycapProps> = (props) => { |
| 42 | const onMac = isMac(); |
| 43 | let label = props.children; |
| 44 | |
| 45 | // Apply platform-specific mappings first |
| 46 | if (onMac && label in MAC_KEY_MAP) { |
| 47 | label = MAC_KEY_MAP[label]; |
| 48 | } else if (!onMac && label in WIN_KEY_MAP) { |
| 49 | label = WIN_KEY_MAP[label]; |
| 50 | } |
| 51 | |
| 52 | // Apply universal display mappings |
| 53 | if (label in KEY_DISPLAY_MAP) { |
| 54 | label = KEY_DISPLAY_MAP[label]; |
| 55 | } |
| 56 | |
| 57 | // Single letters: uppercase |
| 58 | if (label.length === 1 && /[a-z]/.test(label)) { |
| 59 | label = label.toUpperCase(); |
| 60 | } |
| 61 | |
| 62 | return ( |
| 63 | <kbd |
| 64 | className={cn( |
| 65 | "inline-flex h-5 min-w-5 items-center justify-center rounded border px-1", |
| 66 | "border-border-medium bg-dark text-muted text-[10px] font-medium leading-none", |
| 67 | props.className |
| 68 | )} |
| 69 | > |
| 70 | {label} |
| 71 | </kbd> |
| 72 | ); |
| 73 | }; |
| 74 | |
| 75 | interface KeycapGroupProps { |
| 76 | /** Array of key labels, rendered as a sequence of keycaps */ |