Miss. Train. Move.

Whistle toast

Toasts, notifications. Drops in and lands with a small squash.

    Sport
    Football
    Move
    Drops in and lands with a small squash.
    For
    Toasts, notifications

    drops and lands 560ms · out 192ms · reduced: fade

    01 Install

    Terminal
    npx shadcn@latest add https://moveui-red.vercel.app/r/whistle-toast.json

    It brings the tokens with it. The first time, import the tokens once in your root layout:

    app/layout.tsx
    import "@/components/moveui/tokens.css";

    Not using shadcn? Copy the files below into components/moveui/, and tokens.css next to them.

    02 Use it

    Example
    import { useWhistle, WhistleToasts } from "@/components/moveui/whistle-toast/whistle-toast";
    
    export function Page() {
      const whistle = useWhistle();
      return (
        <>
          <WhistleToasts {...whistle} />
          <button onClick={() => whistle.push("Saved", "Your changes are live.")}>Save</button>
        </>
      );
    }

    03 Or ask your agent

    Paste this into Claude Code, Cursor or any coding agent. It installs the piece and wires it in.

    Prompt
    Add the Move UI "Whistle toast" piece to this project. It's for: Toasts, notifications.
    
    1. Install it: npx shadcn@latest add https://moveui-red.vercel.app/r/whistle-toast.json
    2. If the project doesn't import the Move UI tokens yet, add this once to the root layout: import "@/components/moveui/tokens.css";
    3. Use it like this, adapted to where it belongs in my code:
    
    import { useWhistle, WhistleToasts } from "@/components/moveui/whistle-toast/whistle-toast";
    
    export function Page() {
      const whistle = useWhistle();
      return (
        <>
          <WhistleToasts {...whistle} />
          <button onClick={() => whistle.push("Saved", "Your changes are live.")}>Save</button>
        </>
      );
    }
    
    Keep its reduced-motion behaviour and keyboard support. Don't hardcode durations, easing or colours: they come from the --ml-* tokens.
    Docs: https://moveui-red.vercel.app/pieces/whistle-toast

    Want your agent to know the whole library and its motion rules? Add the Move UI skill to your project:

    Terminal
    npx shadcn@latest add https://moveui-red.vercel.app/r/skill.json

    04 Code

    components/moveui/whistle-toast/whistle-toast.tsx
    "use client";
    
    import { useCallback, useEffect, useRef, useState } from "react";
    import "./whistle-toast.css";
    
    /**
     * Whistle toast: a short message that drops in, lands with a small squash and leaves quickly.
     * useWhistle() gives you the list and a push(); <WhistleToasts> renders it.
     * Announced to screen readers through a polite live region. Pauses its timer while hovered or focused.
     */
    export type Toast = { id: number; title: string; body?: string; leaving?: boolean };
    
    export function useWhistle({ duration = 3200, max = 3 } = {}) {
      const [toasts, setToasts] = useState<Toast[]>([]);
      const timers = useRef(new Map<number, ReturnType<typeof setTimeout>>());
      const nextId = useRef(1);
    
      const dismiss = useCallback((id: number) => {
        clearTimeout(timers.current.get(id));
        timers.current.delete(id);
        setToasts((all) => all.map((t) => (t.id === id ? { ...t, leaving: true } : t)));
      }, []);
    
      const arm = useCallback((id: number) => {
        clearTimeout(timers.current.get(id));
        timers.current.set(id, setTimeout(() => dismiss(id), duration));
      }, [dismiss, duration]);
    
      const push = useCallback((title: string, body?: string) => {
        const id = nextId.current++;
        setToasts((all) => [{ id, title, body }, ...all].slice(0, max));
        arm(id);
        return id;
      }, [arm, max]);
    
      const remove = useCallback((id: number) => setToasts((all) => all.filter((t) => t.id !== id)), []);
      const hold = useCallback((id: number) => clearTimeout(timers.current.get(id)), []);
    
      useEffect(() => {
        const all = timers.current;
        return () => all.forEach(clearTimeout);
      }, []);
    
      return { toasts, push, dismiss, remove, hold, arm };
    }
    
    type StackProps = Pick<ReturnType<typeof useWhistle>, "toasts" | "dismiss" | "remove" | "hold" | "arm"> & {
      className?: string;
    };
    
    export function WhistleToasts({ toasts, dismiss, remove, hold, arm, className }: StackProps) {
      return (
        <ol className={["ml-toasts", className].filter(Boolean).join(" ")} aria-live="polite" aria-relevant="additions">
          {toasts.map((t) => (
            <li
              key={t.id}
              className="ml-toast"
              data-leaving={t.leaving ? "" : undefined}
              onAnimationEnd={(e) => { if (t.leaving && e.animationName === "ml-toast-out") remove(t.id); }}
              onPointerEnter={() => hold(t.id)}
              onPointerLeave={() => !t.leaving && arm(t.id)}
              onFocus={() => hold(t.id)}
              onBlur={() => !t.leaving && arm(t.id)}
            >
              <div>
                <p className="ml-toast__title">{t.title}</p>
                {t.body && <p className="ml-toast__body">{t.body}</p>}
              </div>
              <button type="button" className="ml-toast__close" aria-label="Dismiss" onClick={() => dismiss(t.id)}>
                <svg width="10" height="10" viewBox="0 0 10 10" aria-hidden="true"><path d="M1 1l8 8M9 1 1 9" stroke="currentColor" strokeWidth="1.5" /></svg>
              </button>
            </li>
          ))}
        </ol>
      );
    }
    
    components/moveui/whistle-toast/whistle-toast.css
    /*
      Whistle toast. In: drops from above, lands with a small squash (--ml-impact-x / -y) and settles,
      on --ml-dur-travel. Out: lifts and fades on --ml-dur-exit. New toasts arrive on top.
      Reduced motion: the impact tokens go to 1 and durations shorten, so it simply fades in.
    */
    .ml-toasts {
      display: grid;
      gap: 0.5rem;
      width: min(20rem, 100%);
      list-style: none;
      margin: 0;
      padding: 0;
    }
    .ml-toast {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 0.75rem;
      padding: 0.85rem 0.9rem;
      border-radius: var(--ml-radius);
      background: var(--ml-ink);
      color: var(--ml-ink-fg);
      transform-origin: 50% 100%;
      animation: ml-toast-in var(--ml-dur-travel) linear both;
    }
    .ml-toast[data-leaving] {
      animation: ml-toast-out var(--ml-dur-exit) var(--ml-ease-out) both;
    }
    .ml-toast__title { font-size: 0.875rem; font-weight: 700; text-transform: uppercase; line-height: 1.1; }
    .ml-toast__body { font-size: 0.8125rem; opacity: 0.75; margin-top: 0.2rem; }
    .ml-toast__close {
      appearance: none;
      border: 0;
      background: none;
      color: inherit;
      padding: 0.25rem;
      margin: -0.25rem -0.25rem 0 0;
      opacity: 0.7;
      cursor: pointer;
    }
    .ml-toast__close:hover { opacity: 1; }
    .ml-toast__close:focus-visible { outline: 2px solid var(--ml-ink-fg); outline-offset: 1px; }
    
    /* Falls (ease-in, gravity), hits (squash), recovers (small stretch), settles. */
    @keyframes ml-toast-in {
      0% { opacity: 0; transform: translateY(-18px); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.5); }
      45% { opacity: 1; transform: translateY(0) scale(var(--ml-impact-x), var(--ml-impact-y)); animation-timing-function: var(--ml-ease-out); }
      70% { transform: translateY(-2px) scale(calc(2 - var(--ml-impact-x)), calc(2 - var(--ml-impact-y))); }
      100% { opacity: 1; transform: none; }
    }
    @keyframes ml-toast-out {
      to { opacity: 0; transform: translateY(-8px) scale(0.98); }
    }
    @media (prefers-reduced-motion: reduce) {
      @keyframes ml-toast-in { from { opacity: 0; } to { opacity: 1; } }
    }