120k

Alert

Displays a callout for user attention.

Installation

pnpm dlx shadcn@latest add @force-ui-vue/alert

Usage

<script setup lang="ts">
import {
  Alert,
  AlertAction,
  AlertDescription,
  AlertTitle,
} from "@/components/ui/alert"
</script>
 
<template>
  <Alert>
    <AlertTitle>Heads up!</AlertTitle>
    <AlertDescription>
      You can add components and dependencies to your app using the cli.
    </AlertDescription>
  </Alert>
</template>

Composition

Use the following composition to build an Alert:

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

Examples

Basic

A basic alert with an icon, title and description.

Destructive

Use variant="destructive" to create a destructive alert.

Status Variants

Use variant="warning", variant="success", or variant="info" for semantic status alerts.

Action

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

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.

API Reference

Alert

The Alert component displays a callout for user attention.

PropTypeDefault
variant"default" | "destructive" | "warning" | "success" | "info""default"

AlertTitle

The AlertTitle component displays the title of the alert.

PropTypeDefault
classstring-

AlertDescription

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

PropTypeDefault
classstring-

AlertAction

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

PropTypeDefault
classstring-