Toast
A short result message, bottom centre.
$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/toast.jsonStatuses
Kontak darurat disimpan
Putri Ramadhani sudah ditambahkan. Undangan login terkirim.
Slip Desember terbit Kamis, 24 Des
Disimpan, tapi 2 karyawan belum lengkap
Koneksi terputus. Perubahan belum tersimpan
Show a toast
When to use
- A Sheet or Dialog closed after saving: "Kontak darurat disimpan".
- A request went to someone else: "Permintaan cuti dikirim ke HR".
- A background job finished: "Slip dikirim ke 43 karyawan".
When not to use
- An error the user must fix → inline field error, or an error line in the Sheet/Dialog.
- A lasting status (Menunggu HR) → Badge or Callout on the page.
- A copy action → the copy button turns into a tick; no toast.
- The change is already visible on screen → nothing.
Do and don't
Say what happened, and to what"Permintaan cuti dikirim ke HR" after Kirim ke HR closes the sheet; the list behind updates at the same time.
"Berhasil!", validation errors"Berhasil!" says nothing. "Tanggal wajib diisi" belongs under the field, not in a toast that disappears after 5 s.
Installation
Add Toast with the shadcn CLI (your project needs a components.json and the MaHR theme: https://mahrdesign.faizintifada.com/r/theme.json), or copy the files by hand.
API
import { toast, Toaster, ToastPill } from "@/components/ui/sonner"| Prop | Type | Default | Description |
|---|---|---|---|
toast.success(message, options?) | (message: string, { action?: { label, onClick } }) => id | – | Also toast.info / toast.warning / toast.danger. Past tense, max 48 characters. One action at most; it closes the toast. With an action: 8 s, else 5 s. |
toast.dismiss(id?) | (id?) => void | – | Close one or all. |
<Toaster offset> | number | 24 | Mounted once in AppShell. 96 on screens with a pager. |
ToastPill status · message · action · onClose | "success" | "info" | "warning" | "danger" · ReactNode · { label, onClick }? · () => void | – | The pill itself, for previews. |