Alert
Present an inline message with a title and optional actions.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/alertComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/cardUsage
import { Alert, AlertTitle } from "@/siteplane/components/alert";
<Alert>
<AlertTitle>Changes saved</AlertTitle>
</Alert>;Composition
Alert
├── icon (optional)
├── AlertTitle
├── AlertDescription
├── AlertAction
└── AlertClose (optional)Place the icon directly under Alert, before the title; the alert then reserves a column for it.
Variants
Choose a semantic variant, pair it with a matching icon and state the status in the text. The variant also sets the role. A default, info or success alert is a polite status, and an error or warning alert is an alert that a screen reader announces at once. Pass role to change it.
With actions
Put buttons in AlertAction. They sit beside the message on larger screens and below it on small screens; connect their callbacks in your application.
Page banner
Use layout="banner" for something that concerns the whole page, such as customers who can't book, at the top of the page above its header. The banner takes the tint of its tone across the full width, with a hairline below it, a short title and one short sentence. Only the icon carries the tone; the title stays in the primary text color.
The action of a banner is always a text link in the primary text color, underlined. The standard places it at the end of the row, in AlertAction (Button variant="link" profile="inline"). The icon, the text, the action and the close control stand on one row while the banner's own width allows it. Below 32rem of its own width, the icon and the close control sit on the title's line, the text runs between them and the action goes under the text.
The same link can also end the sentence, so the banner stays two lines high. The link keeps its words together. A text action never reads like a red delete button, also on an error banner.
Card band
Use layout="band" for a problem that belongs to one card. Place the Alert directly under the CardHeader: it runs across the card's full width, starts its icon where the card's text starts and lays out by its own width, not the window's. It takes the action at the end or the link in the text, like a banner.
Closing
AlertClose adds the kit's ghost close control, labelled "Close". It closes the Alert, which glides up and fades out with the kit's motion while the content below moves up; with reduced motion it closes at once. When focus was inside the Alert, it moves to the next element after it, never to the page. The Alert closes by itself, or set open and onOpenChange to decide in your application how long it stays closed. An inline Alert with AlertClose needs defaultOpen or open to collapse with motion.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
Alert. | default | info | success | warning | error | default | Color treatment. |
Alert. | inline | banner | band | inline | A surface in the content flow, a band across the top of a page, or a band at the top of a Card. |
Alert. | boolean | unset | Shows the Alert, controlled. Closing collapses it with the kit's motion. |
Alert. | boolean | true | Shows the Alert at first, uncontrolled. |
Alert. | (open: boolean) => void | unset | Called with false when AlertClose closes the Alert. |
Alert | string | Close | The accessible name of the close control. |
Alert. | ARIA role | alert for error and warning, status otherwise | Default, info and success are a polite status. Pass a role to override it. |
The four text and action parts accept native div attributes, refs, children and
string className, and AlertClose accepts native button attributes. Alert
owns the surface, the grid and the open state; AlertTitle is the emphasized
text; AlertDescription lays out supporting content; AlertAction places
actions beside the message on larger screens and below on smaller screens;
AlertClose closes the Alert. Titles are divs, not semantic headings. There is
no timer.
Usage notes
Reserve assertive alert announcements for urgent changes. Keep a clear recovery action for errors, and do not announce all static informational messages as alerts.