A short, prominent message calling out information.
Heads up
You can add components to your app using the CLI.
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
export default function AlertDemo() {
return (
<Alert className="max-w-md">
<InfoIcon />
<AlertTitle>Heads up</AlertTitle>
<AlertDescription>You can add components to your app using the CLI.</AlertDescription>
</Alert>
)
}
function InfoIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" {...props}>
<circle cx="12" cy="12" r="10" />
<path d="M12 16v-4M12 8h.01" />
</svg>
)
}
Installation
pnpm dlx shadcn@latest add https://kagadmodyaa.vercel.app/r/alert.jsonNeeds a React + Tailwind project set up with shadcn. Copies the component source straight into your project, so you can edit it.
Alert imports cn() from lib/utils.ts — add it too if you don't have it yet:
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Usage
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
<Alert>
<InfoIcon />
<AlertTitle>Heads up</AlertTitle>
<AlertDescription>You can add components to your app using the CLI.</AlertDescription>
</Alert>Examples
Destructive
Something went wrong
Your session has expired. Please sign in again.
import { Alert, AlertTitle, AlertDescription } from '@/components/ui/alert'
export default function AlertDestructive() {
return (
<Alert variant="destructive" className="max-w-md">
<AlertTriangleIcon />
<AlertTitle>Something went wrong</AlertTitle>
<AlertDescription>Your session has expired. Please sign in again.</AlertDescription>
</Alert>
)
}
function AlertTriangleIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" {...props}>
<path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z" />
<path d="M12 9v4M12 17h.01" />
</svg>
)
}
API Reference
| Name | Type | Default | Description |
|---|---|---|---|
| variant | 'default' | 'destructive' | 'default' | Visual style of the alert. |
| ...props | React.HTMLAttributes<HTMLDivElement> | — | Every native div attribute. role="alert" is set automatically. |