Alert
An inline banner for surfacing a status, error, success, or warning inside a page or panel. Four semantic variants (default, destructive, success, warning) drive the border, background tint, and heading color. Compose with AlertTitle and AlertDescription, or pass children directly for a single-line banner.
Preview
Heads up
Your changes have been saved. You can keep editing or close this panel.
Deployment succeeded
The build finished in 42 seconds and is live at the production URL.
Approaching quota
You have used 80% of your monthly request allowance.
Couldn’t save
The server rejected the request. Check your connection and try again.
Installation
npx shadcn@latest add https://craftbits.dev/r/alert.jsonUsage
import { Alert, AlertTitle, AlertDescription } from "@craft-bits/core";
<Alert variant="success">
<AlertTitle>Deployment succeeded</AlertTitle>
<AlertDescription>
The build finished in 42 seconds and is live at the production URL.
</AlertDescription>
</Alert>
<Alert variant="destructive">
<AlertTitle>Couldn’t save</AlertTitle>
<AlertDescription>
The server rejected the request. Check your connection and try again.
</AlertDescription>
</Alert>Single-line banner (no title / description):
<Alert variant="warning">You are approaching your monthly quota.</Alert>Anatomy
- Variant —
default(neutral surface),destructive(red),success(green),warning(amber). Drives border, background tint, and title color. - AlertTitle — heading. Inherits the variant color so
destructivetitles read red,successtitles read green. - AlertDescription — body. Stays in the muted foreground regardless of variant so long bodies remain readable. Wraps with
[text-wrap:pretty].
Props
Alert
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'destructive' | 'success' | 'warning' | 'default' | Semantic variant. Drives border, background, and title color. |
children | ReactNode | required | Alert content — typically AlertTitle + AlertDescription. |
className | string | — | Merged onto the root <div> via cn(). |
AlertTitle / AlertDescription
Both forward all standard HTMLDivElement attributes. className is merged via cn().
Accessibility
- Renders the root as
<div role="alert">so assistive tech announces the content as it appears. - The colored border + tinted background are reinforced by the title's variant color so color is never the only signal of severity.
- No motion to suppress.
Credits
- Extracted from:
algoflashcards(src/platform/ui/alert.tsx). Generalized the source's two-variant CVA (default / destructive) into four semantic variants, dropped theAlertActionslot and the dense shadcn slot selectors, and wrapped each part inforwardRef.