Components
Promise Toast
A toast that follows a task from loading to done.
<PromiseToast promise={task} loading="Publishing…" success="Published" error="Couldn't publish" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/promise-toast.jsonimport { PromiseToast } from "@/components/promise-toast"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Pass a promise and it follows the task: a spinner while it runs, then a tick or a cross with your message, then it leaves on its own. Pass a new promise to show it again. It sits fixed in the bottom-right corner of the window and announces itself politely to screen readers.
import { PromiseToast } from "@/components/promise-toast";
export function PublishButton() {
const [task, setTask] = useState<Promise<unknown> | null>(null);
return (
<>
<button onClick={() => setTask(publish())}>Publish</button>
<PromiseToast promise={task} loading="Publishing…" success="Published" error="Couldn't publish" />
</>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
promise | `Promise | null` | |
loading | string | Shown while it runs. | |
success | string | Shown when it resolves. | |
error | string | Shown when it rejects. | |
onClose | () => void | Called when it leaves. | |
linger | number | 2500 | Milliseconds it stays after settling. |
With reduced motion, the spinner turns slowly and the toast appears without sliding.