'use client'; import React, { useEffect, useRef, useState, type ReactNode } from 'react'; import { toast as sonnerToast } from 'sonner'; import { CheckCircleFillIcon, WarningIcon } from './icons'; import { cn } from '@/lib/utils'; const iconsByType: Record<'success' | 'error', ReactNode> = { success: , error: , }; export function toast(props: Omit) { return sonnerToast.custom((id) => ( )); } function Toast(props: ToastProps) { const { id, type, description } = props; const descriptionRef = useRef(null); const [multiLine, setMultiLine] = useState(false); useEffect(() => { const el = descriptionRef.current; if (!el) return; const update = () => { const lineHeight = Number.parseFloat(getComputedStyle(el).lineHeight); const lines = Math.round(el.scrollHeight / lineHeight); setMultiLine(lines > 1); }; update(); // initial check const ro = new ResizeObserver(update); // re-check on width changes ro.observe(el); return () => ro.disconnect(); }, [description]); return (
{iconsByType[type]}
{description}
); } interface ToastProps { id: string | number; type: 'success' | 'error'; description: string; }