# 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](/docs/components/toast).

```tsx
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

```bash
npm i @aloxe/react @aloxe/tokens
```

Then add the CSS imports from [Installation](/docs/getting-started/installation).

## Usage

```tsx
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.

```tsx
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.

```tsx
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 get `role="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 | Required | Description |
| --- | --- | --- | --- | --- |
| `title` | `ReactNode` |  | Yes | 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](/docs/getting-started/figma) for where to get the file and how its names map to code.
