import { useEffect, useState, type ReactNode } from "react"; import { createPortal } from "react-dom"; /** A full-screen study space (a quiz, a flashcard deck) that opens like the Mind Constellation does, and can be * minimised to a small pill in the corner and brought back, keeping its place. Escape minimises. */ export function StudyOverlay({ title, onClose, children }: { title: string; onClose: () => void; children: ReactNode }) { const [minimized, setMinimized] = useState(false); useEffect(() => { if (minimized) return; const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMinimized(true); document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [minimized]); return createPortal( <> {/* Stays mounted while minimised, so the answers given so far are kept */} {minimized && (
)} , document.body, ); }