From fd86dc15734f3b7126d88f0130897c597100e30a Mon Sep 17 00:00:00 2001
From: polwex <polwex@sortug.com>
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 (
+    <div
+      className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"
+      onClick={onClose} // Close on overlay click
+    >
+      <div
+        className="p-6 bg-white rounded-lg shadow-xl w-11/12 max-w-lg"
+        onClick={(e) => e.stopPropagation()} // Prevent click from closing modal if clicking inside content
+      >
+        <button
+          onClick={onClose}
+          className="text-gray-500 hover:text-gray-700"
+          aria-label="Close modal"
+        >
+          × {/* A simple 'X' close button */}
+        </button>
+        <div>
+          {children} {/* Server Component content will be rendered here */}
+        </div>
+      </div>
+    </div>
+  );
+}
-- 
cgit v1.2.3

