Alert
An inline callout for form errors, warnings, and success confirmations — status-colored panels with neobrutalist borders and hard shadows.
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
import {The alert is an inline callout: an icon, a title, a description, and an optional action, arranged on a CSS grid. It's a dependency-free role="alert" div — no primitive underneath, identical across both backends — styled to the neobrutalist recipe: thick borders, hard shadows, and bold type, with a status axis for error, success, warning, and info coloring.
Reach for it when:
- Form and request errors — surface a validation failure or a failed API call right next to the thing that broke.
- Success and status confirmations — "settings saved", "trial expiring", "payment received", colored by the
statusprop. - Callouts with a follow-up — a warning or upgrade notice that carries an
AlertActionbutton ("Enable", "Undo", "Upgrade").
Installation#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/alert.json
Copy and paste the following code into your project.
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
// CSS-grid layout (shadcn-style): drop an icon as a direct child and the alert
// auto-arranges into an icon column + a content column — no manual flex wrapper.
// `has-[>svg]` adds the icon column only when an icon is present. NeoBrutalist
// chrome: hard 2px border, square corners, hard offset shadow.
const alertVariants = cva(
cn(
"group/alert relative grid w-full grid-cols-[0_1fr] items-start gap-y-1 rounded border-2 px-4 py-3 text-left text-sm shadow-md",
"has-[>svg]:grid-cols-[1.25rem_1fr] has-[>svg]:gap-x-3",
"has-data-[slot=alert-action]:pr-14",
"[&>svg]:size-5 [&>svg]:translate-y-0.5 [&>svg]:shrink-0 [&>svg]:text-current"
),
{
variants: {
// shadcn's variant axis (kept for API compatibility). `solid` is a Neobrutalism
// addition.
variant: {
default:
"border-border bg-background text-foreground *:data-[slot=alert-description]:text-muted-foreground",
destructive:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
solid:
"border-border bg-foreground text-background *:data-[slot=alert-description]:text-background/80",
},
// Neobrutalism status axis — additive; overrides the variant's colors when set.
status: {
error:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
success:
"border-green-900 bg-green-300 text-green-900 *:data-[slot=alert-description]:text-green-900/80",
warning:
"border-yellow-900 bg-yellow-300 text-yellow-900 *:data-[slot=alert-description]:text-yellow-900/80",
info: "border-blue-900 bg-blue-300 text-blue-900 *:data-[slot=alert-description]:text-blue-900/80",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Alert({
className,
variant,
status,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
role="alert"
className={cn(alertVariants({ variant, status }), className)}
{...props}
/>
)
}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"col-start-2 min-h-5 font-head text-base leading-tight tracking-tight [&_a]:underline [&_a]:underline-offset-3",
className
)}
{...props}
/>
)
}
function AlertDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-description"
className={cn(
"col-start-2 grid justify-items-start gap-1 text-sm [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p]:leading-relaxed [&_p:not(:last-child)]:mb-4",
className
)}
{...props}
/>
)
}
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-action"
className={cn("absolute top-2 right-2", className)}
{...props}
/>
)
}
export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants }
Update the import paths to match your project setup.
Usage#
import {
Alert,
AlertAction,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert"<Alert>
<InfoIcon />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components and dependencies to your app using the cli.
</AlertDescription>
<AlertAction>
<Button variant="outline">Enable</Button>
</AlertAction>
</Alert>Composition#
Use the following composition to build an Alert:
Alert
├── Icon
├── AlertTitle
├── AlertDescription
└── AlertActionExamples#
Basic#
A basic alert with an icon, title and description.
import { CheckCircle2Icon } from "lucide-react"
import {Destructive#
Use variant="destructive" to create a destructive alert.
import { AlertCircleIcon } from "lucide-react"
import {Action#
Use AlertAction to add a button or other action element to the alert.
import {
Alert,
AlertAction,Custom Colors#
You can customize the alert colors by adding custom classes such as bg-amber-50 dark:bg-amber-950 to the Alert component.
import { AlertTriangleIcon } from "lucide-react"
import {RTL#
To enable RTL support in Neobrutalism.com, see the RTL configuration guide.
"use client"
import * as React from "react"Accessibility#
The alert root renders role="alert", an implicit assertive live region: screen readers announce its content the moment it is inserted into the DOM. The announcement only fires on dynamic insertion — an alert already present at page load is read as ordinary text, so render it conditionally when it should be heard. role="alert" never moves focus; if the user must respond before continuing, use an alert dialog instead, and treat AlertAction as a shortcut rather than the only way forward.
API Reference#
Alert#
The Alert component displays a callout for user attention.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "solid" | "default" |
status | "error" | "success" | "warning" | "info" | - |
status is additive: it overrides the active variant's colors when set.
AlertTitle#
The AlertTitle component displays the title of the alert.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertDescription#
The AlertDescription component displays the description or content of the alert.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertAction#
The AlertAction component displays an action element (like a button) positioned absolutely in the top-right corner of the alert.
| Prop | Type | Default |
|---|---|---|
className | string | - |