|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
|
|
import { cn } from "~/lib/utils";
|
|
|
|
|
import { buttonVariants } from "~/components/ui/button";
|
|
|
|
|
import { useStore } from "~/store";
|
|
|
|
|
import { shouldHideCollapsedToastContent } from "./toast.logic";
|
|
|
|
|
|
|
|
|
|
type ThreadToastData = {
|
|
|
|
|
threadId?: string | null;
|
|
|
|
@@ -146,6 +147,9 @@ function Toasts({ position = "top-right" }: { position: ToastPosition }) {
|
|
|
|
|
const { toasts } = Toast.useToastManager<ThreadToastData>();
|
|
|
|
|
const activeThreadId = state.activeThreadId;
|
|
|
|
|
const isTop = position.startsWith("top");
|
|
|
|
|
const visibleToasts = toasts.filter((toast) =>
|
|
|
|
|
shouldRenderForActiveThread(toast.data, activeThreadId),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const activeToastIds = new Set(toasts.map((toast) => toast.id));
|
|
|
|
@@ -172,100 +176,107 @@ function Toasts({ position = "top-right" }: { position: ToastPosition }) {
|
|
|
|
|
data-position={position}
|
|
|
|
|
data-slot="toast-viewport"
|
|
|
|
|
>
|
|
|
|
|
{toasts
|
|
|
|
|
.filter((toast) => shouldRenderForActiveThread(toast.data, activeThreadId))
|
|
|
|
|
.map((toast) => {
|
|
|
|
|
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
|
|
|
|
{visibleToasts.map((toast, visibleIndex) => {
|
|
|
|
|
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
|
|
|
|
const hideCollapsedContent = shouldHideCollapsedToastContent(
|
|
|
|
|
visibleIndex,
|
|
|
|
|
visibleToasts.length,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Toast.Root
|
|
|
|
|
return (
|
|
|
|
|
<Toast.Root
|
|
|
|
|
className={cn(
|
|
|
|
|
"absolute z-[calc(9999-var(--toast-index))] h-(--toast-calc-height) w-full select-none rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 [transition:transform_.5s_cubic-bezier(.22,1,.36,1),opacity_.5s,height_.15s] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
|
|
|
|
// Base positioning using data-position
|
|
|
|
|
"data-[position*=right]:right-0 data-[position*=right]:left-auto",
|
|
|
|
|
"data-[position*=left]:right-auto data-[position*=left]:left-0",
|
|
|
|
|
"data-[position*=center]:right-0 data-[position*=center]:left-0",
|
|
|
|
|
"data-[position*=top]:top-0 data-[position*=top]:bottom-auto data-[position*=top]:origin-top",
|
|
|
|
|
"data-[position*=bottom]:top-auto data-[position*=bottom]:bottom-0 data-[position*=bottom]:origin-bottom",
|
|
|
|
|
// Gap fill for hover
|
|
|
|
|
"after:absolute after:left-0 after:h-[calc(var(--toast-gap)+1px)] after:w-full",
|
|
|
|
|
"data-[position*=top]:after:top-full",
|
|
|
|
|
"data-[position*=bottom]:after:bottom-full",
|
|
|
|
|
// Define some variables
|
|
|
|
|
"[--toast-calc-height:var(--toast-frontmost-height,var(--toast-height))] [--toast-gap:--spacing(3)] [--toast-peek:--spacing(3)] [--toast-scale:calc(max(0,1-(var(--toast-index)*.1)))] [--toast-shrink:calc(1-var(--toast-scale))]",
|
|
|
|
|
// Define offset-y variable
|
|
|
|
|
"data-[position*=top]:[--toast-calc-offset-y:calc(var(--toast-offset-y)+var(--toast-index)*var(--toast-gap)+var(--toast-swipe-movement-y))]",
|
|
|
|
|
"data-[position*=bottom]:[--toast-calc-offset-y:calc(var(--toast-offset-y)*-1+var(--toast-index)*var(--toast-gap)*-1+var(--toast-swipe-movement-y))]",
|
|
|
|
|
// Default state transform
|
|
|
|
|
"data-[position*=top]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)+(var(--toast-index)*var(--toast-peek))+(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
|
|
|
|
"data-[position*=bottom]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--toast-peek))-(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
|
|
|
|
// Limited state
|
|
|
|
|
"data-limited:opacity-0",
|
|
|
|
|
// Expanded state
|
|
|
|
|
"data-expanded:h-(--toast-height)",
|
|
|
|
|
"data-position:data-expanded:transform-[translateX(var(--toast-swipe-movement-x))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
// Starting and ending animations
|
|
|
|
|
"data-[position*=top]:data-starting-style:transform-[translateY(calc(-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-[position*=bottom]:data-starting-style:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
|
|
|
|
"data-[position*=top]:data-[position*=right]:data-starting-style:transform-[translateX(calc(100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:opacity-0",
|
|
|
|
|
// Ending animations (direction-aware)
|
|
|
|
|
"data-ending-style:not-data-limited:not-data-swipe-direction:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
|
|
|
|
"data-[position*=top]:data-[position*=right]:data-ending-style:not-data-limited:not-data-swipe-direction:transform-[translateX(calc(100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
|
|
|
|
// Ending animations (expanded)
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
|
|
|
|
)}
|
|
|
|
|
data-position={position}
|
|
|
|
|
key={toast.id}
|
|
|
|
|
swipeDirection={
|
|
|
|
|
position.includes("center")
|
|
|
|
|
? [isTop ? "up" : "down"]
|
|
|
|
|
: position.includes("left")
|
|
|
|
|
? ["left", isTop ? "up" : "down"]
|
|
|
|
|
: ["right", isTop ? "up" : "down"]
|
|
|
|
|
}
|
|
|
|
|
toast={toast}
|
|
|
|
|
>
|
|
|
|
|
<ThreadToastVisibleAutoDismiss
|
|
|
|
|
dismissAfterVisibleMs={toast.data?.dismissAfterVisibleMs}
|
|
|
|
|
toastId={toast.id}
|
|
|
|
|
/>
|
|
|
|
|
<Toast.Content
|
|
|
|
|
className={cn(
|
|
|
|
|
"absolute z-[calc(9999-var(--toast-index))] h-(--toast-calc-height) w-full select-none rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 [transition:transform_.5s_cubic-bezier(.22,1,.36,1),opacity_.5s,height_.15s] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
|
|
|
|
// Base positioning using data-position
|
|
|
|
|
"data-[position*=right]:right-0 data-[position*=right]:left-auto",
|
|
|
|
|
"data-[position*=left]:right-auto data-[position*=left]:left-0",
|
|
|
|
|
"data-[position*=center]:right-0 data-[position*=center]:left-0",
|
|
|
|
|
"data-[position*=top]:top-0 data-[position*=top]:bottom-auto data-[position*=top]:origin-top",
|
|
|
|
|
"data-[position*=bottom]:top-auto data-[position*=bottom]:bottom-0 data-[position*=bottom]:origin-bottom",
|
|
|
|
|
// Gap fill for hover
|
|
|
|
|
"after:absolute after:left-0 after:h-[calc(var(--toast-gap)+1px)] after:w-full",
|
|
|
|
|
"data-[position*=top]:after:top-full",
|
|
|
|
|
"data-[position*=bottom]:after:bottom-full",
|
|
|
|
|
// Define some variables
|
|
|
|
|
"[--toast-calc-height:var(--toast-frontmost-height,var(--toast-height))] [--toast-gap:--spacing(3)] [--toast-peek:--spacing(3)] [--toast-scale:calc(max(0,1-(var(--toast-index)*.1)))] [--toast-shrink:calc(1-var(--toast-scale))]",
|
|
|
|
|
// Define offset-y variable
|
|
|
|
|
"data-[position*=top]:[--toast-calc-offset-y:calc(var(--toast-offset-y)+var(--toast-index)*var(--toast-gap)+var(--toast-swipe-movement-y))]",
|
|
|
|
|
"data-[position*=bottom]:[--toast-calc-offset-y:calc(var(--toast-offset-y)*-1+var(--toast-index)*var(--toast-gap)*-1+var(--toast-swipe-movement-y))]",
|
|
|
|
|
// Default state transform
|
|
|
|
|
"data-[position*=top]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)+(var(--toast-index)*var(--toast-peek))+(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
|
|
|
|
"data-[position*=bottom]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--toast-peek))-(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
|
|
|
|
// Limited state
|
|
|
|
|
"data-limited:opacity-0",
|
|
|
|
|
// Expanded state
|
|
|
|
|
"data-expanded:h-(--toast-height)",
|
|
|
|
|
"data-position:data-expanded:transform-[translateX(var(--toast-swipe-movement-x))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
// Starting and ending animations
|
|
|
|
|
"data-[position*=top]:data-starting-style:transform-[translateY(calc(-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-[position*=bottom]:data-starting-style:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
|
|
|
|
"data-ending-style:opacity-0",
|
|
|
|
|
// Ending animations (direction-aware)
|
|
|
|
|
"data-ending-style:not-data-limited:not-data-swipe-direction:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
|
|
|
|
// Ending animations (expanded)
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
|
|
|
|
"data-expanded:data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
|
|
|
|
"pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm transition-opacity duration-250 data-expanded:opacity-100",
|
|
|
|
|
hideCollapsedContent &&
|
|
|
|
|
"not-data-expanded:pointer-events-none not-data-expanded:opacity-0",
|
|
|
|
|
)}
|
|
|
|
|
data-position={position}
|
|
|
|
|
key={toast.id}
|
|
|
|
|
swipeDirection={
|
|
|
|
|
position.includes("center")
|
|
|
|
|
? [isTop ? "up" : "down"]
|
|
|
|
|
: position.includes("left")
|
|
|
|
|
? ["left", isTop ? "up" : "down"]
|
|
|
|
|
: ["right", isTop ? "up" : "down"]
|
|
|
|
|
}
|
|
|
|
|
toast={toast}
|
|
|
|
|
>
|
|
|
|
|
<ThreadToastVisibleAutoDismiss
|
|
|
|
|
dismissAfterVisibleMs={toast.data?.dismissAfterVisibleMs}
|
|
|
|
|
toastId={toast.id}
|
|
|
|
|
/>
|
|
|
|
|
<Toast.Content className="pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm transition-opacity duration-250 data-behind:not-data-expanded:pointer-events-none data-behind:opacity-0 data-expanded:opacity-100">
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
{Icon && (
|
|
|
|
|
<div
|
|
|
|
|
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
|
|
|
|
data-slot="toast-icon"
|
|
|
|
|
>
|
|
|
|
|
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-0.5">
|
|
|
|
|
<Toast.Title className="font-medium" data-slot="toast-title" />
|
|
|
|
|
<Toast.Description
|
|
|
|
|
className="text-muted-foreground"
|
|
|
|
|
data-slot="toast-description"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{toast.actionProps && (
|
|
|
|
|
<Toast.Action
|
|
|
|
|
className={buttonVariants({ size: "xs" })}
|
|
|
|
|
data-slot="toast-action"
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
{Icon && (
|
|
|
|
|
<div
|
|
|
|
|
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
|
|
|
|
data-slot="toast-icon"
|
|
|
|
|
>
|
|
|
|
|
{toast.actionProps.children}
|
|
|
|
|
</Toast.Action>
|
|
|
|
|
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Toast.Content>
|
|
|
|
|
</Toast.Root>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-0.5">
|
|
|
|
|
<Toast.Title className="font-medium" data-slot="toast-title" />
|
|
|
|
|
<Toast.Description
|
|
|
|
|
className="text-muted-foreground"
|
|
|
|
|
data-slot="toast-description"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{toast.actionProps && (
|
|
|
|
|
<Toast.Action className={buttonVariants({ size: "xs" })} data-slot="toast-action">
|
|
|
|
|
{toast.actionProps.children}
|
|
|
|
|
</Toast.Action>
|
|
|
|
|
)}
|
|
|
|
|
</Toast.Content>
|
|
|
|
|
</Toast.Root>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Toast.Viewport>
|
|
|
|
|
</Toast.Portal>
|
|
|
|
|
);
|
|
|
|
|