introducing reusable modal component
This commit is contained in:
parent
8b90c37ba7
commit
12fb2589ec
14
src/assets/css/components/Modal.scss
Normal file
14
src/assets/css/components/Modal.scss
Normal 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;
|
||||||
|
}
|
||||||
22
src/components/ui/Modal.jsx
Normal file
22
src/components/ui/Modal.jsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user