Alert
ProA message that stays until it's resolved: a form's error, a page's warning, a system notice. Error, info, success, warning and neutral, tonal or outlined. Not an M3 component (@windmorph/react-pro).
import { Alert } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
Alert 16 props
The message.
A short summary above the message.
Makes the title a heading of this level, when the alert heads a section. Left out, the title is a paragraph.
What kind of message it is; picks the colours and the icon.
erroris read at once (role="alert"); the others are a polite status, so passerrorfor a failure the person must act on.tonal(a container colour) oroutlined(quieter).Replaces the severity's icon;
nullshows none.Up to two
Buttons, text or tonal.Whether it's shown. Set it to
false(rather than unmounting the alert) to let it leave: it fades out as its height folds, then unmounts its content and callsonClosed.Moves focus to the alert when it appears, for an error that blocks a form. A keyboard user sees the M3 focus indicator on it.
The alert itself (the live region).
Events
Adds a close button; without it the alert can't be dismissed. Focus leaves the alert before this is called (back to where it was before
autoFocus, else the next control), so hiding the alert here never drops focus to the page.After it has left (
openfalse) and its content is gone.
Text
Its words, for translation. A
LabelsProvidersets them for the whole app.
Classes for each part; they win over the component's own (
cn()).The alert itself (the live region);
classNamegoes here too.The severity's icon.
The title.
The message.
The actions' row.
The close button.
Classes for the root element, merged with the component's own (yours win).
Inline styles for the root element.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
| Severity: info (default), error, success, warning, neutral | Built | Variant · Severities, Form error |
| Variant: tonal and outlined | Built | Variant · Severities |
| With a title | Built | Configuration · Severities, Dismissible |
| With actions | Built | Configuration · Form error |
| Dismissible | Built | Configuration · Dismissible |
Leaving with its exit motion (open={false}) | Built | Configuration · Dismissible |
| A form’s error | Built | Use case · Form error |
Severity: info (default), error, success, warning, neutral
BuiltVariant · Severities, Form error
Variant: tonal and outlined
BuiltVariant · Severities
With a title
BuiltConfiguration · Severities, Dismissible
With actions
BuiltConfiguration · Form error
Dismissible
BuiltConfiguration · Dismissible
Leaving with its exit motion (
Builtopen={false})Configuration · Dismissible
A form’s error
BuiltUse case · Form error
M3 Expressive specs
- Shape
rounded-corner-medium- Variants
tonal, outlined
Theming & tokens
Tonal alerts use the severity's container and on-container roles; outlined ones have no fill and on-surface text, with the border and icon in the severity's colour. A test keeps the text at 4.5:1 in every theme, mode and contrast level. Set the tokens below on an alert or an ancestor (the root carries data-tokens="wm-alert", with data-severity and data-variant picking each one's default), and style the parts with classNames (root, icon, title, message, actions, close). In forced colours every alert keeps a border.
| Variable | Default | Paints |
|---|---|---|
--wm-alert-container | var(--_wm-alert-severity-container)Varies with variant. | The background: the severity's container role (tonal) or transparent (outlined). |
--wm-alert-content | var(--_wm-alert-severity-content)Varies with variant. | The title, message and close button: the severity's on-container role (tonal) or on-surface (outlined). |
--wm-alert-outline | transparentVaries with variant. | The 1px border: transparent (tonal) or the severity's strong role (outlined). |
--wm-alert-icon | var(--_wm-alert-severity-icon)Varies with variant. | The severity's icon: the content colour (tonal) or the severity's strong role (outlined). |
--wm-alert-corner | var(--md-sys-shape-corner-medium) | The corners. |