import { useEffect } from 'react'; import { createPortal } from 'react-dom'; import { CircleCheckIcon, XIcon } from 'lucide-react'; import { getPortalContainer } from '../../lib/portal'; const SHOWN_MS = 6000; /** * One line of confirmation at the bottom of the screen, gone by itself a * few seconds later. The editors have no toaster of their own (the block * editor's snackbar is not on the classic screens) and the app's would cost * every post edit screen forty kilobytes for one message, so this is the * whole of it, rendered in the portal the dialogs use. */ export const Toast = ({ message, onDone, }: { message: string | null; onDone: () => void; }): JSX.Element | null => { useEffect(() => { if (message === null) return undefined; const timer = window.setTimeout(onDone, SHOWN_MS); return () => window.clearTimeout(timer); }, [message, onDone]); if (message === null) return null; return createPortal(
{message}
, getPortalContainer() ); };