Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions apps/desktop/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1398,21 +1398,6 @@
transform-origin: bottom center;
transition: transform 220ms var(--ease-snappy);
}
/* An auto-dismissing card's clock, along its foot: a 1px accent hairline that drains. */
@keyframes rc-toast-timer {
from {
transform: scaleX(1);
}
to {
transform: scaleX(0);
}
}
.rc-toast-timer {
animation-name: rc-toast-timer;
animation-timing-function: linear;
animation-fill-mode: forwards;
transform-origin: left center;
}

/*
* Skeletons: a quiet block where content will appear, swept by a soft
Expand Down
151 changes: 95 additions & 56 deletions apps/desktop/src/ui/Toaster.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Up to three toasts, newest in front (state/toasts.ts keeps the queue), frosted
// like the composer, in the window's bottom-right corner, away from the
// transcript being read. Info and success leave after 2.5 s, errors after 5 s.
// transcript being read. At rest the cards behind the front one take its
// height and hide their text, so only their edges peek above it. Info and
// success leave after 2.5 s, errors after 5 s.
// The pointer or focus on the stack, a drag, or the window in the background
// stops the clock. A click anywhere on the card, ×, Escape, or a drag past 48px
// sideways or 24px down dismisses; a drag never selects text anywhere.
Expand All @@ -17,16 +19,26 @@ import {
TOAST_DRAG_MS,
} from "../lib/toastDrag";
import { dismissToast, expireToasts, setToastsPaused, type Toast, useApp } from "../state/store";
import { nextExpiry, toastTtl } from "../state/toasts";
import { CircleAlert, CircleCheck, Info, X } from "./icons";
import { cx, Pill, Spinner } from "./primitives";
import { nextExpiry } from "../state/toasts";
import {
ArrowUpRight,
CircleAlert,
CircleCheck,
ExternalLink,
FolderOpen,
Info,
RotateCcw,
Undo2,
X,
} from "./icons";
import { cx, Spinner } from "./primitives";

/** How far the cards behind the front one peek over its top edge, and how much smaller each is. */
const TOAST_PEEK = 6;
const TOAST_SHRINK = 0.04;
/** The 8px between fanned-out cards. */
/** The stack's distance from the window's bottom and right edges. */
const TOAST_INSET = 16;
/** The 8px between fanned-out cards. */
const TOAST_GAP = 8;
/** A quiet settle on the check after a spinner finishes. */
const TOAST_SETTLE_MS = 320;
Expand All @@ -50,11 +62,12 @@ interface DragSession {

function ToastCard({
toast,
paused,
compactHeight,
onDrag,
}: {
toast: Toast;
paused: boolean;
/** A card behind the front one at rest: drawn at the front card's height with its text hidden. */
compactHeight?: number;
onDrag: (dragging: boolean) => void;
}) {
const ref = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -167,6 +180,7 @@ function ToastCard({
const timer = setTimeout(() => setSettled(false), TOAST_SETTLE_MS);
return () => clearTimeout(timer);
}, [spinning, toast.tone]);
const compact = compactHeight !== undefined;
return (
<div
ref={ref}
Expand All @@ -177,69 +191,89 @@ function ToastCard({
onPointerUp={onPointerUp}
onPointerCancel={onPointerCancel}
onLostPointerCapture={onLostPointerCapture}
style={compact ? { height: compactHeight } : undefined}
className={cx(
"rc-toast pointer-events-auto relative flex w-[380px] max-w-[calc(100vw-32px)] cursor-pointer touch-none items-start gap-2 overflow-hidden rounded-xl py-1.5 pr-1.5 pl-3 text-callout select-none active:cursor-grabbing",
"rc-toast pointer-events-auto relative w-[380px] max-w-[calc(100vw-32px)] cursor-pointer touch-none overflow-hidden rounded-xl text-callout select-none active:cursor-grabbing",
toast.leaving ? (flung ? "" : "rc-toast-out") : "rc-toast-in",
)}
>
<span className="flex h-6 shrink-0 items-center">
{spinning ? (
<Spinner size={13} />
) : (
<Icon
size={14}
className={cx(
settled && "rc-dot-in",
error ? "text-danger" : toast.tone === "success" ? "text-success" : "text-fg-muted",
)}
/>
<div
data-toast-body
aria-hidden={compact || undefined}
className={cx(
"flex items-start gap-2 py-1.5 pr-1.5 pl-3 transition-opacity duration-150 ease-out",
compact && "opacity-0",
)}
</span>
<p className="line-clamp-3 min-w-0 flex-1 py-1 text-fg">{toast.text}</p>
{toast.action && (
<Pill
size="sm"
onClick={() => {
toast.action?.run();
dismissToast(toast.id);
}}
>
{toast.action.label}
</Pill>
)}
<button
type="button"
aria-label="Dismiss"
onClick={() => dismissToast(toast.id)}
className="flex size-6 shrink-0 items-center justify-center rounded-full text-fg-faint hover:bg-fill hover:text-fg active:bg-fill-strong"
>
<X size={12} />
</button>
{toast.persist && toast.progress !== undefined ? (
<div className="flex min-w-0 flex-1 items-start gap-2">
<span className="flex h-6 shrink-0 items-center">
{spinning ? (
<Spinner size={13} />
) : (
<Icon
size={14}
className={cx(
settled && "rc-dot-in",
error ? "text-danger" : toast.tone === "success" ? "text-success" : "text-fg-muted",
)}
/>
)}
</span>
<p className="line-clamp-3 min-w-0 flex-1 py-1 text-fg">{toast.text}</p>
</div>
<div className="flex shrink-0 items-center gap-1">
{toast.action && <ToastActionButton toast={toast} compact={compact} />}
<button
type="button"
aria-label="Dismiss"
tabIndex={compact ? -1 : undefined}
onClick={() => dismissToast(toast.id)}
className="flex size-6 items-center justify-center rounded-full text-fg-faint hover:bg-fill hover:text-fg active:bg-fill-strong"
>
<X size={12} />
</button>
</div>
</div>
{toast.persist && toast.progress !== undefined && (
<span className="absolute inset-x-0 bottom-0 h-0.5 bg-fill" aria-hidden>
<span
className="block h-full bg-accent transition-[width] duration-300 ease-snappy"
style={{ width: `${Math.round(Math.min(1, Math.max(0, toast.progress)) * 100)}%` }}
/>
</span>
) : toast.persist ? null : (
// An auto-dismissing card drains a 1px accent hairline along its foot; it stops with
// the clock while the stack is held by the pointer, focus or a drag.
<span className="absolute inset-x-0 bottom-0 h-px overflow-hidden" aria-hidden>
<span
key={toast.at}
className="rc-toast-timer block h-full bg-accent"
style={{
animationDuration: `${toastTtl(toast.tone)}ms`,
animationPlayState: paused ? "paused" : "running",
}}
/>
</span>
)}
</div>
);
}

const ACTION_ICONS: Record<string, (props: { size?: number }) => ReactNode> = {
Undo: Undo2,
Open: ArrowUpRight,
"Release page": ExternalLink,
Restart: RotateCcw,
"Move…": FolderOpen,
};

function ToastActionButton({ toast, compact }: { toast: Toast; compact: boolean }) {
const action = toast.action;
if (!action) return null;
const ActionIcon = ACTION_ICONS[action.label];
return (
<button
type="button"
tabIndex={compact ? -1 : undefined}
onClick={() => {
action.run();
dismissToast(toast.id);
}}
className="flex h-6 items-center gap-1 rounded-full bg-accent/12 pr-3 pl-2 font-medium whitespace-nowrap text-accent hover:bg-accent/18 active:bg-accent/24"
>
{ActionIcon && <ActionIcon size={13} />}
{action.label}
</button>
);
}

export function Toaster() {
const toasts = useApp((s) => s.toasts);
const section = useRef<HTMLElement>(null);
Expand Down Expand Up @@ -354,7 +388,11 @@ export function Toaster() {
: `translateY(${-index * TOAST_PEEK}px) scale(${Math.max(0.9, 1 - index * TOAST_SHRINK)})`,
}}
>
<ToastCard toast={toast} paused={paused} onDrag={setDragging} />
<ToastCard
toast={toast}
compactHeight={!expanded && index > 0 ? heights[toasts[0]?.id ?? ""] : undefined}
onDrag={setDragging}
/>
</ToastSlot>
))}
</div>
Expand All @@ -380,9 +418,10 @@ function ToastSlot({
useEffect(() => {
const el = ref.current;
if (!el) return;
const report = () => onHeight(id, el.offsetHeight);
const body = el.querySelector<HTMLElement>("[data-toast-body]") ?? el;
const report = () => onHeight(id, body.offsetHeight);
report();
return observeSize(el, report);
return observeSize(body, report);
}, [id, onHeight]);
return (
<div ref={ref} className={cx("rc-toast-slot", className)} style={style}>
Expand Down
12 changes: 7 additions & 5 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,16 @@ a raw element. `?catalog` in a dev build shows them all on one page.
- **Toast:** `.rc-toast rounded-2xl` (strong glass and a slight shadow), 380px wide, `py-1.5 pl-3 pr-1.5 text-callout`: an icon
(info `text-fg-muted`, success `text-success`, error `text-danger`, a
spinner while it has progress), the text in `text-fg` (up to 3 lines), at
most one action as a secondary pill (`h-6 bg-fill`), and a close button.
most one action as a tinted button on the close button's row (`h-6
bg-accent/12 text-accent`, the action's icon before its label: Undo ↶,
Open ↗), and a quiet close button. The card is as tall as its text.
Progress is a 2px accent bar along its foot. `Toaster` shows at most three
(`state/toasts.ts` enforces the queue), newest on top: at rest only the
front card is fully shown, the others peeking 6px above it, and hovering or
front card is fully shown, the others taking its height with their text
hidden and peeking 6px above it, and hovering or
focusing the stack fans them out 8px apart, upward. In the window's
bottom-right corner, 16px in, away from the transcript being read. An
auto-dismissing card drains a 1px accent hairline along its foot, which
stops with its clock; a card replaced in place from spinner to check settles
bottom-right corner, 16px in, away from the transcript being read. No timer
line: a card's clock is not drawn. A card replaced in place from spinner to check settles
onto the check. The same message again refreshes its card and
restarts its time instead of stacking; past three, the oldest is dropped.
Info and success leave after 2.5s, errors after 5s. The pointer or focus on
Expand Down