import { useStore } from '@nanostores/preact'; import { $toastMessage } from '../stores/toast'; import { useEffect } from 'preact/hooks'; import { CheckIcon } from './ReactIcons/CheckIcon'; import { ErrorIcon } from './ReactIcons/ErrorIcon'; import { WarningIcon } from './ReactIcons/WarningIcon'; import { InfoIcon } from './ReactIcons/InfoIcon'; import { Spinner } from './ReactIcons/Spinner'; export interface Props {} export function Toaster(props: Props) { const toastMessage = useStore($toastMessage); useEffect(() => { if (toastMessage === undefined) { return; } const removeMessage = setTimeout(() => { if (toastMessage?.type !== 'loading') { $toastMessage.set(undefined); } }, 2500); return () => { clearTimeout(removeMessage); }; }, [toastMessage]); if (!toastMessage) { return null; } return (
{ $toastMessage.set(undefined); }} className={`fixed bottom-5 left-1/2 max-w-[300px] animate-fade-slide-up min-w-[300px] sm:min-w-[auto] z-50`} >
{toastMessage.type === 'success' && ( )} {toastMessage.type === 'error' && ( )} {toastMessage.type === 'warning' && ( )} {toastMessage.type === 'info' && ( )} {toastMessage.type === 'loading' && } {toastMessage.message}
); }