import * as React from "react"; import { motion, AnimatePresence, type Transition } from "framer-motion"; import { CodeBlock } from "./code-block"; const OVERLAY_INITIAL = { opacity: 0 }; const OVERLAY_ANIMATE = { opacity: 1 }; const OVERLAY_EXIT = { opacity: 0 }; const OVERLAY_TRANSITION: Transition = { duration: 0.2 }; const PANEL_INITIAL = { opacity: 0, scale: 0.95 }; const PANEL_ANIMATE = { opacity: 1, scale: 1 }; const PANEL_EXIT = { opacity: 0, scale: 0.95 }; const PANEL_TRANSITION: Transition = { duration: 0.2, ease: "easeOut" }; interface CommandDialogProps { trigger: React.ReactNode; title: string; description?: string; command: string; footnote?: React.ReactNode; } export function CommandDialog({ trigger, title, description, command, footnote, }: CommandDialogProps) { const [open, setOpen] = React.useState(false); const ref = React.useRef(null); React.useEffect(() => { function handleClickOutside(e: MouseEvent) { if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); } } function handleKeyDown(e: KeyboardEvent) { if (e.key === "Escape") setOpen(false); } document.addEventListener("mousedown", handleClickOutside); document.addEventListener("keydown", handleKeyDown); return () => { document.removeEventListener("mousedown", handleClickOutside); document.removeEventListener("keydown", handleKeyDown); }; }, []); const handleToggle = React.useCallback(() => setOpen((prev) => !prev), []); const handleClose = React.useCallback(() => setOpen(false), []); return (
{open && ( <>

{title}

{description &&

{description}

}
{command} {footnote &&

{footnote}

}
)}
); }