Alert
An inline message in info, success, warning or danger tone.
Use an alert for a message about the page or a task that should stay visible: an error that blocks a form, a warning before an action, a confirmation. For a short message about an action that just happened, use a toast.
import { Alert } from "@aloxe/react";
export default function AlertTones() {
return (
<div className="flex w-full max-w-md flex-col gap-3">
<Alert tone="info" role="note" title="Maintenance on Sunday from 02:00 to 03:00 UTC" />
<Alert tone="success" role="note" title="Payment method updated" />
<Alert tone="warning" role="note" title="Your trial ends in 3 days" />
<Alert tone="danger" role="note" title="The last deploy failed" />
</div>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { Alert } from "@aloxe/react";
<Alert
tone="danger"
title="The last deploy failed"
description="Check the build log for details."
/>Alert is a server component; only a dismissible alert hydrates a small client part.
Examples
With description and actions
description adds detail or the next step. Actions passed as children go under it.
import { Alert, Button } from "@aloxe/react";
export default function AlertWithDescription() {
return (
<Alert
tone="warning"
role="note"
title="Your trial ends in 3 days"
description="Add a payment method to keep your projects and history."
className="w-full max-w-md"
>
<Button size="sm">Add payment method</Button>
<Button size="sm" variant="ghost">
Compare plans
</Button>
</Alert>
);
}Dismissible
dismissible adds a close button. The alert doesn't come back on its own; use onDismiss to remember the choice and to move focus somewhere useful.
import { Alert } from "@aloxe/react";
export default function AlertDismissible() {
return (
<Alert
tone="info"
role="note"
dismissible
dismissLabel="Dismiss tip"
title="Press Ctrl K to search the docs"
className="w-full max-w-md"
/>
);
}Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the actions and the close button, if any. |
| Enter or Space | Activates the focused button. |
- Warning and danger alerts get
role="alert"and are announced right away when they're added. Info and success getrole="status"and are announced politely. - Live regions only announce content added after the page loads. For alerts that are part of the page from the start, pass
role="note", as these examples do. - The tone is shown by the icon and the text as well as the colour.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="alert"].
Alert
| Prop | Type | Default | Description |
|---|---|---|---|
| title (required) | ReactNode | One short line saying what happened. | |
| tone | "info" | "success" | "warning" | "danger" | "info" | Sets the colours, the icon and the default role. |
| description | ReactNode | Detail or the next step, under the title. | |
| children | ReactNode | Actions or a link, under the description. | |
| dismissible | boolean | false | Adds a close button. Only a dismissible alert ships client JavaScript. |
| onDismiss | () => void | Called after the alert closes. Use it to remember the choice and to move focus somewhere useful. | |
| dismissLabel | string | "Dismiss" | Accessible name of the close button. |
| icon | ReactNode | null | Replaces the tone icon; null shows none. | |
| role | AriaRole | Defaults to alert (warning, danger) or status (info, success). Use note for alerts present when the page loads. | |
| className | string | Merged with the default classes. |
Figma
Matches the Alert component. Figma Tone maps to tone, Show description to description and Dismissible to dismissible.
See Figma for where to get the file and how its names map to code.