From 3d4b740e5a512db8fbdd934af2fbc9585fa00f0f Mon Sep 17 00:00:00 2001 From: polwex Date: Thu, 15 May 2025 18:47:59 +0700 Subject: thanks gemini, very pretty --- src/pages/test/client-modal.tsx | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/pages/test/client-modal.tsx (limited to 'src/pages/test/client-modal.tsx') diff --git a/src/pages/test/client-modal.tsx b/src/pages/test/client-modal.tsx new file mode 100644 index 0000000..293e28c --- /dev/null +++ b/src/pages/test/client-modal.tsx @@ -0,0 +1,59 @@ +"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, + title = "Modal", +}: 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 + > +
+

{title}

+ +
+
+ {children} {/* Server Component content will be rendered here */} +
+
+
+ ); +} -- cgit v1.2.3