import alertCircleIcon from '@tabler/icons/outline/alert-circle.svg'; import circleCheckIcon from '@tabler/icons/outline/circle-check.svg'; import infoCircleIcon from '@tabler/icons/outline/info-circle.svg'; import xIcon from '@tabler/icons/outline/x.svg'; import clsx from 'clsx'; 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.tsx'; import HStack from './hstack.tsx'; import Icon from './icon.tsx'; import Stack from './stack.tsx'; import Text from './text.tsx'; 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; summary?: string; } /** * Customizable Toasts for in-app notifications. */ const Toast = (props: IToast) => { const { t, message, type, action, actionLink, actionLabel, summary } = 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 */}
{summary ? ( {summary} ) : null}
); }; export default Toast;