# Alert

A banner in the flow of a page: a tinted box with a 16 px icon centred on 12 px text, in five kinds, with an optional title, link and dismiss. Each kind has its own icon, so colour is never the only signal.

- Beta: ready to use; its API can still change in a minor release.
- Category: Feedback

```tsx
import { Alert } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for a condition on the page that stays until it's resolved, like a mailbox that isn't connected, and put the fix in `action` as a `TextLink`.
- Do: Add `role="alert"` or `role="status"` only when it appears in response to something, like a sync that just failed, so a banner that was there on load isn't announced.
- Do: Use `neutral` for a fact that needs no action, like matters created before 2024 not showing billing totals.
- Do: Write an error as what happens next or what to do, like "We couldn't reach LEAP. Changes will sync when it's back."
- Don't: Rely on colour alone to tell a warning from an error. Say which it is in the `title` or the text, so it reads the same to someone who can't see the colour.
- Don't: Use it to confirm something the person just did, like saving a contact. Use `toast`.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Dismisses it, with focus on its close button. |

## Related

- [Toast](./toast.md)
- [Next Action Banner](./next-action-banner.md)
- [Empty State](./empty-state.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { Alert, TextLink } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
function Dismissable() {
  const [shown, setShown] = useState(true);
  if (!shown) {
    return (
      <TextLink
        size="sm"
        render={<button type="button" onClick={() => setShown(true)} />}
      >
        Show it again
      </TextLink>
    );
  }
  return (
    <Alert
      kind="info"
      title="Mailbox not connected"
      action={
        <TextLink size="sm" href="/alert">
          Connect
        </TextLink>
      }
      onDismiss={() => setShown(false)}
    >
      Connect your mailbox to log emails automatically.
    </Alert>
  );
}
```

### Kinds

```tsx
<div className="flex w-100 flex-col gap-3">
  <Alert kind="info">
    Connect your mailbox to log emails automatically.
  </Alert>
  <Alert kind="success">
    Your mailbox is connected. Emails will log automatically.
  </Alert>
  <Alert kind="warning">
    This matter type has no LEAP template yet — converting uses the
    default.
  </Alert>
  <Alert kind="error">
    We couldn’t reach LEAP. Changes will sync when it’s back.
  </Alert>
  <Alert kind="neutral">
    Matters created before 2024 don’t show billing totals.
  </Alert>
</div>
```

### Title, link and dismiss

```tsx
<div className="w-100">
  <Dismissable />
</div>
```

## Props

Also takes every prop of a <div>. Add role="alert" or role="status" only when it appears in response to something, so a static banner isn't announced.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `kind` | `"info" \| "success" \| "warning" \| "error" \| "neutral"` | `"info"` | Info (navy tint), success, warning, error or neutral. |
| `title` | `ReactNode` |  | An optional bold first line. |
| `action` | `ReactNode` |  | A link on the right that resolves it, like a TextLink "Connect". |
| `onDismiss` | `() => void` |  | Shows a × on the right and runs when it's pressed. |
| `dismissLabel` | `string` | `"Dismiss"` | Names the × when "Dismiss" isn't enough. |
