Alert
A message that stays in the page until it stops being true: a warning about a form, a notice about the account, a note above a table. For something brief that appears after an action, use Snackbar.
Install
npx shadcn@latest add @nelumbo/alertVariants
Neutral by default; tonal colors when the message carries meaning. Each variant picks its own icon. Destructive is announced at once (role alert); the others are announced politely (role status).
Title only, and icons
A title alone makes a one-line notice. icon replaces the symbol, and icon={false} removes it.
With actions
One or two buttons, with the action prop or an AlertAction child. Ghost and outline buttons take the alert's text color.
Dismissible
onDismiss adds a close button. The alert collapses and fades out (just a fade with reduced motion), then the callback runs.
Banner
layout="banner" is full width with square corners, for the top of a page or a card. Actions sit on the right on wide screens and drop below the text on narrow ones.
Usage
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"// shadcn's API<Alert variant="destructive"> <AlertTitle>Payment failed</AlertTitle> <AlertDescription>Your card was declined.</AlertDescription></Alert>// Nelumbo: tonal variants, actions, dismiss, banner<Alert variant="warning" onDismiss={() => setSeen(true)}> <AlertTitle>Storage almost full</AlertTitle> <AlertDescription>You've used 92% of your space.</AlertDescription> <AlertAction> <Button size="sm">Upgrade</Button> </AlertAction></Alert><Alert layout="banner" variant="info" action={<Button size="sm">Details</Button>}> <AlertTitle>Scheduled maintenance on Sunday</AlertTitle></Alert>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
variant | "default" | "info" | "success" | "warning" | "destructive" | "brand" | "default" | Neutral, tinted with a status color, or brand (a solid fill, distinct from info for any brand accent) |
layout | "inline" | "banner" | "inline" | Banner: full width, square, actions on the right from sm up |
icon | IconName | ReactNode | false | per variant | info, check_circle, warning, error, campaign; default has none |
action | ReactNode | One or two buttons. <AlertAction> children work the same | |
onDismiss | () => void | Adds a close button; runs after the alert animates out | |
dismissLabel | string | "Dismiss" | Name of the close button |
role | string | "alert" for destructive, else "status" | Override when needed |