Alert

Web/Mobile

Displays a callout for user attention with title, description, icon, and optional action.

Installation

pnpm dlx cubix-ui@latest add alert --base radix

Usage

Import
import { CircleCheckIcon, InfoIcon } from "lucide-react"

import { Alert, AlertDescription, AlertTitle } from "@/components/cubix/alert"
Example
<div className="grid w-full max-w-xl gap-4">
  <Alert>
    <CircleCheckIcon />
    <AlertTitle>پرداخت موفق</AlertTitle>
    <AlertDescription>
      پرداخت ۲۹٫۹۹ دلاری شما انجام شد. رسید به نشانی ایمیل ارسال شده است.
    </AlertDescription>
  </Alert>
  <Alert>
    <InfoIcon />
    <AlertTitle>قابلیت جدید در دسترس است</AlertTitle>
    <AlertDescription>
      حالت تاریک اضافه شده. می‌توانید آن را از تنظیمات حساب فعال کنید.
    </AlertDescription>
  </Alert>
</div>

Composition

Place an optional icon, then AlertTitle and AlertDescription. Put buttons or dismiss controls in AlertAction so they sit in the top-end corner.

Structure
Alert
├── Icon
├── AlertTitle
├── AlertDescription
└── AlertAction

Accessibility

The root renders role="alert" so assistive tech announces the message when it appears. Keep the title short, and give dismiss buttons a clear aria-label.

Examples

Basic

A basic alert with an icon, title, and description.

Destructive

Pass variant="destructive" for error and failure callouts. The shipped styles use the destructive token - no extra color classes required.

Action

Use AlertAction to add a button or other control in the top-end corner.

Dismissible

Combine AlertAction with local state to let the user dismiss the alert.

Custom colors

Override the surface with className when you need a one-off tone such as a warning palette.

API Reference

Note: Parts render data-slot attributes (alert, alert-title, alert-description, alert-action) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

Alert

PropTypeDefaultDescription
variant"default" | "destructive""default"The visual style of the alert.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
...propsReact.ComponentProps<'div'>-All native div attributes (role, id, aria-*, ...) are forwarded to the rendered element.

AlertTitle

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDescription

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertAction

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).