/* eslint-disable react-hooks/exhaustive-deps */ import { useEffect, useRef } from "react"; import useModalStore from "../stores/useModalStore"; import { AnimatePresence, motion } from "motion/react"; import CloseIcon from "./icons/CloseIcon"; import Button from "./ui/Button"; function ModalContainer() { const { modal, setModal } = useModalStore(); const divRef = useRef(null); const backdropRef = useRef(null); const popoverRef = useRef(null); const containerRef = useRef(null); function handleResize() { if (!popoverRef.current) return; if (divRef.current!.clientHeight > popoverRef.current!.clientHeight) { backdropRef.current!.style.height = `${divRef.current!.clientHeight}px`; } else { backdropRef.current!.style.height = `100%`; } } function handleKeydown(e: KeyboardEvent) { if (e.key !== "Escape") return; setModal(null); } const rootRef = useRef(null); useEffect(() => { window.addEventListener("resize", handleResize); window.addEventListener("keydown", handleKeydown); return () => { window.removeEventListener("resize", handleResize); window.removeEventListener("keydown", handleKeydown); }; }, []); return ( {modal && (
setModal(null)} />
{modal}
)} ); } export default ModalContainer;