import classNames from 'classnames' import { ReactNode, useEffect, useRef } from 'react' import Button from 'components/Button' import Card from 'components/Card' import { Cross } from 'components/Icons' interface Props { header: string | ReactNode headerClassName?: string children?: ReactNode | string content?: ReactNode | string className?: string contentClassName?: string open: boolean onClose: () => void } export default function Modal(props: Props) { const ref: any = useRef(null) function onClose() { ref.current?.close() props.onClose() } useEffect(() => { if (props.open) { ref.current?.showModal() } else { ref.current?.close() } }, [props.open]) // close dialog on unmount useEffect(() => { const dialog = ref.current dialog?.removeAttribute('open') return () => dialog.close() }, []) return (
{props.header}
{props.children ? props.children : props.content}
) }