Alert

An inline message about the content around it, in five tones, with optional actions and dismissal.

Status: beta. Category: Feedback.

import { Alert } from '@glyphui/ui'

Exports: Alert, alertStyles.

Notes

  • Danger and warning alerts use role="alert" and are announced immediately; other tones use role="status".
  • For page-wide announcements use Banner; for messages that disappear on their own use a toast.

Example: Tones

import { Alert } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="grid gap-3">
      <Alert title="Heads up">Workspace settings now live under your profile.</Alert>
      <Alert tone="info" title="Scheduled maintenance">
        The API will be read-only on Sunday from 02:00 to 03:00 UTC.
      </Alert>
      <Alert tone="success" title="Domain verified">
        acme.dev now serves your workspace.
      </Alert>
      <Alert tone="warning" title="Trial ends in 3 days">
        Add a payment method to keep your projects.
      </Alert>
      <Alert tone="danger" title="Payment failed">
        Your card was declined. Update it to avoid losing access.
      </Alert>
    </div>
  )
}

Example: Actions and dismiss

Pass onDismiss to show a close button.

import { Alert, Button } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [open, setOpen] = useState(true)
  if (!open) {
    return (
      <Button variant="outline" onClick={() => setOpen(true)}>
        Show alert again
      </Button>
    )
  }
  return (
    <Alert
      tone="info"
      title="A new version is available"
      action={
        <Button size="sm" variant="outline">
          Update
        </Button>
      }
      onDismiss={() => setOpen(false)}
    >
      Version 2.4 adds keyboard shortcuts.
    </Alert>
  )
}

Example: Outline

import { Alert } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="grid gap-3">
      <Alert variant="outline" tone="success" title="Backup complete">
        12,481 files saved at 09:41.
      </Alert>
      <Alert variant="outline" tone="danger" title="Build failed" icon={false}>
        3 type errors in <code>src/app.tsx</code>.
      </Alert>
    </div>
  )
}

Live page: https://glyphui.xyz/components/alert