1. Components
  2. Feedback
  3. Alert

Alert

Displays a callout for user attention.

import { Alert } from "@/registry/ui/default/core/alert";

export default function AlertDemo() {
  return <Alert>You can add components to your app using the cli.</Alert>;
}

Installation

npx dotui-cli@latest add alert

Examples

Variants

Use the variant and fill props to change the visual style of the alert.

Variant
<Alert variant={variant} fill={fill}>
  You can add components to your app using the cli.
</Alert>

Title

Use the title prop to add a title to the alert.

<Alert variant="warning" fill title="Your account has been suspended." />

Content

Pass children to the alert to add content.

<Alert title="Payment Information">
  Enter your payment method to complete your purchase.
</Alert>

Custom icon

Use the icon prop to add a custom icon to the alert. An explicit null value can be used to remove the default icon.

<Alert icon={<GlobeIcon />}>Hello world!</Alert>

Action

Use the action prop to add an action to the alert.

<Alert
  action={<Button>Upgrade</Button>}
>
  You are currently on the free plan. Upgrade to unlock more features.
</Alert>

Examples

Composition

If you need to customize things further, you can drop down the composition pattern.

<AlertRoot>
  <WalletIcon />
  <div className="flex-1">
    <AlertTitle>Payment Information</AlertTitle>
    <AlertContent>
      Enter your payment method to complete your purchase.
    </AlertContent>
  </div>
  <Button variant="primary" size="sm">
    Upgrade
  </Button>
</AlertRoot>

API Reference

Alert accepts all HTML div element props and the following:

PropTypeDefaultDescription
variant
'default' | 'success | 'warning' | 'danger | 'info'
'default'
The visual style of the alert.
fill
boolean
false
Weather the visual style should be filled.

Last updated on 10/11/2024