Toasts are brief, temporary notifications that provide feedback about an operation without interrupting the user's workflow.
Usage
import { Toaster, queue } from '@console/nimbus-ui/core';Architecture
Nimbus uses an imperative, globally accessible toast system. This ensures you can trigger notifications from absolutely anywhere in your application—including outside of the React component tree (like inside Redux thunks, Axios interceptors, or standard utility functions).
1. The <Toaster /> Mount
You must mount the <Toaster /> component exactly once at the very root of your application (e.g., in App.tsx or layout.tsx). This acts as the global visual portal where all toasts render.
import { Toaster } from '@/core/Toast';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<Toaster placement="bottom-right" />
{children}
</body>
</html>
);
}2. The queue API
To trigger a toast, simply import the queue object and call queue.add(). You do not need to wrap your app in complex context providers or use custom hooks. The queue manager handles layout batching, View Transitions, and automatic cleanup behind the scenes.
import { queue } from '@/core/Toast';
// You can call this inside a component, or in a TS file
const handleSave = async () => {
try {
await api.saveData();
queue.add({
title: 'Data saved successfully',
variant: 'success',
});
} catch (error) {
queue.add({
title: 'Failed to save',
description: 'Please try again later.',
variant: 'error',
});
}
};Examples
Primary
The standard method for triggering a toast notification. By default, toasts will automatically dismiss after 5000ms.
Variants
Toasts come in distinct semantic variants. Use these to communicate the exact nature of the notification to the user without relying solely on text.
With Action
You can provide an interactive action block to a toast. This is ideal for
"Undo" functionality or quick inline resolutions. Pressing the action button
will automatically close the toast after executing your callback.
Async
Calling queue.add() returns a unique string key for that specific toast.
You can use this key to update or close the toast programmatically when a
background task completes or fails.
Dynamic Placements
Use the placement prop on the root <Toaster/> component to control the
screen quadrant where notifications spawn.
Custom Delay
Pass a timeout value (in milliseconds) via the second argument configuration object
to override the default 5000ms duration.
Loading
Setting the variant to 'loading' natively disables the auto-dismiss timeout,
making the toast persistent until you explicitly close it using queue.close(key).
Only use this for loading states.
Persistent
Setting the timeout to 'infinity' natively disables the auto-dismiss timeout,
making the toast persistent until you explicitly close it using queue.close(key).
Use this for critical background tasks that require user blocking or waiting.
Close All
API
| Prop | Type | Default | Description |
|---|---|---|---|
| placement | enum | bottom-right |
React Aria