import React, { useMemo } from 'react'; import * as ToastPrimitive from '@radix-ui/react-toast'; import { ToastProps } from '@radix-ui/react-toast'; import { motion } from 'framer-motion'; import { simpleToastTheme, type SimpleToastTheme } from './SimpleToast.theme'; import { LoadingIcon, CheckRoundFilledIcon, CrossIcon, InfoRoundFilledIcon, WarningIcon, } from 'components/shared/CustomIcon'; import { Button, type ButtonOrLinkProps } from 'components/shared/Button'; import { cloneIcon } from 'utils/cloneIcon'; type CtaProps = ButtonOrLinkProps & { buttonLabel: string; }; export interface SimpleToastProps extends ToastProps { id: string; title: string; variant?: SimpleToastTheme['variant']; cta?: CtaProps[]; onDismiss: (toastId: string) => void; } export const SimpleToast = ({ id, className, title, variant = 'success', cta = [], onDismiss, ...props }: SimpleToastProps) => { const hasCta = cta.length > 0; const { wrapper: wrapperCls, icon: iconCls, closeIcon: closeIconCls, title: titleCls, } = simpleToastTheme({ variant }); const Icon = useMemo(() => { if (variant === 'success') return ; if (variant === 'error') return ; if (variant === 'warning') return ; if (variant === 'info') return ; return ; // variant === 'loading' }, [variant]); const renderCta = useMemo(() => { if (!hasCta) return null; return (
{cta.map(({ buttonLabel, ...props }, index) => ( ))}
); }, [cta]); const renderCloseButton = useMemo( () => (
onDismiss(id)} className={closeIconCls()}>
), [id], ); return ( {cloneIcon(Icon, { className: iconCls() })}

{title}

{renderCta} {renderCloseButton}
); };