From fd86dc15734f3b7126d88f0130897c597100e30a Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 15 May 2025 20:32:25 +0700 Subject: m --- src/components/Modal.tsx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/components/Modal.tsx (limited to 'src/components/Modal.tsx') diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx new file mode 100644 index 0000000..4c52caa --- /dev/null +++ b/src/components/Modal.tsx @@ -0,0 +1,55 @@ +"use client"; + +import { useState, ReactNode, useEffect } from "react"; + +interface ClientModalProps { + isOpen: boolean; + onClose: () => void; + children: ReactNode; // This will receive the Server Component's output + title?: string; +} + +export default function ClientModal({ + isOpen, + onClose, + children, +}: ClientModalProps) { + // Optional: Prevent body scroll when modal is open + useEffect(() => { + if (isOpen) { + document.body.style.overflow = "hidden"; + } else { + document.body.style.overflow = "unset"; + } + return () => { + document.body.style.overflow = "unset"; + }; + }, [isOpen]); + + if (!isOpen) { + return null; + } + + return ( +
+
e.stopPropagation()} // Prevent click from closing modal if clicking inside content + > + +
+ {children} {/* Server Component content will be rendered here */} +
+
+
+ ); +} -- cgit v1.2.3