"use client" import * as React from "react" import { Toast as ToastPrimitive } from "@base-ui/react/toast" import { XIcon } from "lucide-react" import { cn } from "@/lib/utils" export const toastManager = ToastPrimitive.createToastManager() type ToastType = "default" | "success" | "error" | "warning" | "info" interface ToastData { type?: ToastType } function ToastList() { const { toasts } = ToastPrimitive.useToastManager() return ( {toasts.map((toast) => (
{toast.title && ( {toast.title} )} {toast.description && ( {toast.description} )}
Dismiss
{toast.actionProps && ( )}
))}
) } function Toaster() { return ( ) } function toast(options: { title?: string description?: string type?: ToastType timeout?: number actionLabel?: string onAction?: () => void }) { toastManager.add({ title: options.title, description: options.description, timeout: options.timeout ?? 4000, data: { type: options.type ?? "default" }, ...(options.actionLabel && { actionProps: { children: options.actionLabel, onClick: options.onAction, }, }), }) } toast.success = (title: string, description?: string) => toast({ title, description, type: "success" }) toast.error = (title: string, description?: string) => toast({ title, description, type: "error" }) toast.warning = (title: string, description?: string) => toast({ title, description, type: "warning" }) toast.info = (title: string, description?: string) => toast({ title, description, type: "info" }) export { Toaster, toast }