# Toast stack

> Notifications with continuous squircle geometry that stack, fan out on hover, follow a promise in one toast, and swipe away.

Toasts usually pile up or pop over each other. Here a new one rises in from the edge through a blur and the ones before it step back into a hairline stack, three rims peeking out behind the newest. Crafted with continuous Figma squircle geometry and clean borderless cards. The icon tile arrives with a soothing, choreographed spring delay as the card settles, drawing its vector strokes and giving a gentle tactile bump on promise resolution. Hover or focus fans them out into an unclipped list at their real heights. toast.promise keeps one toast from start to finish: a spinner while the work runs, then its words morph and a check draws itself (or an error, with a small shake). Swipe one away with kinetic inertia, or press Alt+T to reach them from the keyboard.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/toast-stack.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `text-morph`
- Docs and live preview: https://hairlineui.com/ui/toast-stack
- Registry item (source): https://hairlineui.com/r/toast-stack.json

## Usage

```tsx
import { Toaster, toast } from "@/components/toast-stack";

// Once, near the root of your app:
<Toaster position="bottom-right" />

// Anywhere:
toast("Order archived", { action: { label: "Undo", onClick: restore } });
toast.success("Invite sent");
toast.warning("Storage running low", { action: { label: "Upgrade", onClick: upgrade } });
toast.promise(save(), { loading: "Saving changes", success: "Changes saved", error: "Couldn't save" });
```

## With a server action

One toast follows the request from start to finish, so people see it land without a second notification.

```tsx
"use client";
import { toast } from "@/components/toast-stack";
import { updateHours } from "./actions";

export function SaveHours({ hours }: { hours: Hours }) {
  return (
    <button
      onClick={() =>
        toast.promise(updateHours(hours), {
          loading: "Saving opening hours",
          success: "Opening hours saved",
          error: (e) => (e instanceof Error ? e.message : "Couldn't save"),
        })
      }
    >
      Save
    </button>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `toast(title, options)` | `function` | – | Shows a toast and returns its id. Options: description, type, duration, action { label, onClick }, id (to update one in place). |
| `toast.success / error / warning / info / loading` | `function` | – | The same with a type, squircle status tile, and its animated vector glyph. |
| `toast.promise(promise, messages)` | `function` | – | One toast that morphs from loading to success or error. Messages can be functions of the result or error. |
| `toast.dismiss(id?)` | `function` | – | Dismiss one toast, or all of them. |
| `Toaster position` | `"bottom-right" \| "bottom-center" \| "bottom-left" \| "top-right" \| "top-center" \| "top-left"` | `"bottom-right"` | Which corner; the stack grows away from that edge. |
| `Toaster visible / hotkey` | `number / string` | `3 / "t"` | How many show in the stack, and the letter that, with Alt, moves focus to the newest toast. |

## States

- **arrive**: Rises from 28px past the edge through a 6px blur with slight overshoot (520ms); earlier toasts scale down 5% each and step back 11px.
- **squircle**: Continuous Figma curvature (corner smoothing 1.0) on the 36px tile and card, with a 1px clipped inner hairline border.
- **stacked**: Up to three peek behind the newest at its height, their contents hidden; more wait out of sight.
- **fanned**: Hover or keyboard focus spreads them into a list at their measured heights with 10px gaps; the stack’s hit area grows with it.
- **clean**: Completely borderless and clean card face with no bottom lines or progress bars.
- **promise**: The spinner blurs into a self-drawing check with a tile settle bump while the title morphs letter-by-letter.
- **dismiss**: Swipe past 80px or flick with inertia to carry it off the edge; the close button or Escape lifts it out through a blur.

## What it handles

Toasts usually pile up or pop over each other. This stacks them neatly in continuous squircles, follows a request in a single toast, and never disappears while someone is reading it.

- **Concentric squircle craft**: Figma superellipse curves for both the card and icon tile with 1px inner hairline borders and specular top lighting.
- **Vector stroke motion & settle bump**: Glyphs draw themselves (checkmarks, crosses, warning and info stems) and tiles settle with a physical micro-bounce on resolution.
- **They stack neatly**: A new toast rises in and the earlier ones step back into a stack, with three rims peeking out behind the newest.
- **They fan out on hover or focus**: The stack spreads into a list at the toasts’ real heights, so every message can be read.
- **One toast for one request**: toast.promise shows a spinner, then morphs into success with a drawn check, or into an error with a small shake.
- **Timers that wait for you**: Toasts auto-dismiss cleanly over their duration, paused while you hover, focus, or when the tab is hidden.
- **Kinetic swipe, close or Escape**: Swipe past a threshold with velocity inertia, press the close button or press Escape to dismiss.
- **Callable from anywhere**: Render one Toaster, then call toast() from anywhere, even outside React. Pick one of six positions. Alt+T focuses the newest.

## Replaces

a toast library, a stacked layout, pausing timers, promise toasts, swipe to dismiss

## Where it fits

- **Save and update feedback**: Confirm that a change went through without a page jump.
- **Async actions**: One toast that follows a request from start to finish.
- **Undo actions**: A toast with an action button, such as Undo.
- **Errors & Warnings**: Tell people something failed or needs attention, without a blocking dialog.

## Notes

- Concentric Figma squircle geometry calculated with zero external dependencies.
- Each toast is a polite status (errors are alerts), announced once as it arrives or changes. The region is labelled "Notifications (Alt+T)".
- Hovering, keyboard focus or a hidden tab pauses every timer, so nothing disappears while someone is reading it.
- Swiping works with mouse, pen and touch with rational rubber-band boundaries and velocity projection.
- Render one Toaster; toast() can be called from anywhere, including outside React.
- Installs Text morph. With reduced motion the toasts sit as a list and change in place.

License: MIT (https://hairlineui.com/license#components)
