/* eslint-disable react-hooks/exhaustive-deps */ import { AnimatePresence, motion } from "motion/react"; import { usePopupStore } from "../stores/usePopupStore"; import clsx from "clsx"; import Button from "./ui/Button"; import CloseIcon from "./icons/CloseIcon"; import { useEffect, useRef } from "react"; function PopupContainer() { const { position, popup, side, setPopup, setSide } = usePopupStore(); const rootRef = useRef(null); useEffect(() => { if (!rootRef.current || !popup) return; const { bottom, top, left, right } = rootRef.current.getBoundingClientRect(); if (bottom > innerHeight - 32) setSide("top"); else if (top < 32) setSide("bottom"); else if (left < 32) setSide("right"); else if (right > innerWidth - 32) setSide("left"); }, [popup, position, rootRef.current]); return ( {popup && ( = 768 ? { top: position.y, left: position.x } : { bottom: 0, left: 0 } } className={clsx( "fixed md:absolute 2xl:pointer-events-none z-2 2xl:rounded-[1.111vw] 2xl:p-[1.111vw] p-4 md:max-2xl:rounded-2xl rounded-t-2xl bg-white 2xl:w-[17.222vw] md:max-2xl:w-[248px] w-screen shadow-[0_2px_8px_0_rgba(0,0,0,0.15)]", side === "left" && "md:-translate-y-1/2 2xl:-translate-x-[calc(100%+1.25vw)] md:max-2xl:-translate-x-[calc(100%+18px)]", side === "right" && "md:-translate-y-1/2 2xl:translate-x-[1.25vw]", side === "top" && "md:-translate-x-1/2 2xl:-translate-y-[calc(100%+1.25vw)] md:max-2xl:-translate-y-[calc(100%+18px)]", side === "bottom" && "md:-translate-x-1/2 2xl:translate-y-[1.25vw] md:max-2xl:translate-y-[18px]" )} > {popup}
)} ); } export default PopupContainer;