Alert
A message about the page or a task, in one of four tones: info, success, warning and critical. Each tone takes its colors from the color.status.<tone> tokens through the alert.<tone> contract tokens, and each pair passes an APCA check when tokens build. info is neutral ink, like the rest of Todae; a company theme can give it a hue.
On this page
import { Alert, Button, Stack } from '@tounsoo/todae';
import { CircleCheck, CircleX, Info, TriangleAlert } from 'lucide-react';
// Todae ships no icons. These come from Lucide; any icon library works.
export default function AlertTones() {
return (
<Stack.Root>
<Alert.Root tone="info" role="none">
<Alert.Icon>
<Info />
</Alert.Icon>
<Alert.Title>Scheduled maintenance</Alert.Title>
<Alert.Description>Sign-in pauses for ten minutes on Sunday at 02:00 UTC.</Alert.Description>
</Alert.Root>
<Alert.Root tone="success" role="none">
<Alert.Icon>
<CircleCheck />
</Alert.Icon>
<Alert.Title>Invoice paid</Alert.Title>
</Alert.Root>
<Alert.Root tone="warning" role="none">
<Alert.Icon>
<TriangleAlert />
</Alert.Icon>
<Alert.Title>Storage almost full</Alert.Title>
<Alert.Description>You have used 92% of your plan.</Alert.Description>
</Alert.Root>
<Alert.Root tone="critical" role="none">
<Alert.Icon>
<CircleX />
</Alert.Icon>
<Alert.Title>Payment failed</Alert.Title>
<Alert.Description>Update your card to keep your plan.</Alert.Description>
<Alert.Actions>
<Button.Root variant="secondary">Update card</Button.Root>
</Alert.Actions>
</Alert.Root>
</Stack.Root>
);
}
Scheduled maintenance
Invoice paid
Storage almost full
Payment failed
Todae ships no icons. Alert.Icon is a slot: put any icon from your own set in it, and it sits before the text, hidden from assistive technology. The columns follow the parts you render, so an alert without an icon or a close button leaves no gap.
Announcements
Alert.Root is a live region by default: role="status" for info and success, which waits for a pause, and role="alert" for warning and critical, which interrupts. A screen reader announces a live region when its content changes, so for a message that appears after an action, keep the region on the page and change what is inside it. Pass role="none" for a banner that is part of the page from the start and needs no announcement, as the examples above do.
An alert fades in as it appears, over alert.motion.duration.enter and alert.motion.easing.enter, under reduced motion too, and goes at once. Its text and role are there from the first frame, so the fade holds back no announcement, and an alert whose text changes in place doesn't fade again.
Alert.Close is a ghost Button.Root. It is named "Dismiss" unless its own text, such as "Got it", names it. That default is the dismiss string of StringsProvider, English unless you set it; a non-empty aria-label still wins. The alert has no open state; remove it in onClick.
import { Alert, Button, Stack } from '@tounsoo/todae';
import { useRef, useState } from 'react';
export default function AlertDismissible() {
const [shown, setShown] = useState(false);
const saveRef = useRef<HTMLButtonElement>(null);
return (
<Stack.Root>
<Button.Root ref={saveRef} variant="secondary" onClick={() => setShown(true)}>
Save changes
</Button.Root>
{/* The status region stays on the page; only its content changes, so it is announced. */}
<div role="status">
{shown ? (
<Alert.Root tone="success" role="none">
<Alert.Title>Changes saved</Alert.Title>
<Alert.Close
onClick={() => {
// The button is about to go away: give focus somewhere first.
saveRef.current?.focus();
setShown(false);
}}
/>
</Alert.Root>
) : null}
</div>
</Stack.Root>
);
}
Icons
An svg or img directly inside Alert.Icon takes the alert.icon.size token. Alert.Close with no content shows the close glyph: a cross, unless a GlyphsProvider sets one. To use a different icon for one close, put it in a Button.Icon.
import { TriangleAlert, X } from 'lucide-react';
<Alert.Root tone="warning">
<Alert.Icon>
<TriangleAlert />
</Alert.Icon>
<Alert.Title>Storage almost full</Alert.Title>
<Alert.Close onClick={hide}>
<Button.Icon>
<X />
</Button.Icon>
</Alert.Close>
</Alert.Root>
Accessible composition
Todae handles: Alert.Root sets role="status" or role="alert" by tone, as described above, and keeps any role you pass. Alert.Icon is aria-hidden. Alert.Close is a native button with a name: its own text, a non-empty aria-label, or the dismiss string. Todae does not move focus, either when the alert appears or when it goes.
You supply: The message as text, in Alert.Title and Alert.Description. The tone shows only as color and an icon that is hidden, so when it matters, say it in the words, such as "Payment failed". For a message that follows an action, keep a wrapper with the tone's live role (status or alert) mounted and render an Alert.Root with role="none" inside it. When a close button removes the alert, move focus somewhere sensible, such as the control the message was about.
Watch for: Mounting a new live region together with its message, which screen readers may not announce. A wrapper that drops role or the rest props, so role="none" never reaches the root. Removing the alert from its own close button without moving focus, which leaves focus on the page body.
When to use
When: A message about the page or the last action that stays until it is fixed or dismissed: a failed payment, a maintenance window, a saved confirmation next to the form.
When not: A field's own error → ErrorMessage. A choice that blocks the task → Dialog. A count or label on an item → Chip. Hover help → Tooltip.
Props
| Name | Type | Description |
|---|---|---|
tone | "info"| "success"| "warning"| "critical" | Colors from color.status.<tone> through the alert contract tokens. Also picks the default role. Default: "info" |
role | React.AriaRole | Live region role. Pass role="none" for a banner that is on the page from the start. Default: "status" for info and success, "alert" for warning and critical |
children | React.ReactNode | Alert parts, or any content. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Icon graphic from your own icon set. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Title text. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Body content. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Buttons or links. |
| Name | Type | Description |
|---|---|---|
aria-label | string | Accessible name. Text of two or more letters or digits, such as "Got it", names the button by itself. Otherwise the dismiss string from StringsProvider names it, Dismiss in English. Default: "Dismiss" when its text, not counting aria-hidden or SVG parts, has fewer than two letters or digits |
onClick | React.MouseEventHandler<HTMLButtonElement> | Hide the alert here. |