Pricing

The Alert component is used to display important messages to users, such as warnings, errors, or success messages. It can include an icon, title, description, and action buttons.

import { CheckCircle2Icon } from "lucide-react"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertDemo() {

Installation

pnpm slabui add alert

Usage

import {
  Alert,
  AlertAction,
  AlertButton,
  AlertButtonIcon,
  AlertContent,
  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
โ”œโ”€โ”€ AlertContent
โ”œโ”€โ”€โ”€โ”€ AlertTitle
โ”œโ”€โ”€โ”€โ”€ AlertDescription
โ”œโ”€โ”€ AlertAction
โ””โ”€โ”€โ”€โ”€  Button

Examples

Basic

A basic alert with an icon, title and description.

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertBasic() {
  return (
    <div className="grid w-full max-w-md items-start gap-4 scr">

Variants

Use variant to change the appearance of the alert.

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertVariants() {
  return (
    <>

Action

Use AlertAction and Button to add a button or other action element to the alert.

import { InfoIcon, X } from "lucide-react"

import {
  Alert,
  AlertAction,

With Icons

Use svg Icon to add an icon to the alert button.

import { InfoIcon } from "lucide-react"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertBasic() {

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 { CheckCircle2 } from "lucide-react"

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"

export function AlertCustom() {

API Reference

Alert

The Alert component displays a callout for user attention.

PropDefaultType
variantdefaultdefault | primary | danger | success | warning | inverted

AlertTitle

The AlertTitle component displays the title of the alert.

PropDefaulttype
className-string

AlertDescription

The AlertDescription component displays the description or content of the alert.

PropDefaultType
className-string

AlertAction

The AlertAction component displays an action element (like a button) positioned absolutely in the top-right corner of the alert.

PropDefaultType
className-string