DocsAPI Reference
API Reference
Complete options and methods reference for Nudge UI.
toast methods
| Method | Signature | Description |
|---|---|---|
| toast.show() | show(message, options?): string | Show a toast. Returns toast ID. |
| toast.success() | success(message, options?): string | Show a success toast. |
| toast.error() | error(message, options?): string | Show an error toast. |
| toast.warning() | warning(message, options?): string | Show a warning toast. |
| toast.info() | info(message, options?): string | Show an info toast. |
| toast.loading() | loading(message, options?): string | Show a loading spinner toast. |
| toast.dismiss() | dismiss(id: string): void | Remove a toast by ID. |
| toast.clearAll() | clearAll(): void | Remove all toasts immediately. |
| toast.update() | update(id, updates): void | Update an existing toast. |
ToastOptions
| Option | Type | Default | Description |
|---|---|---|---|
| type | "default" | "success" | "error" | "warning" | "info" | "loading" | "custom" | "default" | Visual type of the toast. |
| position | "top-right" | "top-left" | "top-center" | "bottom-right" | "bottom-left" | "bottom-center" | "top-right" | Screen position of the toast stack. |
| autoClose | boolean | true | Auto-dismiss after duration. |
| duration | number (ms) | 4000 | Time before auto-dismiss. Requires autoClose: true. |
| allowHtml | boolean | false | Render message as raw HTML. ⚠️ Sanitize first. |
| title | string | undefined | Optional bold title above the message. |
| onClose | (toast: ToastItem) => void | undefined | Callback fired when the toast is removed. |
| className | string | undefined | Additional CSS class(es) on the toast element. |
| twClass | string | undefined | Additional Tailwind utility class string. |
ToastItem (resolved)
| Field | Type | Description |
|---|---|---|
| id | string | Unique toast identifier. |
| message | string | The toast message text (or HTML if allowHtml). |
| type | ToastType | The resolved toast type. |
| position | ToastPosition | The resolved position. |
| autoClose | boolean | Whether auto-dismiss is active. |
| duration | number | Auto-dismiss duration in ms. |
| allowHtml | boolean | Whether message is rendered as HTML. |
| title | string | Optional title text. |
| createdAt | number | Unix timestamp when the toast was created (Date.now()). |
| exiting | boolean | Internal - true when the exit animation is playing. |
ToasterCore (class)
| Method | Description |
|---|---|
| addToast(message, options?) | Add a toast. Returns ID. |
| updateToast(id, updates) | Update an existing toast's fields. |
| removeToast(id) | Begin exit animation and remove after 280ms. |
| clearAll() | Immediately remove all toasts. |
| subscribe(listener) | Register a listener fn(toasts[]) - returns unsubscribe fn. |
| getToasts() | Returns current toasts snapshot array. |