import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { Icon } from "@iconify/react"; import SubmitButton from "../submit-button"; interface Props { title: string; description: string; onSubmit: (close: () => void) => void; error?: string; children?: React.ReactNode; } export default function SubmitDialogButton({ title, description, onSubmit, error, children }: Props) { const [isOpen, setIsOpen] = useState(false); const [isVisible, setIsVisible] = useState(false); const submit = () => { onSubmit(close); }; const close = () => { setIsVisible(false); setTimeout(() => { setIsOpen(false); }, 300); }; useEffect(() => { if (isOpen) { // slight delay to trigger animation setTimeout(() => setIsVisible(true), 10); } }, [isOpen]); return ( <> {isOpen && createPortal(
{description}
{children} {error && Error: {error}}