UI.MD

Alert

An inline message with a tone, an optional icon, a title, a body and one action, for a note that stays put inside a page, card or dialog.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/alert.json

Usage

import { Alert } from "@/components/ui/alert"

Examples

Default

The icon sits on the first line of text and takes the tone's colour. Pass an element (<IconInfoCircle />), not a bare component.

Your trial ends Friday
Pick a plan before then to keep your projects and your team.

Tones

Neutral for a tip, info for news, success for a result, warning for something to check, destructive for a failure. Destructive speaks up to screen readers; the rest wait their turn.

Tip
Drag a card to a new column to change its status.
Import queued
We will email you when your 2,400 contacts are in.
Invoice sent
Ava Chen has 30 days to pay.
Two tasks overlap
Design review and Standup are both at 10:00 on Tuesday.

With an action

One action, usually a small Button. It sits beside the title, or under the text when there is no title. Keep it to a single verb.

Flagged for review
This post uses a claim we could not match to a source.

Title or body alone

Either part can stand alone. Without an icon the text runs from the edge.

All changes saved
Only people with the link can see this page.

API Reference

PropTypeDefaultDescription
tone"neutral" | "info" | "success" | "warning" | "destructive""neutral"Fill, text and icon colour together. Each pair clears its contrast in light and dark. destructive sets role="alert"; the others set role="status".
iconReact.ReactNode-An icon element, 16px, on the first line. Hidden from screen readers; the title says what it means.
titleReact.ReactNode-The heading line: what happened, in a few words.
childrenReact.ReactNode-The body. Say what to do next, not what went wrong twice.
actionReact.ReactNode-One action, usually <Button size="xs" variant="soft">. Beside the title, or under the body when there is no title.
rolestring-Overrides the tone's default role.
tone"neutral" | "info" | "success" | "warning" | "destructive" = "neutral"Fill, text and icon colour together. Each pair clears its contrast in light and dark. destructive sets role="alert"; the others set role="status".
iconReact.ReactNodeAn icon element, 16px, on the first line. Hidden from screen readers; the title says what it means.
titleReact.ReactNodeThe heading line: what happened, in a few words.
childrenReact.ReactNodeThe body. Say what to do next, not what went wrong twice.
actionReact.ReactNodeOne action, usually <Button size="xs" variant="soft">. Beside the title, or under the body when there is no title.
rolestringOverrides the tone's default role.