34 lines
1021 B
TypeScript
34 lines
1021 B
TypeScript
"use client";
|
|
|
|
import { useEffect, type ReactNode } from "react";
|
|
|
|
interface ModalProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
title: string;
|
|
children: ReactNode;
|
|
}
|
|
|
|
export function Modal({ open, onClose, title, children }: ModalProps) {
|
|
useEffect(() => {
|
|
if (open) document.body.style.overflow = "hidden";
|
|
else document.body.style.overflow = "";
|
|
return () => { document.body.style.overflow = ""; };
|
|
}, [open]);
|
|
|
|
if (!open) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
|
<div className="absolute inset-0 bg-black/40" onClick={onClose} />
|
|
<div className="relative bg-white rounded-2xl shadow-xl max-w-lg w-full mx-4 p-6">
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h2 className="text-lg font-semibold">{title}</h2>
|
|
<button onClick={onClose} className="text-gray-400 hover:text-gray-600 text-xl leading-none">×</button>
|
|
</div>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|