Alert
Slant / Controls
Inline notices with tones, actions, progress and dismissal.
Demo
Usage
import { Alert, Button } from '@tuttn/slant'
<Alert title="Update available" action={<Button variant="primary" size="sm" onClick={install}>Update</Button>}>
A newer version is ready to install.
</Alert>
<Alert title="Installing…" progress={progress}>{progress}% done</Alert>
<Alert tone="warning" title="Checkpoint is 3 days old" onDismiss={dismiss}>
Save progress before handing off.
</Alert>
// Speaks the title (and a string body) through the root's announcer when it
// appears and whenever the title changes; assertive for warning and danger.
<Alert announce tone="danger" title="Sync failed">Check your connection.</Alert>Props
| Prop | Type | Default | Description |
|---|---|---|---|
tone | Tone | 'accent' | Colours the leading pixel and the progress bar; warning and danger also make the alert urgent. |
title | ReactNode | — | The first line. |
children | ReactNode | — | The body copy under the title, in muted text. |
action | ReactNode | — | A trailing control, e.g. a `<Button size="sm">`; takes the place of the dismiss button. |
progress | number | — | Shows a thin progress bar under the body (0–100). |
onDismiss | () => void | — | Adds a trailing dismiss button. |
dismissLabel | string | 'Dismiss' (the root's `messages.dismiss`) | The dismiss button's accessible name. |
announce | boolean | false | Speaks the title, followed by the body when it is a string, through the root's announcer on mount and whenever the title changes: assertively for the warning and danger tones, politely otherwise. The alert then carries no live role, so it is not announced twice. |
role | 'status' | 'alert' | — | The live role when `announce` is off: `alert` for the warning and danger tones, `status` otherwise. Ignored with `announce`. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style and other attributes go on the alert element, which also takes the ref. |
An alert that is on the page from the start is a status (or an alert for warning and danger) region, which screen readers announce when its content changes. One that appears in response to something, like an upload finishing, should pass announce: live regions added to the page are often not read, so the alert speaks through the persistent regions of the nearest <Slant> root instead, and drops its own role so it is not read twice.
Size an action with the Button’s own props; size="sm" matches the dismiss button.