summaryrefslogtreecommitdiff
path: root/src/components/Modal.tsx
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-05-15 20:32:25 +0700
committerpolwex <polwex@sortug.com>2025-05-15 20:32:25 +0700
commitfd86dc15734f3b7126d88f0130897c597100e30a (patch)
tree253890a5f0bde7bc460904ce1743581f53a23d5b /src/components/Modal.tsx
parent3d4b740e5a512db8fbdd934af2fbc9585fa00f0f (diff)
m
Diffstat (limited to 'src/components/Modal.tsx')
-rw-r--r--src/components/Modal.tsx55
1 files changed, 55 insertions, 0 deletions
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>
+ );
+}