[ Feedback ]
Alert
An inline message that draws attention to important information without interrupting the user. Four semantic variants, each with a matching icon, an optional title and an optional close button.
3 examplesDark modeAccessible
Import#
import { Alert } from 'reusify-ui';When to use#
- Page- or section-level messages that should stay visible, such as "Your trial ends in 3 days".
- Form-level errors summarizing what went wrong.
- For short confirmations that disappear on their own ("Saved!"), use a Toast.
Examples#
Variants#
Heads up
A new version is available.
Payment received
Your invoice has been paid.
Trial ending
Your trial ends in 3 days.
Deploy failed
Build exited with code 1.
<Alert variant="info" title="Heads up">A new version is available.</Alert>
<Alert variant="success" title="Payment received">Your invoice has been paid.</Alert>
<Alert variant="warning" title="Trial ending">Your trial ends in 3 days.</Alert>
<Alert variant="danger" title="Deploy failed">Build exited with code 1.</Alert>Dismissible#
Passing onClose shows a close button. You decide what to do, usually hide the alert.
Storage almost full
You have used 90% of your 5 GB. Upgrade to keep uploading.
const [open, setOpen] = useState(true);
{open && (
<Alert variant="warning" title="Storage almost full" onClose={() => setOpen(false)}>
You have used 90% of your 5 GB. Upgrade to keep uploading.
</Alert>
)}Without title / custom icon#
Title is optional. Pass icon to replace the default icon, or icon={false} to hide it.
Changes are saved automatically.
🎉
You shipped your first component!
No icon here.
<Alert>Changes are saved automatically.</Alert>
<Alert variant="success" icon="🎉">You shipped your first component!</Alert>
<Alert variant="danger" icon={false}>No icon here.</Alert>API reference#
<Alert />
Also accepts every <div> attribute.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'info' | 'success' | 'warning' | 'danger' | 'info' | Color and default icon. |
title | ReactNode | - | Bold first line. |
children | ReactNode | - | Message body. |
icon | ReactNode | false | - | Custom icon, or false to hide it. |
onClose | () => void | - | Shows a dismiss button that calls this. |
variant'info''info' | 'success' | 'warning' | 'danger'Color and default icon.
title-ReactNodeBold first line.
children-ReactNodeMessage body.
icon-ReactNode | falseCustom icon, or false to hide it.
onClose-() => voidShows a dismiss button that calls this.
Accessibility#
- warning and danger use role="alert" (announced immediately); info and success use role="status" (announced politely).
- The close button has the label "Dismiss".