import { toast as sonnerToast } from 'sonner' import { cn } from '../../utils/cn' import Icon from './Icon' import { ToastAction, ToastClose, ToastCountdown, ToastDescription, ToastRoot, ToastTitle, } from './ToastElements' import { type Variant } from './variants' export type ToastProps = { title?: string description: string variant?: Variant action?: { label: string; onClick: VoidFunction } toastId?: string | number close?: boolean | undefined countdown?: boolean | undefined duration?: number | undefined className?: string | undefined } export const Toast = ({ title, description, variant = 'info', action, toastId, close = true, countdown = true, className, }: ToastProps) => (
{title && {title}} {description}
{action !== undefined && ( action.onClick} > {action.label} )} {close && } {countdown && }
) export function toast(props: ToastProps) { return sonnerToast.custom( (toastId) => , { position: 'top-center', unstyled: true, duration: props.duration ?? 8000, }, ) }