blob: 4c52caa0cdc8461a0d32c01b20d255aeecfe1600 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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>
);
}
|