Feedbackui
Alert
Inline callout in default, info, success, warning, and destructive tones.
Node.js 20 reaches end of life on April 30
Projects on Node.js 20 will build with Node.js 22 after that date.
Preview branches are on
Every pull request gets its own database branch.
Domain verified
app.acme.dev is serving traffic with a valid certificate.
You have used 85% of your compute
Upgrade to avoid suspension at the end of the period.
Build failed
Type error in app/page.tsx on line 14.
Installation
npx shadcn@latest add @particular/alertnpm dependencies
- class-variance-authority@^0.7.1
- cn@^0.4.0
Source
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
const alertVariants = cva(
"group/alert relative grid w-full gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default: "bg-card text-card-foreground",
destructive:
"bg-card text-destructive *:data-[slot=alert-description]:text-destructive *:[svg]:text-current",
success:
"border-success/25 bg-success-subtle text-success *:data-[slot=alert-description]:text-success",
warning:
"border-warning/25 bg-warning-subtle text-warning *:data-[slot=alert-description]:text-warning",
info: "border-info/25 bg-info-subtle text-info *:data-[slot=alert-description]:text-info",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Alert({
className,
variant,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/>
)
}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
function AlertDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-description"
className={cn(
"text-sm text-balance text-muted-foreground md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_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 }