npx shadcn@4.23.1 add @goop/trail-toastToast
FreeA short notice at a corner of the app that confirms an action and goes by itself, with an optional action such as Undo, for React and Tailwind CSS. Free, MIT.
What an agent sees
- ToastIndicatorA status icon at the toast's start, a pack icon by its name
- ToastActionThe link a notice ends with (
action={<ToastAction href>Words</ToastAction>}) - ToastButtonA button a notice ends with (
action={<ToastButton onClick>Undo</ToastButton>}) - ToasterThe toast region, mounted once near the root of the app, or once per named region (
id) - toastShows a toast card in the app's
Toasterand returns its id
import { ToastIndicator, ToastAction, ToastButton, Toast, Toaster, toast } from '@/components/ui/goop/toast';
import { useState } from 'react';
import { Button, ButtonLabel } from '@/components/ui/goop/button';
function Inbox() {
const [rows, setRows] = useState(['Roadmap', 'Invoices', 'Offsite']);
const [batch, setBatch] = useState<string[]>([]);
const archive = (row: string) => {
const ids = [...batch, row];
setBatch(ids);
setRows((now) => now.filter((id) => id !== row));
toast.undo({
id: 'archive',
title: ids.length === 1 ? 'Conversation archived' : `${ids.length} conversations archived`,
onUndo: () => {
setBatch([]);
setRows((now) => [...now, ...ids]);
// the restored row takes the focus back once it is drawn
requestAnimationFrame(() => document.getElementById(`row-${ids[0]}`)?.focus());
},
onCommit: () => {
setBatch([]);
send(ids);
},
});
};
return (
<ul>
{rows.map((id) => (
<li key={id}>
<Button id={`row-${id}`} variant="ghost" onClick={() => archive(id)}>
<ButtonLabel>Archive {id}</ButtonLabel>
</Button>
</li>
))}
</ul>
);
}
function ExportNotes({ exportNotes }: { exportNotes: () => Promise<{ count: number }> }) {
return (
<>
<Button variant="outline" onClick={() => toast.warning('Recording storage almost full')}>
<ButtonLabel>Check storage</ButtonLabel>
</Button>
<Button
onClick={() =>
toast.promise(exportNotes, {
loading: 'Exporting interview notes',
success: ({ count }) => ({ title: `${count} notes exported`, description: 'They are in your downloads.' }),
error: (reason) => ({ title: 'Couldn’t export the notes', description: String(reason) }),
})
}
>
<ButtonLabel>Export notes</ButtonLabel>
</Button>
</>
);
}Remove a note and press Undo in its toast (or Ctrl/Cmd+Z) within eight seconds: the note comes back where it was and takes the focus. Let the toast go and the removal is kept for good. Raise a plain toast and an error toast; several stack. Pick a look to see one card still: a picture and a link, a status glyph, the error toast with or without its words or a picture. The notes live in the page only; “removed for good” only counts; the picture is a plain block of our own.
When to use
- A short notice at a corner of the app that confirms an action and goes by itself, with an optional action such as Undo.
- Also called: notification or snackbar.
Installation
Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Toast on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.
npx shadcn@4.23.1 add @goop/trail-toastAdd the Goop Toast to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { ToastIndicator, ToastAction, ToastButton, Toast, Toaster, toast } from '@/components/ui/goop/toast';
import { useState } from 'react';
import { Button, ButtonLabel } from '@/components/ui/goop/button';
function Inbox() {
const [rows, setRows] = useState(['Roadmap', 'Invoices', 'Offsite']);
const [batch, setBatch] = useState<string[]>([]);
const archive = (row: string) => {
const ids = [...batch, row];
setBatch(ids);
setRows((now) => now.filter((id) => id !== row));
toast.undo({
id: 'archive',
title: ids.length === 1 ? 'Conversation archived' : `${ids.length} conversations archived`,
onUndo: () => {
setBatch([]);
setRows((now) => [...now, ...ids]);
// the restored row takes the focus back once it is drawn
requestAnimationFrame(() => document.getElementById(`row-${ids[0]}`)?.focus());
},
onCommit: () => {
setBatch([]);
send(ids);
},
});
};
return (
<ul>
{rows.map((id) => (
<li key={id}>
<Button id={`row-${id}`} variant="ghost" onClick={() => archive(id)}>
<ButtonLabel>Archive {id}</ButtonLabel>
</Button>
</li>
))}
</ul>
);
}
function ExportNotes({ exportNotes }: { exportNotes: () => Promise<{ count: number }> }) {
return (
<>
<Button variant="outline" onClick={() => toast.warning('Recording storage almost full')}>
<ButtonLabel>Check storage</ButtonLabel>
</Button>
<Button
onClick={() =>
toast.promise(exportNotes, {
loading: 'Exporting interview notes',
success: ({ count }) => ({ title: `${count} notes exported`, description: 'They are in your downloads.' }),
error: (reason) => ({ title: 'Couldn’t export the notes', description: String(reason) }),
})
}
>
<ButtonLabel>Export notes</ButtonLabel>
</Button>
</>
);
}- Fits: account, app (their recipes).
- Raise a notice with
toast, never by drawing a Toast: every kind takes the title alone or the card's object,toast.success('Saved')ortoast.error({ title: 'Couldn’t save', description: 'The server did not answer.' })(the object also takesaction,idandduration). Mount<Toaster />once for the whole app, in its root layout, never once per page:toast()shows nothing without it. - height, width, padding, gap, corner, border, background, shadow, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| variant | default | info | success | warning | destructive | loading = default |
- Each option with its sentence: toast--options.md
- Types: ToastOptions = Omit<ComponentProps<typeof Toast>, 'id'> & { id?: string | number; duration?: number; toasterId?: string }; UndoToastOptions = Omit<ToastOptions, 'action'> & { onUndo: () => void; onCommit?: () => void; undoLabel?: string; shortcut?: string | false }
| Part | What it is |
|---|---|
| ToastIndicator | A status icon at the toast's start, a pack icon by its name; decorative, as the title says what happened; its props: toast--indicator.md |
| ToastAction | The link a notice ends with (action={<ToastAction href>Words</ToastAction>}); also takes href?: string |
| ToastButton | A button a notice ends with (action={<ToastButton onClick>Undo</ToastButton>}); its props: toast--button.md |
| Toaster | The toast region, mounted once near the root of the app, or once per named region (id); its props: toast--toaster.md |
| toast | Shows a toast card in the app's Toaster and returns its id; toast.error(…) (the toast library's own name) or toast.destructive(…) (the theme's status word) shows the error card; toast.success, toast.warning, toast.info and toast.loading the other kinds |
- Class recipes (cva): toastVariants (Toast)
ToastIndicator
A status icon at the toast's start, a pack icon by its name; decorative, as the title says what happened.
import { ToastIndicator } from '@/components/ui/goop/toast';Options
- icon: IconName — A pack icon name.
Toast: every option
import { Toast } from '@/components/ui/goop/toast';Options
- variant: default (default), info, success, warning, destructive, loading
- title: ReactNode — The notice's few words.
- description?: ReactNode — A line or two under the title.
- mark?: ReactNode — A 16 px
<ToastIndicator icon>at the start, in place of the error toast's red mark; not drawn withmedia. - media?: ReactNode — A 36 px picture of yours at the start, in place of any glyph.
- action?: ReactNode — What the notice ends with: a
ToastActionlink or aToastButton. - closeLabel?: string = 'Close' — The close cross's accessible name.
- kindLabel?: string — The kind's words a screen reader hears before the title ("Error", "Success"… by default); an empty string says none.
- onDismiss?: () => void — Called when the close cross is pressed.
Toaster
The toast region, mounted once near the root of the app, or once per named region (id).
import { Toaster } from '@/components/ui/goop/toast';Options
- id?: string — The region's name: it shows only the notices raised with
toast({ toasterId })of that name.
Motion
- The part sets its own motion: add no transition or animation of your own.
- How the theme moves, and how to move your own parts the same way: Motion.
Notes for AI
Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.