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.
This commit is contained in:
icarus 2025-12-13 00:55:20 +08:00
parent 8794f2b3ac
commit c8c67006af
No known key found for this signature in database
GPG Key ID: D4AF089AAEC25D18
2 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -345,6 +345,10 @@ toast.loading = (props: QuickLoadingProps) => {
})
}
toast.dismiss = (id: ToastProps['id']) => {
sonnerToast.dismiss(id)
}
const toastColorVariants = cva(undefined, {
variants: {
type: {