introducing reusable modal component

This commit is contained in:
Antoine M 2024-02-13 19:24:31 +01:00
parent 8b90c37ba7
commit 12fb2589ec
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,14 @@
dialog {
&::backdrop {
backdrop-filter: blur(6px) brightness(0.2);
}
width: clamp(50%, 900px, 90%);
}
.game-modal {
&__close-button {
@apply absolute top-2 right-2 bg-construction p-4 border-none;
}
overflow: visible;
}

View File

@ -0,0 +1,22 @@
import React from "react";
import { useCallback, useEffect, useMemo, useRef } from "react";
export default function Modal({ open, onClose, children, className }) {
const modalRef = useRef(null);
useEffect(() => {
const { current: el } = modalRef;
el.showModal();
}, []);
useEffect(() => {
const { current: el } = modalRef;
if (open) el.showModal();
}, [open]);
return (
<dialog className={className} ref={modalRef} onClose={onClose}>
{children}
</dialog>
);
}