From c8c67006afe5770f3b170448cebcb0a3c1720d17 Mon Sep 17 00:00:00 2001 From: icarus Date: Sat, 13 Dec 2025 00:55:20 +0800 Subject: [PATCH] feat(sonner): add dismiss method to toast API Add the ability to dismiss specific toast notifications by their ID. This provides more control over toast management in the UI. --- packages/ui/src/components/primitives/sonner.d.ts | 9 +++++++++ packages/ui/src/components/primitives/sonner.tsx | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/packages/ui/src/components/primitives/sonner.d.ts b/packages/ui/src/components/primitives/sonner.d.ts index 3026be7915..1be1a8880c 100644 --- a/packages/ui/src/components/primitives/sonner.d.ts +++ b/packages/ui/src/components/primitives/sonner.d.ts @@ -140,6 +140,15 @@ interface toast { * }) */ loading: (props: QuickLoadingProps) => void + + /** + * Dismiss a toast notification by its ID + * @param id - The ID of the toast to dismiss + * @example + * const toastId = toast.info({ title: 'Info' }) + * toast.dismiss(toastId) + */ + dismiss: (id: string | number) => void } // Export types for external use diff --git a/packages/ui/src/components/primitives/sonner.tsx b/packages/ui/src/components/primitives/sonner.tsx index c85b87ac40..14f2a32af5 100644 --- a/packages/ui/src/components/primitives/sonner.tsx +++ b/packages/ui/src/components/primitives/sonner.tsx @@ -345,6 +345,10 @@ toast.loading = (props: QuickLoadingProps) => { }) } +toast.dismiss = (id: ToastProps['id']) => { + sonnerToast.dismiss(id) +} + const toastColorVariants = cva(undefined, { variants: { type: {