Toast
Transient notification. 4 types × 2 themes.
import { Button } from "@/components/ui/button";
import { Toast } from "@/components/ui/toast";
export default function Example() {
return <Toast action={<Button size="sm" variant="ghost">Undo</Button>}>Darjeeling tin added to your cart.</Toast>;
}
Installation
$ npx uix-ui@latest add toastThis copies the file into components/ui/toast.tsx in your project. npx shadcn@latest add @uix/toast works too.
Usage
import { Toast } from "@/components/ui/toast";
<Toast action={<Button size="sm" variant="ghost">Undo</Button>}>Darjeeling tin added to your cart.</Toast>
Examples
Types and themes
import { Toast } from "@/components/ui/toast";
export default function Example() {
return (
<div style={{ display: "grid", gap: 12 }}>
<Toast>Saved to your wishlist.</Toast>
<Toast type="success">Order placed. Thank you, Nusrat!</Toast>
<Toast type="warning">Only 2 tins left in stock.</Toast>
<Toast type="error">We could not reach bKash. Try again.</Toast>
<Toast theme="dark" type="success">Dark toast: parcel delivered.</Toast>
</div>
);
}
Dismissing
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Toast } from "@/components/ui/toast";
export default function Example() {
const [items, setItems] = React.useState(["Sylhet green added.", "Masala chai added."]);
return (
<div style={{ display: "grid", gap: 12, width: 360 }}>
{items.map(t => <Toast key={t} type="success" action={<Button size="sm" variant="ghost" onClick={() => setItems(s => s.filter(x => x !== t))}>Dismiss</Button>}>{t}</Toast>)}
{items.length === 0 ? <Button variant="outline" onClick={() => setItems(["Sylhet green added.", "Masala chai added."])}>Bring them back</Button> : null}
</div>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
theme | light | dark | "light" | |
type | default | success | warning | error | "default" | |
action | React.ReactNode | – | Button or link on the right, for example an Undo action. |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx