import classNames from 'classnames' import { ReactNode, useEffect, useRef } from 'react' import EscButton from 'components/Button/EscButton' import Card from 'components/Card' import useStore from 'store' interface Props { header: string | ReactNode headerClassName?: string hideCloseBtn?: boolean children?: ReactNode | string content?: ReactNode | string className?: string contentClassName?: string modalClassName?: string onClose: () => void hideTxLoader?: boolean dialogId?: string } export default function Modal(props: Props) { const ref: React.RefObject = useRef(null) const modalClassName = props.modalClassName ?? 'max-w-modal' function onClose() { ref.current?.close() props.onClose() } useEffect(() => { ref.current?.showModal() document.body.classList.add('h-screen', 'overflow-hidden') }, []) // close dialog on unmount useEffect(() => { const dialog = ref.current return () => { dialog?.removeAttribute('open') dialog?.close() document.body.classList.remove('h-screen', 'overflow-hidden') } }, []) return (
{props.header} {!props.hideCloseBtn && }
{props.children ? props.children : props.content}
) }