Compare commits

...

1 Commits

Author SHA1 Message Date
Krzysztof Czerwinski
ee3e529964 Dismissable toast 2025-05-19 17:03:00 +02:00
2 changed files with 8 additions and 3 deletions

View File

@@ -13,9 +13,13 @@ import { useToast } from "@/components/ui/use-toast";
export function Toaster() { export function Toaster() {
const { toasts } = useToast(); const { toasts } = useToast();
const swipeThreshold = toasts.some((toast) => toast.dismissable === false)
? Infinity
: undefined;
return ( return (
<ToastProvider> <ToastProvider swipeThreshold={swipeThreshold}>
{toasts.map(function ({ id, title, description, action, ...props }) { {toasts.map(function ({ id, title, description, action, dismissable, ...props }) {
return ( return (
<Toast key={id} {...props}> <Toast key={id} {...props}>
<div className="grid gap-1"> <div className="grid gap-1">
@@ -25,7 +29,7 @@ export function Toaster() {
)} )}
</div> </div>
{action} {action}
<ToastClose /> {dismissable !== false && <ToastClose />}
</Toast> </Toast>
); );
})} })}

View File

@@ -13,6 +13,7 @@ type ToasterToast = ToastProps & {
title?: React.ReactNode; title?: React.ReactNode;
description?: React.ReactNode; description?: React.ReactNode;
action?: ToastActionElement; action?: ToastActionElement;
dismissable?: boolean;
}; };
const actionTypes = { const actionTypes = {