import { useEffect } from "react"; import { useShortcutContext } from "../contexts/ShortcutContext"; import { ShortcutDefinition } from "../hooks/useKeyboardShortcuts"; interface ShortcutItemProps { shortcut: ShortcutDefinition; } function ShortcutItem({ shortcut }: ShortcutItemProps) { const getKeyCombo = () => { const parts: string[] = []; if (shortcut.meta) parts.push("⌘"); if (shortcut.ctrl) parts.push("⌃"); if (shortcut.alt) parts.push("⌥"); if (shortcut.shift) parts.push("⇧"); // Display key nicely let displayKey = shortcut.key; if (displayKey === "Space") displayKey = "␣"; if (displayKey === "ArrowLeft") displayKey = "←"; if (displayKey === "ArrowRight") displayKey = "→"; if (displayKey === "ArrowUp") displayKey = "↑"; if (displayKey === "ArrowDown") displayKey = "↓"; if (displayKey === "Escape") displayKey = "Esc"; parts.push(displayKey); return parts.join(" "); }; return (
{shortcut.description} {getKeyCombo()}
); } function ShortcutHelp() { const { categories, showHelp, setShowHelp } = useShortcutContext(); // Close on Escape useEffect(() => { if (!showHelp) return; const handler = (e: KeyboardEvent) => { if (e.key === "Escape") { setShowHelp(false); } }; window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); }, [showHelp, setShowHelp]); if (!showHelp) return null; return ( <> {/* Backdrop */}
setShowHelp(false)} style={{ position: "fixed", inset: 0, background: "rgba(0, 0, 0, 0.7)", backdropFilter: "blur(8px)", zIndex: 9998, animation: "fadeIn 0.2s ease", }} /> {/* Modal */}
{/* Header */}

Keyboard Shortcuts

{/* Content */}
{categories.length === 0 ? (
No shortcuts available in this view
) : ( categories.map((category) => (

{category.name}

{Object.entries(category.shortcuts).map(([id, shortcut]) => ( ))}
)) )}
); } export default ShortcutHelp;