Components
Toast
Built on Base UIBrief messages shown from anywhere with a function call. Mount the Toaster once.
Installation
npx nook-ui@latest add toastPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Toast" component to this project, exactly as Nook ships it.
Brief messages shown from anywhere with a function call. Mount the Toaster once.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add toast`. It writes `components/ui/toast.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/toast.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import { Button } from "@/components/ui/button";
import { Toaster, toast } from "@/components/ui/toast";
export default function ToastDefault() {
return (
<div className="flex flex-wrap gap-3">
<Button variant="outline" onClick={() => toast({ title: "Changes saved", description: "Your profile is up to date." })}>
Show toast
</Button>
<Button variant="outline" onClick={() => toast({ variant: "destructive", title: "Upload failed", description: "The file is larger than 10 MB." })}>
Show error
</Button>
<Toaster />
</div>
);
}
```
API
- `Toaster`: Mount once near the root of your app.
- `position` (`"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"`, default "bottom-right"): Where toasts stack.
- `timeout` (`number`, default 5000): Default milliseconds before a toast closes.
- `className` (`string`): Classes for the viewport.
- `toast(options)`: Show a toast. Returns its id.
- `title` (`ReactNode`): Short heading.
- `description` (`ReactNode`): Supporting text.
- `variant` (`"default" | "success" | "info" | "warning" | "destructive" | "loading"`, default "default"): Icon and announcement priority. A warning has a dashed edge and an alert mark, not a color.
- `action` (`{ label: string; onClick: () => void }`): A button in the toast, such as Undo. The toast closes when it is pressed.
- `timeout` (`number`): Override the default. Use 0 to keep it until dismissed.
- `toastPromise(promise, messages)`: One toast that shows a loader while the promise runs, then the result. Returns the promise.
- `loading` (`ToastOptions`): Shown while the promise is pending.
- `success` (`ToastOptions | (value) => ToastOptions`): Shown when it resolves.
- `error` (`ToastOptions | (reason) => ToastOptions`): Shown when it rejects.
- `dismissToast(id?)`: Close one toast, or all when no id is given.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Toasts live in a polite live region. Destructive toasts are high priority. Press F6 to jump to the region; do not use toasts for information that must not be missed.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import { Button } from "@/components/ui/button";
import { Toaster, toast } from "@/components/ui/toast";
export default function ToastDefault() {
return (
<div className="flex flex-wrap gap-3">
<Button variant="outline" onClick={() => toast({ title: "Changes saved", description: "Your profile is up to date." })}>
Show toast
</Button>
<Button variant="outline" onClick={() => toast({ variant: "destructive", title: "Upload failed", description: "The file is larger than 10 MB." })}>
Show error
</Button>
<Toaster />
</div>
);
}Examples
Undo, info, warning and position
Following a task
The button shows it is working, and one toast goes from loading to the result.
With an action
Stays until dismissed
Positions
Props
Toaster
Mount once near the root of your app.
| Prop | Type | Default | Description |
|---|---|---|---|
| position | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "bottom-right" | Where toasts stack. |
| timeout | number | 5000 | Default milliseconds before a toast closes. |
| className | string | – | Classes for the viewport. |
toast(options)
Show a toast. Returns its id.
| Prop | Type | Default | Description |
|---|---|---|---|
| title | ReactNode | – | Short heading. |
| description | ReactNode | – | Supporting text. |
| variant | "default" | "success" | "info" | "warning" | "destructive" | "loading" | "default" | Icon and announcement priority. A warning has a dashed edge and an alert mark, not a color. |
| action | { label: string; onClick: () => void } | – | A button in the toast, such as Undo. The toast closes when it is pressed. |
| timeout | number | – | Override the default. Use 0 to keep it until dismissed. |
toastPromise(promise, messages)
One toast that shows a loader while the promise runs, then the result. Returns the promise.
| Prop | Type | Default | Description |
|---|---|---|---|
| loading | ToastOptions | – | Shown while the promise is pending. |
| success | ToastOptions | (value) => ToastOptions | – | Shown when it resolves. |
| error | ToastOptions | (reason) => ToastOptions | – | Shown when it rejects. |
dismissToast(id?)
Close one toast, or all when no id is given.
Accessibility
Toasts live in a polite live region. Destructive toasts are high priority. Press F6 to jump to the region; do not use toasts for information that must not be missed.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.