"use client" import * as React from "react" import * as SheetPrimitive from "@radix-ui/react-dialog" import { atom, useAtom } from "jotai" import { Sheet, SheetPortal, SheetOverlay, SheetTitle, sheetVariants, SheetDescription } from "@/components/ui/sheet" import { LaIcon } from "../la-icon" import { cn } from "@/lib/utils" import { buttonVariants } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { useKeyboardManager } from "@/hooks/use-keyboard-manager" export const showShortcutAtom = atom(false) type ShortcutItem = { label: string keys: string[] then?: string[] } type ShortcutSection = { title: string shortcuts: ShortcutItem[] } const SHORTCUTS: ShortcutSection[] = [ { title: "General", shortcuts: [ { label: "Open command menu", keys: ["⌘", "k"] }, { label: "Log out", keys: ["⌥", "⇧", "q"] } ] }, { title: "Navigation", shortcuts: [ { label: "Go to link", keys: ["G"], then: ["L"] }, { label: "Go to page", keys: ["G"], then: ["P"] }, { label: "Go to topic", keys: ["G"], then: ["T"] } ] }, { title: "Links", shortcuts: [{ label: "Create new link", keys: ["c"] }] }, { title: "Pages", shortcuts: [{ label: "Create new page", keys: ["p"] }] } ] const ShortcutKey: React.FC<{ keyChar: string }> = ({ keyChar }) => ( ) const ShortcutItem: React.FC = ({ label, keys, then }) => (
{label}
{keys.map((key, index) => ( ))} {then && ( <> then {then.map((key, index) => ( ))} )}
) const ShortcutSection: React.FC = ({ title, shortcuts }) => (

{title}

{shortcuts.map((shortcut, index) => ( ))}
) export function Shortcut() { const [showShortcut, setShowShortcut] = useAtom(showShortcutAtom) const [searchQuery, setSearchQuery] = React.useState("") const { disableKeydown } = useKeyboardManager("shortcutSection") React.useEffect(() => { disableKeydown(showShortcut) }, [showShortcut, disableKeydown]) const filteredShortcuts = React.useMemo(() => { if (!searchQuery) return SHORTCUTS return SHORTCUTS.map(section => ({ ...section, shortcuts: section.shortcuts.filter(shortcut => shortcut.label.toLowerCase().includes(searchQuery.toLowerCase())) })).filter(section => section.shortcuts.length > 0) }, [searchQuery]) return (
Keyboard Shortcuts Quickly navigate around the app
Close
setSearchQuery(e.target.value)} />
{filteredShortcuts.map((section, index) => ( ))}
) }