Components / Core
Alert
Message about the page or a task. warning and danger alerts are announced right away (role="alert"); the others are announced politely.
import { Alert } from "@stylhero/ui";
Example
Code
import { Alert, Button, Stack } from "@stylhero/ui";
function AlertExample() {
return (
<Stack gap={3}>
<Alert title="Saved">Your build is saved to your account.</Alert>
<Alert tone="success" variant="outlined">Payment received.</Alert>
<Alert tone="warning" title="Price changed" action={<Button size="sm" variant="secondary">Review</Button>}>
The GPU is $40 more than when you added it.
</Alert>
<Alert tone="danger" variant="filled" onClose={() => {}}>Couldn't reach the store.</Alert>
</Stack>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
action |
ReactNode |
- | A button on the right, e.g. <Button size="sm" variant="ghost">Undo</Button>. |
icon |
ReactNode |
- | Replace the default icon, or pass null for none. |
onClose |
() => void |
- | Shows a close button. |
title |
ReactNode |
- | |
tone |
"info" | "success" | "warning" | "danger" |
"info" |
|
variant |
"soft" | "outlined" | "filled" |
"soft" |
"filled" is the loud, solid version. |
Also takes every <div> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.
Accessibility
warninganddangeruserole="alert"(announced right away);infoandsuccessuserole="status"(announced when the reader is idle).
Generated from src/components/Alert.tsx. Something wrong or missing? Open an issue.