1
Fork 0
This repository has been archived on 2024-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
tic-tac-toe/src/modal.jsx

29 lines
610 B
React
Raw Normal View History

2024-06-01 19:22:27 +00:00
import { useEffect, useRef } from "react";
export default ({ isOpen, children, className, onClose }) => {
const ref = useRef(null);
useEffect(() => {
if (isOpen) {
ref.current.showModal();
if (onClose) {
ref.current.addEventListener("close", onClose);
}
} else {
ref.current.close();
}
}, [isOpen]);
return (
<dialog
2024-06-02 17:52:05 +00:00
className="h-64 w-screen max-w-[100vw] bg-navy-700 backdrop:bg-black/50"
2024-06-01 19:22:27 +00:00
ref={ref}
>
2024-06-03 17:11:30 +00:00
<div className="center h-full w-full">
2024-06-01 19:22:27 +00:00
<div className={className}>{children}</div>
</div>
</dialog>
);
};