Say what just happened
import { Button } from "@senvenli/react/action";
import { toast } from "@senvenli/react/overlay";
export default function Example() {
return <Button onPress={() => toast.success("Order confirmed", { description: "ORD-1040 · email sent to the customer" })}>Confirm order</Button>;
}import { Toaster } from "@senvenli/react/overlay";Examples
Tones
Success, information and danger. A danger toast stays until it is dismissed.import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { toast } from "@senvenli/react/overlay";
export default function Example() {
return (
<Stack direction="horizontal" space="space-100">
<Button onPress={() => toast.success("Changes saved")}>Success</Button>
<Button onPress={() => toast.information("Export started", { description: "You get an email when the file is ready." })}>Information</Button>
<Button onPress={() => toast.danger("Upload failed", { description: "The file is larger than 10 MB." })}>Danger</Button>
</Stack>
);
}With an action
One link at most: undo a reversible step, or view the result.import { Button } from "@senvenli/react/action";
import { toast } from "@senvenli/react/overlay";
export default function Example() {
return (
<Button
iconBefore="archive"
onPress={() =>
toast({
title: "Project archived",
description: "Atlas moved to the archive.",
action: { label: "Undo", onPress: () => toast.success("Project restored") },
})
}
>
Archive project
</Button>
);
}Kept until dismissed
A timeout of 0 keeps a toast until it is dismissed; its key dismisses it from code.import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { toast } from "@senvenli/react/overlay";
import { useRef } from "react";
export default function Example() {
const key = useRef<string | null>(null);
return (
<Stack direction="horizontal" space="space-100">
<Button
onPress={() => {
if (key.current) toast.dismiss(key.current);
key.current = toast({ title: "Import started", description: "1,204 customers · this can take a minute.", timeout: 0 });
}}
>
Start import
</Button>
<Button variant="subtle" onPress={() => key.current && toast.dismiss(key.current)}>
Dismiss it
</Button>
</Stack>
);
}Following a promise
`toast.promise`: a spinner while it runs, then the success or the error in place.import { Button } from "@senvenli/react/action";
import { toast } from "@senvenli/react/overlay";
// One toast for a task that takes a moment: a spinner while it runs, then the result in place.
export default function Example() {
const save = () => new Promise<string>((resolve) => setTimeout(() => resolve("ORD-0914"), 1500));
return (
<Button
variant="primary"
onPress={() =>
void toast.promise(save(), {
loading: "Saving the order…",
success: (id) => `Order ${id} saved`,
error: "The order was not saved",
})
}
>
Save order
</Button>
);
}Guidelines
When to use it
- Confirming an action that finished: saved, sent, deleted (with Undo).
Use something else when
- The message must stay until resolved. Banner
Do and avoid
- Write in the past tense: "Order confirmed".
Accessibility
Built in
- Announced politely; danger toasts stay until dismissed.
- The provider mounts the toast region once.