# Alert

A callout for important messages with default and destructive variants plus title, description, and action primitives for inline feedback.

- Category: Overlays & Navigation
- License: MIT
- Page: https://www.saasuji.com/components/alert
- Install: npx shadcn@latest add https://www.saasuji.com/r/alert.json

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant (Alert) | `"default" | "destructive"` | `"default"` | Color treatment: neutral card surface or destructive border and text. |
| alertVariants | `(props?: { variant?: "default" | "destructive" | null } & { class?: ClassValue }) => string` | — | Exported class-variance-authority helper that composes the alert class names. |
| className (Alert, AlertTitle, AlertDescription, AlertAction) | `string` | — | Additional classes merged onto the part that receives it. |
| children (Alert, AlertTitle, AlertDescription, AlertAction) | `React.ReactNode` | — | Title, description, and action content; an optional icon as the first child switches the layout to an icon column. |
| ...props (Alert, AlertTitle, AlertDescription, AlertAction) | `React.ComponentProps<"div">` | — | All remaining native div attributes are forwarded to the part that receives them. |

## Source

```tsx
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const alertVariants = cva(
  "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:gap-x-3 has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
  {
    variants: {
      variant: {
        default: "bg-card text-card-foreground",
        destructive:
          "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90",
      },
    },
    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(
        "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
        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 text-muted-foreground [&_p]:leading-relaxed",
        className
      )}
      {...props}
    />
  )
}

function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-action"
      className={cn(
        "col-start-2 mt-2 flex flex-wrap items-center gap-2",
        className
      )}
      {...props}
    />
  )
}

export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants }

```
