Alert

A notice that stands out from the page to tell the reader something important.

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { VStack } from "@/components/ui/stack"
import { CheckCircleIcon } from "@phosphor-icons/react/dist/csr/CheckCircle"
import { InfoIcon } from "@phosphor-icons/react/dist/csr/Info"
import { widths } from "@/theme/widths"

export default function AlertDemo() {
  return (
    <VStack gap={4} xstyle={widths.md}>
      <Alert variant="success">
        <CheckCircleIcon aria-hidden="true" />
        <AlertTitle>Invoice paid</AlertTitle>
        <AlertDescription>
          We charged $29.99 to your card and sent the receipt to your billing email.
        </AlertDescription>
      </Alert>
      <Alert variant="info">
        <InfoIcon aria-hidden="true" />
        <AlertTitle>Version history is here</AlertTitle>
        <AlertDescription>
          Open any document and choose History to restore an earlier draft.
        </AlertDescription>
      </Alert>
    </VStack>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/alert

Needs the arene setup first.

Usage

import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
<Alert>
  <InfoIcon />
  <AlertTitle>Two-step sign-in</AlertTitle>
  <AlertDescription>Ask for a code from your phone when you sign in.</AlertDescription>
  <AlertAction>
    <Button variant="outline">Enable</Button>
  </AlertAction>
</Alert>

Composition

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

The icon is any svg passed as a direct child. The alert is a three-column grid, and interop.css places the icon in the first column and the action in the last. Both columns collapse to nothing when empty.

Basic

The default variant with an icon, a title and a description.

import * as stylex from "@stylexjs/stylex"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { CheckCircleIcon } from "@phosphor-icons/react/dist/csr/CheckCircle"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  alert: { maxWidth: width.md },
})

export default function AlertBasic() {
  return (
    <Alert xstyle={styles.alert}>
      <CheckCircleIcon aria-hidden="true" />
      <AlertTitle>Preferences saved</AlertTitle>
      <AlertDescription>
        Your notification settings now apply to every project in this workspace.
      </AlertDescription>
    </Alert>
  )
}

Variants

Use the variant prop to set the tone: default, info, success, warning or destructive. Each is a flat tinted fill with a matching border, and the icon takes the variant's accent colour. The title and description keep the page's own text colours, so every variant reads the same way.

import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { VStack } from "@/components/ui/stack"
import { CheckCircleIcon } from "@phosphor-icons/react/dist/csr/CheckCircle"
import { InfoIcon } from "@phosphor-icons/react/dist/csr/Info"
import { NotePencilIcon } from "@phosphor-icons/react/dist/csr/NotePencil"
import { WarningCircleIcon } from "@phosphor-icons/react/dist/csr/WarningCircle"
import { WarningIcon } from "@phosphor-icons/react/dist/csr/Warning"
import { widths } from "@/theme/widths"

export default function AlertVariants() {
  return (
    <VStack gap={3} xstyle={widths.md}>
      <Alert>
        <NotePencilIcon aria-hidden="true" />
        <AlertTitle>Drafts save automatically</AlertTitle>
        <AlertDescription>Changes are kept for 30 days before they are discarded.</AlertDescription>
      </Alert>
      <Alert variant="info">
        <InfoIcon aria-hidden="true" />
        <AlertTitle>Maintenance on Sunday</AlertTitle>
        <AlertDescription>
          The dashboard will be read-only from 02:00 to 03:00 UTC.
        </AlertDescription>
      </Alert>
      <Alert variant="success">
        <CheckCircleIcon aria-hidden="true" />
        <AlertTitle>Domain verified</AlertTitle>
        <AlertDescription>Email from example.com will now be delivered.</AlertDescription>
      </Alert>
      <Alert variant="warning">
        <WarningIcon aria-hidden="true" />
        <AlertTitle>Your trial ends in 3 days</AlertTitle>
        <AlertDescription>Add a payment method to keep your projects running.</AlertDescription>
      </Alert>
      <Alert variant="destructive">
        <WarningCircleIcon aria-hidden="true" />
        <AlertTitle>Payment failed</AlertTitle>
        <AlertDescription>Check your payment method and try again.</AlertDescription>
      </Alert>
    </VStack>
  )
}

Action

Put a button in AlertAction. It sits in the alert's last column, beside the text.

import * as stylex from "@stylexjs/stylex"
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  alert: { maxWidth: width.md },
})

export default function AlertActionDemo() {
  return (
    <Alert xstyle={styles.alert}>
      <AlertTitle>Offline editing is available</AlertTitle>
      <AlertDescription>Turn it on to keep writing when your connection drops.</AlertDescription>
      <AlertAction>
        <Button size="xs">Enable</Button>
      </AlertAction>
    </Alert>
  )
}

API reference

Pass render to replace a part's element or compose it with another component.

Alert

Renders a div with role="alert", which a screen reader announces as soon as it appears. For a notice that is part of the page, such as a note in an article, pass role="note" instead. Every part also takes xstyle and className.

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

alertStyles

The style map behind the component, exported so you can apply the same styles to any element.

KeyDescription
baseThe grid, padding, border width and type
variantsOne entry per variant, keyed by its name

Data attributes

AttributeOnEffect
data-slot="alert"the rootWhere interop.css keys the icon's grid slot
data-variantthe rootReflects the variant prop
data-slot="alert-title"the titleLinks inside are underlined by interop.css
data-slot="alert-description"the descriptionLinks inside are underlined by interop.css
data-slot="alert-action"the actionTargets the action from a parent

CSS variables

VariableOnEffect
--arene-alert-accentthe rootThe icon's colour. Set by the variant, read by interop.css