components / feedback
Alert
A terminal-style log line for information, success, warnings, or errors.
alert-default.tsx
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
export default function AlertDefault() {
return (
<div className="flex w-full max-w-xl flex-col gap-2">
<Alert variant="info" time="09:41:07">
<AlertTitle>deploy queued</AlertTitle>
<AlertDescription>build 482 waits behind 2 others</AlertDescription>
</Alert>
<Alert variant="success" time="09:41:52">
<AlertTitle>deploy finished</AlertTitle>
<AlertDescription>live on cd-ui.dev in 38s</AlertDescription>
</Alert>
<Alert variant="warn" time="09:42:15">
<AlertTitle>disk almost full</AlertTitle>
<AlertDescription>14 GB left on /dev/sda1</AlertDescription>
<AlertAction>
<Button size="sm" variant="outline">
Clean up
</Button>
</AlertAction>
</Alert>
<Alert variant="error" tag="fatal" time="09:43:01">
<AlertTitle>payment failed</AlertTitle>
<AlertDescription>card declined, retry in 3 attempts</AlertDescription>
</Alert>
</div>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/alert.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
<Alert variant="warn">
<AlertTitle>disk almost full</AlertTitle>
<AlertDescription>14 GB left on /dev/sda1</AlertDescription>
</Alert>API
Alert
One log line: [tag] time title - description, with a colored rule on the left. An icon placed directly inside is allowed. Server component.
| prop | type | default |
|---|---|---|
variantLevel. | "info" | "success" | "warn" | "error" | "info" |
tagText of the level chip. Defaults to the level name. | ReactNode | variant name |
timeOptional timestamp shown after the tag. | ReactNode | - |
classNameExtra classes, merged with | string | - |
AlertTitle · AlertDescription · AlertAction
AlertTitle and AlertDescription share the line, joined by a dash. AlertAction pins a button or link to the right end.
| prop | type | default |
|---|---|---|
classNameExtra classes, merged with | string | - |
Accessibility
warnanderroruserole="alert", announced right away.infoandsuccessuserole="status", announced politely. Passroleto override.