# Toast

> A notification system: call toast() from anywhere to queue one, mount <Toaster /> once to render the stack — success, error, info and loading variants, an optional action, and accessible live-region announcements.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Overlays
- Tags: overlay, toast, notification, snackbar, live-region, accessibility
- Types: `ToastProps`, `ToasterProps`, `ToasterPosition`, `ToastVariant`, `ToastAction`, `ToastCloseReason`, `ToastOptions`, `ToastItem`
- Docs: https://fancy-ui.rama.app/docs/components/toast
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/toast

## Import

```tsx
import { Toast } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `position` | `"top-left" \| "top-center" \| "top-right" \| "bottom-left" \| "bottom-center" \| "bottom-right"` | `"bottom-right"` | Corner (or edge-center) the <Toaster /> stack anchors to |
| `className` (Svelte `class`) | `string` | — | Additional classes for the viewport that stacks the toasts |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the <Toaster /> root node |
| `sound` | `boolean` | `false` | Plays success or error when a toast of that variant appears, once the user has enabled sound |
| `toast().title` (required) | `string` | — | Primary line of the toast raised by the toast() function |
| `toast().description` | `string` | — | Secondary line, shown under the title |
| `toast().variant` | `"success" \| "error" \| "info" \| "loading"` | `"info"` | Icon, accent colour, and the live region it announces through — error is assertive, everything else polite |
| `toast().duration` | `number` | `5000` | Milliseconds before auto-dismiss; Infinity is sticky. Defaults to Infinity for the loading variant, which has no natural finish time |
| `toast().action` | `{ label: string; onClick: () => void }` | — | A single action button. Auto-dismiss pauses on hover or focus for every toast, with or without one |

## Example

```tsx
import { Button, Toaster, toast } from "fancy-ui-react";

export function ToastExample() {
	return (
		<>
			<Toaster sound />
			<Button
				onClick={() =>
					toast({
						title: "Theme saved",
						description: "CSS copied to the clipboard.",
						variant: "success",
					})
				}
			>
				Show toast
			</Button>
		</>
	);
}
```
