# Alert

An inline banner with a title, optional body and caller-supplied actions. Use info, success, warning or danger to communicate the kind of message. Static banners are named sections; opt into status or alert for dynamic updates.

**Dependencies:** npm: 1 direct, 2 total; registry: 2 direct, 2 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Show a message that belongs to the current page, such as a saved setting or a failed upload.
- Explain a condition and offer an optional next step beside it.

### When not to use

- A destructive choice that requires confirmation. Use AlertDialog.
- A short message that disappears after an action. Use Toast.
- An empty successful result. Use EmptyState.

### Native

**Default**

```text
WerewolfAlert(title: AnyView(Text("Heads up")))
```

```text
WerewolfAlert { Text("Heads up") }
```

**Warning with body**

```text
WerewolfAlert(title: AnyView(Text("Storage almost full")), variant: .warning, children: AnyView(Text("Free up space soon.")))
```

```text
WerewolfAlert(variant = WerewolfAlertVariant.Warning, children = { Text("Free up space soon.") }) { Text("Storage almost full") }
```

## Variants

### variant

The message type. Each value uses its status soft pair: info, success, warning or danger.

Values: `info`, `success`, `warning`, `danger`. Default: `info`.

## Examples

### Inline guidance

```tsx
<Alert title="Your workspace is ready">Invite a teammate to start reviewing projects together.</Alert>
```

### With an action

```tsx
<Alert variant="warning" title="Storage is nearly full" action={<Link href="#storage">Manage storage</Link>}>Remove unused files before your next upload.</Alert>
```

### Dismissible update

The parent removes the banner when onDismiss runs. Supply a specific accessible name for the close button.

```tsx
<Alert variant="success" title="Changes saved" role="status" dismissible dismissLabel="Dismiss saved changes message" onDismiss={dismissAlert}>Your project settings are up to date.</Alert>
```

## Do and don't

### Do

- Write a short title and explain the next step in the body.
- Use caller-supplied actions to resolve a warning or error.
- Provide dismissLabel and remove the banner in onDismiss when dismissal is allowed.

### Don't

- Do not use Alert for confirmation dialogs; use AlertDialog.
- Do not announce every static banner as an alert.
- Do not rely on the icon or color alone to communicate the message.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `variant` | `enum` | `info`, `success`, `warning`, `danger` | `info` | The message type. Each value uses its status soft pair: info, success, warning or danger. |
| `title` (required) | `node` |  |  | Short heading that names the banner. |
| `icon` | `node` |  |  | Decorative icon replacing the variant icon. null hides the icon. |
| `action` | `node` |  |  | An action such as Button or Link, supplied by the caller. |
| `dismissible` | `boolean` |  | `false` | Shows a dismissal button. true requires dismissLabel and onDismiss. Not generated for iOS and Android. |
| `dismissLabel` | `string` |  |  | Accessible name of the dismissal button, required when dismissible is true. Not generated for iOS and Android. |
| `onDismiss` | `function` |  |  | Called when the dismissal button is activated. The parent removes the banner. Required when dismissible is true. Not generated for iOS and Android. |

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `children` | no | Optional message body. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | Named section with a soft status fill and border, and primary text. |
| `icon` | Decorative 16px variant icon in the status color, in a box one line tall so it stays level with the first line of the title. Replaced by icon or hidden with icon={null}. |
| `content` | Column that holds the title, body and optional actions. |
| `title` | Heading that names the section by default. |
| `body` | Optional body in primary text, like the title. |
| `actions` | Caller-supplied action below the message. |
| `close` | Optional dismissal button, named by dismissLabel. |
| `hitArea` | Transparent minimum target around the dismissal button. |

## Accessibility

Role: `region`

| Keys | Action |
| --- | --- |
| `Tab` | Focus a supplied action or the dismissal button. |
| `Enter / Space` | Activate the focused dismissal button. |

- The title names the section unless aria-label or aria-labelledby supplies a different name.
- Variant alone does not create a live region. Use role="status" for polite updates or role="alert" for urgent updates.
- The icon is decorative; the title and body carry the message.
- Dismissal remains under parent control. Alert never hides itself.

## Install

```bash
npx werewolf-ui add alert
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add alert --platform ios
npx werewolf-ui add alert --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
