diff --git a/packages/studio/src/components/StudioOverlays.tsx b/packages/studio/src/components/StudioOverlays.tsx index e27da1467c..b20d1556ec 100644 --- a/packages/studio/src/components/StudioOverlays.tsx +++ b/packages/studio/src/components/StudioOverlays.tsx @@ -75,19 +75,21 @@ export const StudioOverlays = memo(function StudioOverlays({ }} /> )} - {/* One bottom-right stack so the feedback card and toasts queue instead - of covering each other. Empty when nothing is showing. */} -
- {toasts.map((toast) => ( - dismissToast(toast.id)} - /> - ))} - + {/* Toasts centre in the room the feedback card leaves, so the two never cover each other. */} +
+
+ {toasts.map((toast) => ( + dismissToast(toast.id)} + /> + ))} +
+
+ +
); diff --git a/packages/studio/src/components/StudioToast.test.tsx b/packages/studio/src/components/StudioToast.test.tsx new file mode 100644 index 0000000000..22278b7fa7 --- /dev/null +++ b/packages/studio/src/components/StudioToast.test.tsx @@ -0,0 +1,41 @@ +// @vitest-environment happy-dom + +import React, { act } from "react"; +import { afterEach, describe, expect, it } from "vitest"; +import { mountReactHarness } from "../hooks/domSelectionTestHarness"; +import { StudioToast } from "./StudioToast"; + +(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true; + +afterEach(() => { + document.body.innerHTML = ""; +}); + +function mount(tone: "error" | "info") { + const dismissed: string[] = []; + mountReactHarness( + dismissed.push(tone)} />, + ); + return dismissed; +} + +describe("StudioToast", () => { + it("dismisses an info toast on a click anywhere on it, with no Dismiss button", () => { + const dismissed = mount("info"); + expect(document.querySelector("button")).toBeNull(); + act(() => document.querySelector("[role=status]")?.click()); + expect(dismissed).toEqual(["info"]); + }); + + it("keeps an error toast up on a click on it, so its text can be selected and copied", () => { + const dismissed = mount("error"); + act(() => document.querySelector("[role=alert]")?.click()); + expect(dismissed).toEqual([]); + }); + + it("gives a persisting error toast a Dismiss button that dismisses it once", () => { + const dismissed = mount("error"); + act(() => document.querySelector("[aria-label=Dismiss]")?.click()); + expect(dismissed).toEqual(["error"]); + }); +}); diff --git a/packages/studio/src/components/StudioToast.tsx b/packages/studio/src/components/StudioToast.tsx index a00fb1b08a..7f7244f205 100644 --- a/packages/studio/src/components/StudioToast.tsx +++ b/packages/studio/src/components/StudioToast.tsx @@ -1,50 +1,34 @@ +import { X } from "../icons/SystemIcons"; +import { toastPersists } from "../hooks/useToast"; + interface StudioToastProps { message: string; - tone?: "error" | "info"; - /** Plays the exit animation when true (owner removes the node after ~160ms). */ - leaving?: boolean; - onDismiss?: () => void; + tone: "error" | "info"; + onDismiss: () => void; } -export function StudioToast({ message, tone, leaving, onDismiss }: StudioToastProps) { - const isError = tone === "error"; +export function StudioToast({ message, tone, onDismiss }: StudioToastProps) { + const persists = toastPersists(tone); return (
{ + if (event.key === "Escape") onDismiss(); + }} + className={`hf-notice-in flex min-h-12 w-fit max-w-[min(680px,100%)] items-center gap-1.5 rounded-3xl bg-text-0 py-1.5 pr-1.5 pl-5 text-[14px] leading-5 font-medium wrap-anywhere text-bg-0 shadow-notice not-has-[button]:pr-5 ${persists ? "" : "cursor-pointer"}`} > -
- {message} + {persists && ( + - )} -
+ + + )}
); } - -export function toastSurface(isError: boolean): string { - return `border shadow-popover bg-raised ${isError ? "border-danger/40" : "border-border"}`; -} diff --git a/packages/studio/src/components/feedback/StudioFeedbackCard.tsx b/packages/studio/src/components/feedback/StudioFeedbackCard.tsx index 9ed8f7ad48..5c379f288b 100644 --- a/packages/studio/src/components/feedback/StudioFeedbackCard.tsx +++ b/packages/studio/src/components/feedback/StudioFeedbackCard.tsx @@ -1,5 +1,4 @@ import { memo, useState, useCallback, useRef, useEffect } from "react"; -import { toastSurface } from "../StudioToast"; import { trackStudioFeedback, trackStudioFeedbackShown, @@ -213,7 +212,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() { }} >

); }); + +function cardSurface(isError: boolean): string { + return `border shadow-popover bg-raised ${isError ? "border-danger/40" : "border-border"}`; +} diff --git a/packages/studio/src/hooks/useToast.ts b/packages/studio/src/hooks/useToast.ts index 209bfc7e21..24d6683d62 100644 --- a/packages/studio/src/hooks/useToast.ts +++ b/packages/studio/src/hooks/useToast.ts @@ -4,19 +4,18 @@ import type { AppToast } from "../utils/studioHelpers"; interface ToastItem extends AppToast { id: number; - /** True while the exit animation plays, just before removal. */ - leaving?: boolean; } const AUTO_DISMISS_MS = 4000; -const EXIT_MS = 160; const MAX_TOASTS = 3; +/** Error toasts persist until dismissed so failures can't silently vanish. */ +export const toastPersists = (tone: AppToast["tone"]) => tone === "error"; + let nextToastId = 1; /** - * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts - * persist until explicitly dismissed so failures can't silently vanish. + * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts persist. */ export function useToast() { const [toasts, setToasts] = useState([]); @@ -30,7 +29,7 @@ export function useToast() { } }, []); - const removeToast = useCallback( + const dismissToast = useCallback( (id: number) => { clearTimer(id); setToasts((prev) => prev.filter((t) => t.id !== id)); @@ -38,17 +37,6 @@ export function useToast() { [clearTimer], ); - const dismissToast = useCallback( - (id: number) => { - clearTimer(id); - // Mark leaving so the exit animation plays, then remove. - setToasts((prev) => prev.map((t) => (t.id === id ? { ...t, leaving: true } : t))); - const timer = setTimeout(() => removeToast(id), EXIT_MS); - timersRef.current.set(id, timer); - }, - [clearTimer, removeToast], - ); - const showToast = useCallback( (message: string, tone: AppToast["tone"] = "error"): number => { const id = nextToastId++; @@ -61,7 +49,7 @@ export function useToast() { } return next; }); - if (tone !== "error") { + if (!toastPersists(tone)) { const timer = setTimeout(() => dismissToast(id), AUTO_DISMISS_MS); timersRef.current.set(id, timer); } diff --git a/packages/studio/src/styles/components.css b/packages/studio/src/styles/components.css index ae76e180bc..b1f31c060d 100644 --- a/packages/studio/src/styles/components.css +++ b/packages/studio/src/styles/components.css @@ -605,7 +605,7 @@ } } -/* Toast enter/exit (StudioToast) */ +/* Feedback card enter/exit (StudioFeedbackCard) */ @keyframes hf-toast-in { from { opacity: 0; @@ -646,6 +646,24 @@ } } +/* A toast rises in and leaves at once (StudioToast). */ +@keyframes hf-notice-in { + from { + opacity: 0; + transform: translateY(8px) scale(0.98); + } +} + +.hf-notice-in { + animation: hf-notice-in 200ms cubic-bezier(0.32, 0.72, 0, 1) backwards; +} + +@media (prefers-reduced-motion: reduce) { + .hf-notice-in { + animation: none; + } +} + /* Overlay/backdrop entrance — the heaviest visual changes shouldn't pop in */ @keyframes hf-backdrop-in { from { diff --git a/packages/studio/src/styles/theme.css b/packages/studio/src/styles/theme.css index d62a08ca82..fc95e02386 100644 --- a/packages/studio/src/styles/theme.css +++ b/packages/studio/src/styles/theme.css @@ -285,6 +285,9 @@ 0 16px 40px light-dark(rgb(0 0 0 / 0.14), rgb(0 0 0 / 0.55)), 0 0 0 1px light-dark(rgb(0 0 0 / 0.07), rgb(0 0 0 / 0.45)); + /* The toast pill: a close contact shadow under a soft lift. */ + --shadow-notice: 0 2px 4px rgb(0 0 0 / 0.12), 0 14px 36px -8px rgb(0 0 0 / 0.4); + /* The primary button reads as a raised key rather than a floating panel: a tight * contact shadow, a soft ambient one, and an inner top highlight. */ --shadow-btn-primary: