lightswind
Version:
A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.
20 lines (19 loc) • 1.45 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useToast } from "../../hooks/use-toast";
import { Toast, ToastDescription, ToastProvider, ToastTitle, ToastViewport, } from "./toast";
import { AnimatePresence } from "framer-motion";
export function Toaster({ position = "top-right" }) {
const { toasts, dismiss } = useToast();
return (_jsx(ToastProvider, { children: _jsx(ToastViewport, { position: position, children: _jsx(AnimatePresence, { mode: "popLayout", children: toasts.map(({ id, title, description, action, type, variant, duration, ...props }) => {
// Map toast type to variant if variant is not provided
const toastVariant = variant || (type === "success" ? "success" :
type === "warning" ? "warning" :
type === "info" ? "info" :
type === "destructive" ? "destructive" :
"default");
return (_jsxs(Toast, { ...props, variant: toastVariant, duration: duration, onOpenChange: (open) => {
if (!open)
dismiss(id);
}, children: [_jsxs("div", { className: "grid gap-1", children: [title && _jsx(ToastTitle, { children: title }), description && _jsx(ToastDescription, { children: description })] }), action] }, id));
}) }) }) }));
}