import {MouseEventHandler, useEffect} from 'react'; import cx from 'classnames'; import {__} from '@wordpress/i18n'; import {ExitIcon, CheckCircle, AlertTriangle} from '@givewp/components/AdminUI/Icons'; import styles from './style.module.scss'; export interface ToastProps { children: string | JSX.Element | JSX.Element[]; handleClose: MouseEventHandler; type?: 'info' | 'error' | 'warning' | 'success'; show?: boolean; position?: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left'; autoClose?: number; showCloseIcon?: boolean; } export default function Toast({children, type, handleClose, position = 'top-right', show = true, autoClose = 0, showCloseIcon = true}: ToastProps) { const getIcon = type => { switch (type) { case 'info': return <> case 'error': return <> case 'warning': return case 'success': return } return null; } useEffect(() => { if(autoClose) { setTimeout(handleClose, autoClose) } }, []); if (!show) return null; return (
{type && (
{getIcon(type)}
)}
{children}
{showCloseIcon && handleClose && (
)}
) }