usmds docs

Alert

Alerts keep users informed of important and sometimes time-sensitive changes.

Installation

npx usmds add alert

Usage

import { Alert } from '@components/Alert';
 
// Basic usage
<Alert
  variant="info"
  title="Alert message"
  description={{
    body: 'Basic alert message'
  }}
/>
 
// With link
<Alert
  variant="info"
  title="Alert message"
  description={{
    body: 'Additional context and followup information including ',
    link: 'a link'
  }}
/>

Props

Alert

Extends View props.

PropTypeDefaultDescription
variant'info' | 'error' | 'warning' | 'success' | 'emergency''info'Determines the color scheme and style of the alert.
alertStyle'default' | 'no-header' | 'list' | 'slim' | 'no-icon''default'Controls the layout and appearance of the alert.
titlestring-The main heading text of the alert.
descriptionAlertDescription-Content configuration for the alert body.
showIconbooleantrueControls the visibility of the alert icon.
classNamestring-Additional CSS classes to apply to the alert.

AlertDescription

PropertyTypeDescription
titlestringOptional title text for no-header and slim variants.
bodystringMain content text of the alert.
linkstringOptional link text to be displayed.
messagesArray<AlertMessage>Array of messages for list-style alerts.

AlertMessage

PropertyTypeDescription
textstringThe main text content of the message.
linkstringOptional link text within the message.
suffixstringOptional text to appear after the link.

Variants

Info Alert

<Alert variant='info' title='Info alert' description={{ body: 'This is an informational alert.' }} />

Error Alert

<Alert variant='error' title='Error alert' description={{ body: 'This is an error alert.' }} />

Warning Alert

<Alert variant='warning' title='Warning alert' description={{ body: 'This is a warning alert.' }} />

Success Alert

<Alert variant='success' title='Success alert' description={{ body: 'This is a success alert.' }} />

Emergency Alert

<Alert variant='emergency' title='Emergency alert' description={{ body: 'This is an emergency alert.' }} />

Alert Styles

Default

<Alert
  variant='info'
  alertStyle='default'
  title='Default alert'
  description={{
    body: 'Standard alert with icon and header.'
  }}
/>

No Header

<Alert
  variant='info'
  alertStyle='no-header'
  description={{
    title: 'Compact message',
    body: 'Alert without separate header section.'
  }}
/>

List

<Alert
  variant='info'
  alertStyle='list'
  title='List alert'
  description={{
    messages: [
      {
        text: 'First message with ',
        link: 'a link',
        suffix: ' and more text.'
      },
      {
        text: 'Second message item.'
      }
    ]
  }}
/>

Slim

<Alert
  variant='info'
  alertStyle='slim'
  description={{
    title: 'Slim alert',
    body: 'Compact version with smaller icon.'
  }}
/>

No Icon

<Alert
  variant='info'
  alertStyle='no-icon'
  description={{
    title: 'No icon alert',
    body: 'Alert without an icon.'
  }}
/>

On this page