# Toast (`.z-toaster`)

> Sonner-style stacked notifications created imperatively through `window.zToast`, grouped by screen position, with swipe dismissal and promise helpers.

- **Kind:** css
- **Category:** feedback

## Reference inventories

- [CSS Variables (26)](https://next.0build.dev/docs/components/toast/css-vars.md)
- [CSS Classes (12)](https://next.0build.dev/docs/components/toast/css-classes.md)

## Methods

| Method | Params | Returns | Description |
| --- | --- | --- | --- |
| `config()` | `options?: ZToastGlobalConfig` | `Readonly<InternalGlobalConfig>` | Reads or updates the global defaults (position, duration, max, expand, dismissible, closeButton, richColors, blur, gap, offset, cls, stl, i18n) and returns the current configuration. |
| `danger()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a toast with the danger status icon and coloring; returns its id. |
| `dismiss()` | `id?: string` | `void` | Dismisses one toast by id, or every toast when called without an id. |
| `error()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Alias of `danger`. |
| `info()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a toast with the info status icon and coloring; returns its id. |
| `loading()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a persistent loading toast with no auto-dismiss timeout; returns its id. |
| `message()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a neutral toast and returns its id. Accepts a message string or a full options object. |
| `promise()` | `promise: Promise<T> \| (() => Promise<T>)`, `options: ZToastPromiseOptions<T>` | `ZToastPromiseResult<T>` | Shows a loading toast that updates to success or danger when the promise settles. Branches accept strings, options objects, or functions of the settled value; a missing branch dismisses the toast. Returns the id plus a thenable with `unwrap()`. |
| `success()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a toast with the success status icon and coloring; returns its id. |
| `update()` | `id: string`, `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Updates an existing toast in place (same id), merging options and restarting its timer. |
| `warning()` | `input: string \| ZToastOptions`, `options?: ZToastOptions` | `string` | Shows a toast with the warning status icon and coloring; returns its id. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-close-button` | — | `descendant` | `marker` | Whether the toast renders a close button. |
| `data-dismissible` | — | `descendant` | `marker` | Whether swipe dismissal is enabled for the toast. |
| `data-expanded` | — | `descendant` | `marker` | Whether the group is expanded (hover/focus) or collapsed to the peek stack. |
| `data-front` | — | `descendant` | `marker` | Whether this toast is the front (newest) item of the collapsed stack. |
| `data-mounted` | — | `descendant` | `marker` | `false` until the first animation frame, then `true`; drives the enter transition. |
| `data-position` | — | `descendant` | `marker` | On the toaster group: the screen position (`bottom-right` by default, plus `bottom-left`, `bottom-center`, `top-right`, `top-left`, `top-center`). |
| `data-removed` | — | `descendant` | `marker` | Set `true` while the toast plays its leave transition. |
| `data-rich-colors` | — | `descendant` | `marker` | Whether status colors tint the whole toast (from the `richColors` option). |
| `data-status` | — | `descendant` | `marker` | Toast status (`default`, `success`, `danger`, `warning`, `info`, `loading`); colors the icon and, with rich colors, the whole toast. |
| `data-swipe-out` | — | `descendant` | `marker` | Set `true` when a swipe dismisses the toast; plays the swipe-out transform. |
| `data-swiping` | — | `descendant` | `marker` | Set `true` during an active swipe; disables transitions. |
| `data-toast-id` | — | `descendant` | `marker` | The toast's id, set on its `li` element. |
| `data-visible` | — | `descendant` | `marker` | Set `false` for toasts beyond the `max` visible count. |
| `data-x-position` | — | `descendant` | `marker` | On each toast: `left`, `right`, or `center`; used for swipe-direction resistance. |
| `data-y-position` | — | `descendant` | `marker` | On each toast: `top` or `bottom`, derived from its group; flips the stacking direction and transform origin. |

## Notes

- Toasts are created imperatively (`zToast.success('Saved')`); the toaster group is created on demand and appended to `body`, so no markup is required. The toast pack exposes `window.zToast`.
- Setting `href` on `action` or `cancel` renders a native `<a>` link (supporting `target` and `rel`, defaulting `rel` to `noopener noreferrer` for `target="_blank"`) while still running `onClick` and dismissing unless prevented.
- Collapsed stacks peek by `--z-toaster-peek` per item and scale down by 5% per depth; hovering or focusing the group expands it.
- Auto-dismiss timers pause while the group is expanded or hovered, or the page is hidden; `loading` toasts never auto-dismiss. Default duration is 4000 ms (danger 6000 ms).
- Toasts can be swiped away along the group's edge direction; `dismissible: false` or interactive content under the pointer blocks the swipe.
- On viewports up to 40rem wide the group spans the viewport with 1rem side offsets.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Alert](https://next.0build.dev/docs/components/alert.md)
