# Alert

> Inline message panel with a status icon, title, optional description and action slot, in five variants.

- Kind: ui · Category: Feedback · Interactivity: none
- Install: `npx shadcn@latest add @haze/alert`
- File: `src/components/haze/ui/alert.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/alert

## Use when
- A message that stays in the flow of the page, such as a billing notice or a failed import
- Telling the reader what happened and offering one follow-up action
- Status messages that need an icon and text, not only a tint

## Avoid when
- A short-lived confirmation that should disappear on its own
- A blocking decision that needs a dialog

## Alternatives
- [status](https://hazeui.com/ui/status.md)
- [dialog](https://hazeui.com/ui/dialog.md)
- [empty](https://hazeui.com/ui/empty.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| variant | `"default" \| "info" \| "success" \| "warning" \| "destructive"` | "default" | no | Picks the icon and the tint of the panel: a 25% border and 8% fill for the four status variants, the card surface for default. |
| title | `string` |  | yes | First line, rendered as a paragraph in medium weight. |
| class | `string` |  | no | Extra classes on the box. |
| ...rest | `HTML attributes` |  | no | Passed to the box; add role="alert" for messages inserted after load. |
| default slot | `slot` |  | no | Description text under the title. |
| action | `slot` |  | no | A button or link, shown to the right of the text on wide layouts and under it on narrow ones. |

## Accessibility
- The action sits to the right of the text on wide layouts and below it on narrow ones.
- No role is set by default, so an alert that is part of the page does not interrupt screen readers; pass role="alert" when you insert it after load.
- Each status has its own icon shape: a circle with a check for success, a triangle for warning and a circle with a cross for destructive. Default and info share the circle with an i, and differ by color and by the title text, so the status is not carried by color alone.
- The title is a paragraph, not a heading, so it never disturbs the outline of the page.

## Agent prompts

### Install and use

Install the Haze UI component "Alert" with `npx shadcn@latest add @haze/alert`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Alert from "@/components/haze/ui/alert.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/alert.md

### Customize with real content

Adapt the Haze alert ui for our product. Replace the demo values of these props with our real content: variant, title, class, ...rest, default slot, action. Keep the layout, the heading level rules and these accessibility details: The action sits to the right of the text on wide layouts and below it on narrow ones. No role is set by default, so an alert that is part of the page does not interrupt screen readers; pass role="alert" when you insert it after load. Each status has its own icon shape: a circle with a check for success, a triangle for warning and a circle with a cross for destructive. Default and info share the circle with an i, and differ by color and by the title text, so the status is not carried by color alone. The title is a paragraph, not a heading, so it never disturbs the outline of the page. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using alert, check it fits: use it when a message that stays in the flow of the page, such as a billing notice or a failed import; telling the reader what happened and offering one follow-up action; status messages that need an icon and text, not only a tint. Avoid it when a short-lived confirmation that should disappear on its own; a blocking decision that needs a dialog. Alternatives: @haze/status, @haze/dialog, @haze/empty.

## Example requests that should lead here
- Show a warning that the trial ends in three days with an upgrade button
- Add a destructive alert above the form when saving fails

## Source

```astro
---
import { CircleCheck, CircleX, Info, TriangleAlert } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  variant?: "default" | "info" | "success" | "warning" | "destructive";
  /** Short first line, rendered as plain text (not a heading). */
  title: string;
  class?: string;
  [key: string]: unknown;
}

const { variant = "default", title, class: className, ...rest } = Astro.props;
const boxes = {
  default: "border-border bg-card shadow-key",
  info: "border-border bg-card shadow-key",
  success: "border-border bg-card shadow-key",
  warning: "border-border bg-card shadow-key",
  destructive: "border-border bg-card shadow-key",
};
const iconColors = {
  default: "text-muted-foreground",
  info: "text-brand",
  success: "text-success",
  warning: "text-warning",
  destructive: "text-destructive",
};
const icons = { default: Info, info: Info, success: CircleCheck, warning: TriangleAlert, destructive: CircleX };
const Icon = icons[variant];
const hasDescription = Astro.slots.has("default");
const hasAction = Astro.slots.has("action");
---

<div class={cn("grid grid-cols-[auto_1fr] items-start gap-x-3 gap-y-3 rounded-lg border p-4", hasAction && "sm:grid-cols-[auto_1fr_auto]", boxes[variant], className)} {...rest}>
  <span class={cn("mt-px shrink-0", iconColors[variant])}>
    <Icon class="size-[1.125rem]" aria-hidden="true" />
  </span>
  <div class="min-w-0">
    <p class="text-[0.8125rem]/5 font-medium tracking-[-0.01em] text-foreground">{title}</p>
    {hasDescription && <div class="mt-1 text-xs/[1.4] text-muted-foreground"><slot /></div>}
  </div>
  {hasAction && <div class="col-start-2 sm:col-start-3 sm:row-start-1"><slot name="action" /></div>}
</div>
```
