/* USAGE: import { toast } from 'sonner'; import { ToastInner } from '@/components/misc/toast-inner'; import { Button } from '@/components/ui/button'; toast.custom( (t) => ( console.log('on Action')} //No Button shown if this is null variant=''default' | 'success' | 'error' | 'info' | 'warning' | 'notification'' buttonText=[No Button shown if this is null] iconName=[Any Icon Name from Lucide in UpperCamelCase or default if null] /> ), { duration: 5000, }, ) } > Show Toast */ 'use client'; import { toast } from 'sonner'; import { X } from 'lucide-react'; import React from 'react'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import * as Icons from 'lucide-react'; interface ToastInnerProps { title: string; description?: string; buttonText?: string; onAction?: () => void; toastId: string | number; variant?: | 'default' | 'success' | 'error' | 'info' | 'warning' | 'notification'; iconName?: keyof typeof Icons; closeOnAction?: boolean; } const variantConfig = { default: { bgColor: 'bg-neutral-150', defaultIcon: 'Info', }, success: { bgColor: 'bg-green-200', defaultIcon: 'CheckCircle', }, error: { bgColor: 'bg-red-200', defaultIcon: 'XCircle', }, info: { bgColor: 'bg-blue-200', defaultIcon: 'Info', }, warning: { bgColor: 'bg-yellow-200', defaultIcon: 'AlertTriangle', }, notification: { bgColor: 'bg-neutral-150', defaultIcon: 'BellRing', }, }; export const ToastInner: React.FC = ({ title, description, buttonText, onAction, toastId, variant = 'default', iconName, closeOnAction = true, }) => { const bgColor = variantConfig[variant].bgColor; // fallback to variant's default icon if iconName is not provided const iconKey = (iconName || variantConfig[variant].defaultIcon) as keyof typeof Icons; const Icon = Icons[iconKey] as React.ComponentType; return ( {/* Close Button */} toast.dismiss(toastId)} className='absolute top-2 right-2 cursor-pointer' aria-label='Close notification' > {variant !== 'default' && ( )} {/* Text Content */} {title} {description && {description}} {/* Action Button */} {onAction && buttonText && ( { onAction(); if (closeOnAction) { toast.dismiss(toastId); } }} > {buttonText} )} ); };