# @salmonui/notifications/toast API reference

> 16 exported symbols of @salmonui/notifications/toast: 3 functions, 10 interfaces and 3 types.

Canonical: https://salmonui.dev/docs/reference/notifications/toast

```ts
import { … } from '@salmonui/notifications/toast';
```

## Functions

### Toaster

Kind: function

Page: https://salmonui.dev/docs/reference/notifications/toast/Toaster

```ts
function Toaster(props: ToasterProps): ReactElement;
```

Toaster. Styling hooks: `.salmon-toaster` (`data-placement`, `data-paused`,
`data-scoped`), its `.salmon-toaster-list`; `.salmon-toast` (`data-tone`,
`data-closing`) with parts `-icon`, `-main`, `-title`, `-description`,
`-actions`, `-action`, `-dismiss`, `-progress`.

### createToastQueue

Kind: function

Page: https://salmonui.dev/docs/reference/notifications/toast/createToastQueue

```ts
function createToastQueue(options?: ToastQueueOptions): ToastQueue;
```

Creates a toast queue. Call it in a client module or in an effect, never at render time.

### useToast

Kind: function

Page: https://salmonui.dev/docs/reference/notifications/toast/useToast

```ts
function useToast(): ToastQueue;
```

The queue of the nearest `Toaster`. Throws outside a `Toaster`.

## Interfaces

### ToastAction

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastAction

```ts
interface ToastAction {
    label: ReactNode;
    altText: string;
    onAction?: ((event: MouseEvent<HTMLButtonElement>) => void) | undefined;
}
```

A button in the toast.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `label` | `label: ReactNode;` |  | The visible button label. |
| `altText` | `altText: string;` |  | Keyboard hint announced with the toast, for example "Undo with F6 then Enter". Required: the toast may be gone before a pointer reaches it. |
| `onAction` | `onAction?: ((event: MouseEvent<HTMLButtonElement>) => void) \| undefined;` | optional | Runs on press; the toast then closes with reason `'action'` unless `event.preventDefault()` is called. |

### ToastBeforeCloseEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastBeforeCloseEvent

```ts
interface ToastBeforeCloseEvent {
    readonly id: string;
    readonly reason: ToastCloseReason;
    readonly defaultPrevented: boolean;
    preventDefault(): void;
}
```

Passed to `onBeforeClose`; `preventDefault()` keeps the toast open.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  |  |
| `reason` | `readonly reason: ToastCloseReason;` |  |  |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |

### ToastCloseEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastCloseEvent

```ts
interface ToastCloseEvent {
    readonly id: string;
    readonly reason: ToastCloseReason;
}
```

Passed to `onClose`.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  |  |
| `reason` | `readonly reason: ToastCloseReason;` |  |  |

### ToastOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastOptions

```ts
interface ToastOptions {
    title?: ReactNode;
    description?: ReactNode;
    content?: ReactNode;
    tone?: ToastTone | undefined;
    icon?: ReactNode | false;
    duration?: number | undefined;
    dismissible?: boolean | undefined;
    progress?: boolean | undefined;
    actions?: readonly ToastAction[] | undefined;
    className?: string | undefined;
    style?: CSSProperties | undefined;
    onOpen?: ((id: string) => void) | undefined;
    onBeforeClose?: ((event: ToastBeforeCloseEvent) => void) | undefined;
    onClose?: ((event: ToastCloseEvent) => void) | undefined;
    onClick?: ((event: MouseEvent<HTMLElement>) => void) | undefined;
}
```

The object passed to `queue.add()` and `queue.update()`.

Members (15):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `title` | `title?: ReactNode;` | optional | Heading line. |
| `description` | `description?: ReactNode;` | optional | Body text under the title. |
| `content` | `content?: ReactNode;` | optional | Replaces the default layout (icon, title, description, actions). |
| `tone` | `tone?: ToastTone \| undefined;` | optional | Color role; `'danger'` toasts are `role="alert"`. Default `'neutral'`. |
| `icon` | `icon?: ReactNode \| false;` | optional | Replaces the built-in tone icon; `false` hides it. Always decorative. |
| `duration` | `duration?: number \| undefined;` | optional | Time on screen in ms. Default 5000, or `Infinity` when the toast has actions; `Infinity` keeps it until dismissed. Counts only while visible and not paused. |
| `dismissible` | `dismissible?: boolean \| undefined;` | optional | Shows a close button; Escape on the focused toast also closes it. Default `false`. |
| `progress` | `progress?: boolean \| undefined;` | optional | Shows the countdown bar (a CSS animation paused with the timer). |
| `actions` | `actions?: readonly ToastAction[] \| undefined;` | optional | Buttons in the toast. |
| `className` | `className?: string \| undefined;` | optional | Extra class on the toast element. |
| `style` | `style?: CSSProperties \| undefined;` | optional | Inline style on the toast element, for example a width. |
| `onOpen` | `onOpen?: ((id: string) => void) \| undefined;` | optional | Called when the toast enters the visible stack. |
| `onBeforeClose` | `onBeforeClose?: ((event: ToastBeforeCloseEvent) => void) \| undefined;` | optional | Called before the toast closes; `event.preventDefault()` keeps it. |
| `onClose` | `onClose?: ((event: ToastCloseEvent) => void) \| undefined;` | optional | Called when the toast closes, with the reason. |
| `onClick` | `onClick?: ((event: MouseEvent<HTMLElement>) => void) \| undefined;` | optional | Called on a click anywhere in the toast. |

### ToastQueue

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastQueue

```ts
interface ToastQueue {
    add(options: ToastOptions): string;
    update(id: string, options: ToastOptions): void;
    dismiss(id?: string, reason?: ToastCloseReason): void;
    pause(): void;
    resume(): void;
    setMax(max: number): void;
    subscribe(listener: () => void): () => void;
    getSnapshot(): ToastQueueSnapshot;
}
```

A toast queue: create one with `createToastQueue()` or let `Toaster` create it.

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `add` | `add(options: ToastOptions): string;` |  | Adds a toast and returns its id. A no-op returning `''` on the server. |
| `update` | `update(id: string, options: ToastOptions): void;` |  | Merges options into a toast; a new `duration` restarts its timer. |
| `dismiss` | `dismiss(id?: string, reason?: ToastCloseReason): void;` |  | Closes a toast, or every toast without an id (waiting toasts leave silently). `reason` defaults to `'programmatic'`. |
| `pause` | `pause(): void;` |  | Pauses every timer; calls nest, each `pause()` needs a `resume()`. |
| `resume` | `resume(): void;` |  | Undoes one `pause()`; timers continue with their remaining time. |
| `setMax` | `setMax(max: number): void;` |  | Sets the number of visible toasts. |
| `subscribe` | `subscribe(listener: () => void): () => void;` |  |  |
| `getSnapshot` | `getSnapshot(): ToastQueueSnapshot;` |  |  |

### ToastQueueOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastQueueOptions

```ts
interface ToastQueueOptions {
    max?: number | undefined;
    now?: (() => number) | undefined;
    setTimeout?: ((callback: () => void, ms: number) => unknown) | undefined;
    clearTimeout?: ((handle: unknown) => void) | undefined;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `max` | `max?: number \| undefined;` | optional | Visible toasts; the rest wait. Default 5. |
| `now` | `now?: (() => number) \| undefined;` | optional | Clock for tests. Default `Date.now`. |
| `setTimeout` | `setTimeout?: ((callback: () => void, ms: number) => unknown) \| undefined;` | optional | Timer for tests. Default `globalThis.setTimeout`. |
| `clearTimeout` | `clearTimeout?: ((handle: unknown) => void) \| undefined;` | optional | Timer for tests. Default `globalThis.clearTimeout`. |

### ToastQueueSnapshot

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastQueueSnapshot

```ts
interface ToastQueueSnapshot {
    readonly toasts: readonly ToastState[];
    readonly visible: readonly ToastState[];
    readonly paused: boolean;
}
```

What `getSnapshot()` returns; a new object on every change.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `toasts` | `readonly toasts: readonly ToastState[];` |  | Every toast, oldest first: the visible ones, then the waiting ones. |
| `visible` | `readonly visible: readonly ToastState[];` |  | The first `max` toasts; the same array while they do not change. |
| `paused` | `readonly paused: boolean;` |  | True while paused (hover, focus, hidden document or `pause()`). |

### ToastState

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastState

```ts
interface ToastState extends ToastOptions {
    readonly id: string;
    readonly closing: boolean;
    readonly run: number;
}
```

A toast in the queue: its options plus store state.

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  | Stable id returned by `queue.add()`. |
| `closing` | `readonly closing: boolean;` |  | True during the exit transition. |
| `run` | `readonly run: number;` |  | Increments when the timer restarts (an update of `duration`), so the countdown bar restarts. |
| `title` | `title?: ReactNode;` | optional, inherited | Heading line. |
| `description` | `description?: ReactNode;` | optional, inherited | Body text under the title. |
| `content` | `content?: ReactNode;` | optional, inherited | Replaces the default layout (icon, title, description, actions). |
| `tone` | `tone?: ToastTone;` | optional, inherited | Color role; `'danger'` toasts are `role="alert"`. Default `'neutral'`. |
| `icon` | `icon?: ReactNode;` | optional, inherited | Replaces the built-in tone icon; `false` hides it. Always decorative. |
| `duration` | `duration?: number;` | optional, inherited | Time on screen in ms. Default 5000, or `Infinity` when the toast has actions; `Infinity` keeps it until dismissed. Counts only while visible and not paused. |
| `dismissible` | `dismissible?: boolean;` | optional, inherited | Shows a close button; Escape on the focused toast also closes it. Default `false`. |
| `progress` | `progress?: boolean;` | optional, inherited | Shows the countdown bar (a CSS animation paused with the timer). |
| `actions` | `actions?: readonly ToastAction[];` | optional, inherited | Buttons in the toast. |
| `className` | `className?: string;` | optional, inherited | Extra class on the toast element. |
| `style` | `style?: CSSProperties;` | optional, inherited | Inline style on the toast element, for example a width. |
| `onOpen` | `onOpen?: ((id: string) => void);` | optional, inherited | Called when the toast enters the visible stack. |
| `onBeforeClose` | `onBeforeClose?: ((event: ToastBeforeCloseEvent) => void);` | optional, inherited | Called before the toast closes; `event.preventDefault()` keeps it. |
| `onClose` | `onClose?: ((event: ToastCloseEvent) => void);` | optional, inherited | Called when the toast closes, with the reason. |
| `onClick` | `onClick?: ((event: MouseEvent<HTMLElement, MouseEvent>) => void);` | optional, inherited | Called on a click anywhere in the toast. |

### ToasterLocaleText

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToasterLocaleText

```ts
interface ToasterLocaleText {
    notifications: string;
    dismiss: string;
}
```

Strings of `Toaster`.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `notifications` | `notifications: string;` |  | Accessible name of the region landmark. Default `"Notifications"`. |
| `dismiss` | `dismiss: string;` |  | Accessible name of the close buttons. Default `"Dismiss"`. |

### ToasterProps

Kind: interface

Page: https://salmonui.dev/docs/reference/notifications/toast/ToasterProps

```ts
interface ToasterProps extends Omit<HTMLAttributes<HTMLElement>, 'children' | 'popover'> {
    queue?: ToastQueue | undefined;
    placement?: ToastPlacement | undefined;
    newestOnTop?: boolean | undefined;
    max?: number | undefined;
    container?: Element | null | undefined;
    hotkey?: boolean | undefined;
    localeText?: Partial<ToasterLocaleText> | undefined;
    children?: ReactNode;
    ref?: Ref<HTMLElement> | undefined;
}
```

Members (9):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `queue` | `queue?: ToastQueue \| undefined;` | optional | The queue to render. Default: a queue the `Toaster` creates, reached with `useToast()`. |
| `placement` | `placement?: ToastPlacement \| undefined;` | optional | Region position. Default `'bottomEnd'`. |
| `newestOnTop` | `newestOnTop?: boolean \| undefined;` | optional | Newest toast first in the stack. Default `true`. |
| `max` | `max?: number \| undefined;` | optional | Visible toasts; the rest wait in the queue. Default 5. |
| `container` | `container?: Element \| null \| undefined;` | optional | Renders the region inside this element (scoped, absolutely positioned; give it `position: relative`) instead of the top layer. `null` renders nothing until the element exists. |
| `hotkey` | `hotkey?: boolean \| undefined;` | optional | F6 moves focus into the region and back. Default `true`. |
| `localeText` | `localeText?: Partial<ToasterLocaleText> \| undefined;` | optional | Overrides of the built-in strings. |
| `children` | `children?: ReactNode;` | optional | Content that can call `useToast()` to reach this queue. |
| `ref` | `ref?: Ref<HTMLElement> \| undefined;` | optional | The region element. |

## Types

### ToastCloseReason

Kind: type

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastCloseReason

```ts
type ToastCloseReason = 'timeout' | 'dismiss' | 'action' | 'programmatic';
```

Why a toast closed.

### ToastPlacement

Kind: type

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastPlacement

```ts
type ToastPlacement = 'topStart' | 'top' | 'topEnd' | 'bottomStart' | 'bottom' | 'bottomEnd';
```

Where the region sits; logical, so `Start` / `End` follow `dir`.

### ToastTone

Kind: type

Page: https://salmonui.dev/docs/reference/notifications/toast/ToastTone

```ts
type ToastTone = 'neutral' | 'primary' | 'info' | 'success' | 'warning' | 'danger';
```

Color role: the neutral scale plus the five theme seeds.
