Clinia UI

Alert

A message that stays on the page until the situation it describes changes.

shadcn docs →

When to use

  • A message about the state of the page that stays until the situation changes: an expiring API key, a failed sync.
  • A form-level error that sums up what to fix.

When not to use

  • A brief confirmation after an action: use Sonner.
  • A choice the user must make before continuing: use Alert Dialog.
  • A short status next to an item: use Badge.

Install

npx shadcn@latest add @clinia/alert

Anatomy

API key expires in 3 days
Rotate it to keep Montreal clinic syncing.
  1. 1Containerdata-slot="alert"border-warning · bg-warning/15 · rounded-lg
  2. 2Icon[data-slot=alert] > svgsize-4 · text-foreground
  3. 3Titledata-slot="alert-title"text-sm · font-medium
  4. 4Action (optional)data-slot="alert-action"absolute · top-2.5 right-3

Clinia rules

  • warning is a bg-warning/15 surface with a warning border and foreground text. The warning colour fails as text (2.30:1), so it never colours the words.
  • destructive and success colour the title, the description and the icon, on the card surface.
  • The title says what happened: Imaging failed to sync, not Error. The description says what to do next.
  • Put the next step in AlertAction, as an outline or ghost button.

Do and don't

Imaging failed to sync
Reconnect the source to resume.
Do say what happened and what to do next.
Error
Something went wrong.
Don't write a title that says nothing about the problem.
API key expires in 3 days
Do use an alert for a state that lasts until it is fixed.
Source saved
Don't use an alert to confirm a one-off action. Use a toast.

States

default
success
warning
destructive
static note · role note
Keys are shown once
Copy the key when you create it. You can't see it again later.

Toggle the site theme to review both themes.

Accessibility

Built in

  • Renders role="alert" by default, so screen readers announce it as soon as it appears, without moving focus. role overrides it.

Your responsibility

  • role="alert" interrupts. For a static note that is part of the content at load, such as a tip in an article, pass role="note": it's read in place and never announced. For a message that appears later but isn't urgent, pass role="status".
  • Don't rely on the variant colour. The title must say it's an error or a warning.
  • Give the action a label that names it: Reconnect source, not Fix.

How to test

  1. With a screen reader on, trigger the alert: it's announced right away, and focus stays where it was.
  2. Press Tab: focus skips the alert itself and lands on any link or button inside it.
  3. Toggle the site theme: every variant's text stays readable in both.

API

PropValuesDefaultDescription
role
React.AriaRole
–

Defaults to alert, which screen readers announce as soon as it appears. Pass note for a static note that is part of the content at load, or status for a message that appears later but isn't urgent.

variant
defaultdestructivesuccesswarning
default

default is neutral. destructive, success and warning carry status.

  • warning A tinted surface with foreground text, because the warning colour fails as text.

All other props come from the native div element.