Skip to main content

Alert

Display contextual feedback, status notices, and announcement banners.

Alert notification
Detailed contextual message providing helpful instructions.
Props
Slots

Anatomy#

Alert [component; slot=root]
├── icon [slot]
├── content [slot]
│   ├── title [slot]
│   └── description [slot]
├── actions [slot]
└── close [slot]

Usage#

Use Alert for inline feedback that stays in the page flow. Choose Toast for transient notifications and BaseDialog for feedback that must block the page. Alert sets role="alert" with aria-live="assertive" for the warning and error types, and role="status" with aria-live="polite" for the rest.

import { Alert } from 'moraine'

export function Example() {
  return <Alert type="info" title="System update available" />
}

Type and variant#

type selects the semantic status: default, info, success, warning, and error. The info, success, warning, and error types render a matching status icon; default renders none. variant selects the surface treatment: subtle (default), soft, outline, and solid.

Description layout#

Pass description for a supporting line below the title. With a description, the root uses larger padding and the title turns bold. children render after the title and description.

<Alert type="warning" title="Storage almost full" description="You have used 85% of your quota." />

Dismissal#

Set closable to render a dismiss button. Clicking it closes the alert, plays the exit animation, and removes the alert from the DOM. Use open with onOpenChange to control visibility, or defaultOpen to start closed. onOpenChange fires only for user dismissal, and onExitComplete fires after the alert leaves the DOM. Override the button’s accessible label (Close alert) with translations={{ close: '...' }}.

const [open, setOpen] = createSignal(true)

<Alert closable open={open()} onOpenChange={setOpen} title="Changes saved" />

Examples#

Show status across every type#

Render one alert per type to compare their colors and status icons.

import { Alert } from 'moraine'

export function Basic() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert type="default" title="Default announcement" />
      <Alert type="info" title="Informational note for users" />
      <Alert type="success" title="Success! Operation completed successfully" />
      <Alert type="warning" title="Warning: Please check your configuration" />
      <Alert type="error" title="Error: An unexpected error occurred" />
    </div>
  )
}

Add a supporting description#

Pass description to explain the title with a second line.

import { Alert } from 'moraine'

export function Description() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="info"
        title="Account verification"
        description="We have sent a verification code to your email. Please confirm it within 24 hours."
      />
      <Alert
        type="success"
        title="Payment received"
        description="Your subscription is now active. Your next billing date is November 21, 2026."
      />
      <Alert
        type="warning"
        title="Storage limit approaching"
        description="You have used 85% of your available storage capacity. Consider upgrading your plan."
      />
      <Alert
        type="error"
        title="Deployment failed"
        description="The build process encountered syntax errors in src/index.ts. Check pipeline logs for details."
      />
    </div>
  )
}

Offer actions#

Put buttons in actions so the reader can respond from the alert.

import { Alert, Button } from 'moraine'

export function Actions() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="info"
        title="Software update available"
        description="Version 2.4.0 includes important performance improvements."
        actions={
          <Button size="sm" variant="outline">
            Upgrade
          </Button>
        }
        closable
      />
    </div>
  )
}

Let the reader dismiss an alert#

Set closable for a dismiss button. Drive visibility with open and onOpenChange.

import { Alert, Button } from 'moraine'
import { createSignal } from 'solid-js'

export function CloseExample() {
  const [open, setOpen] = createSignal(true)

  return (
    <div class="flex flex-col gap-3 h-30 max-w-xl w-full">
      <div>
        <Button variant="outline" size="sm" disabled={open()} onClick={() => setOpen(true)}>
          {open() ? 'Click Icon to Close' : 'Reopen Alert'}
        </Button>
      </div>
      <Alert
        open={open()}
        onOpenChange={setOpen}
        closable
        type="info"
        title="Dismissible notice"
        description="You can close this alert by clicking the close button on the right."
      />
    </div>
  )
}

Span a banner across the page#

Set fullWidth to remove the side borders and corner radius for an edge-to-edge banner.

import { Alert } from 'moraine'

export function FullWidthExample() {
  return (
    <div class="flex flex-col gap-3 w-full">
      <Alert
        fullWidth
        type="warning"
        title="Scheduled maintenance notice"
        description="The platform will undergo scheduled maintenance tonight between 02:00 and 04:00 UTC."
        closable
      />
    </div>
  )
}

Replace or hide the icon#

Pass icon with an icon name or element to override the status icon. Pass icon={false} to hide it.

import { Alert } from 'moraine'

export function CustomIconExample() {
  return (
    <div class="flex flex-col gap-3 max-w-xl w-full">
      <Alert
        type="default"
        icon="icon-tip"
        title="Pro tip"
        description="You can press Ctrl + K to quickly open the command palette from anywhere."
      />
      <Alert
        type="info"
        icon={false}
        title="No icon alert"
        description="This alert has icon={false} to suppress the default status icon."
      />
    </div>
  )
}

API Reference#

Attributes#

Attributes
data-close
Slot: alert
Description: —
data-closed
Slot: alert
Description: Present when disclosure or transition content is closed.
data-expanded
Slot: alert
Description: Present when the panel, accordion, or menu is expanded.
data-full-width
Slot: alert
Description: —
data-has-description
Slot: alert
Description: —
data-type
Slot: alert
Description: —

Props#

Props for Alert. Renders a <div> element by default.

Prop