import classNames from 'clsx'; import React from 'react'; import toast, { Toast as RHToast } from 'react-hot-toast'; import { FormattedMessage } from 'react-intl'; import { Link } from 'react-router-dom'; import { ToastText, ToastType } from 'soapbox/toast'; import HStack from '../hstack/hstack'; import Icon from '../icon/icon'; const renderText = (text: ToastText) => { if (typeof text === 'string') { return text; } else { return ; } }; interface IToast { t: RHToast message: ToastText type: ToastType action?(): void actionLink?: string actionLabel?: ToastText } /** * Customizable Toasts for in-app notifications. */ const Toast = (props: IToast) => { const { t, message, type, action, actionLink, actionLabel } = props; const dismissToast = () => toast.dismiss(t.id); const renderIcon = () => { switch (type) { case 'success': return ( ); case 'info': return ( ); case 'error': return ( ); } }; const renderAction = () => { const classNames = 'mt-0.5 flex-shrink-0 rounded-full text-sm font-medium text-primary-600 dark:text-accent-blue hover:underline focus:outline-none'; if (action && actionLabel) { return ( ); } if (actionLink && actionLabel) { return ( {renderText(actionLabel)} ); } return null; }; return (
{renderIcon()}

{renderText(message)}

{/* Action */} {renderAction()}
{/* Dismiss Button */}
); }; export default Toast;