forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModal.jsx
More file actions
45 lines (38 loc) · 1.03 KB
/
Modal.jsx
File metadata and controls
45 lines (38 loc) · 1.03 KB
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
import React from "react";
const Modal = ({ isOpen, onClose, children }) => {
React.useEffect(() => {
const handleEscKey = (event) => {
if (event.key === "Escape") {
onClose();
}
};
if (isOpen) {
document.addEventListener("keydown", handleEscKey);
document.body.style.overflow = "hidden";
}
return () => {
document.removeEventListener("keydown", handleEscKey);
document.body.style.overflow = "auto";
};
}, [isOpen, onClose]);
if (!isOpen) return null;
const handleBackdropClick = (e) => {
if (e.target === e.currentTarget) {
onClose();
}
};
return (
<div
className="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50"
onClick={handleBackdropClick}
>
<div
className="bg-white dark:bg-gray-900 rounded-lg p-6 min-w-[300px] max-w-[90%] max-h-[90vh] overflow-y-auto shadow-xl"
onClick={(e) => e.stopPropagation()}
>
{children}
</div>
</div>
);
};
export default Modal;