Alert
A callout for something to notice, like an error.
Your changes are saved
They'll show up on your profile in a minute.
alert-demo.tsx
import { Alert, AlertDescription, AlertTitle } from './ui/alert.tsx'
export default () => (
<Alert style="max-width: 28rem">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="10" />
<path d="m9 12 2 2 4-4" />
</svg>
<AlertTitle>Your changes are saved</AlertTitle>
<AlertDescription>They'll show up on your profile in a minute.</AlertDescription>
</Alert>
)
Installation
dui add alertOr copy ui/alert.tsx and ui/alert.css into your project, with lib/jsx/jsx-runtime.ts, lib/jsx/jsx-dev-runtime.ts, lib/css.d.ts, and lib/theme.css.
Examples
Destructive
Your payment didn't go through
Check your card's details and try again:
- Is the card number right?
- Has the card expired?
alert-destructive.tsx
import { Alert, AlertDescription, AlertTitle } from './ui/alert.tsx'
export default () => (
<Alert variant="destructive" style="max-width: 28rem">
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="10" />
<path d="M12 8v4" />
<path d="M12 16h.01" />
</svg>
<AlertTitle>Your payment didn't go through</AlertTitle>
<AlertDescription>
<p>Check your card's details and try again:</p>
<ul style="margin: 0; padding-left: 1rem">
<li>Is the card number right?</li>
<li>Has the card expired?</li>
</ul>
</AlertDescription>
</Alert>
)
Title only
A new version is out. Reload to update.
alert-title-only.tsx
import { Alert, AlertTitle } from './ui/alert.tsx'
export default () => (
<Alert style="max-width: 28rem">
<AlertTitle>A new version is out. Reload to update.</AlertTitle>
</Alert>
)
Compared to shadcn/ui
- The same parts, variants, and grid: an icon, if the alert starts with an <svg>, gets the first column.
- Bring your own icons as inline SVG: there's no
lucide-react.