Alert
Inline message panel with a status icon, title, optional description and action slot, in five variants.
pnpm dlx shadcn@latest add @haze/alert---
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>When to use
- 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
When not to use
- A short-lived confirmation that should disappear on its own
- A blocking decision that needs a dialog
Installation
Add the Haze registry to components.json once, then install Alert with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/alertnpx shadcn@latest add @haze/alertyarn dlx shadcn@latest add @haze/alertbunx --bun shadcn@latest add @haze/alertFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "info" | "success" | "warning" | "destructive" | "default" | 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 | – | First line, rendered as a paragraph in medium weight. |
| class | string | – | Extra classes on the box. |
| ...rest | HTML attributes | – | Passed to the box; add role="alert" for messages inserted after load. |
| default slot | slot | – | Description text under the title. |
| action | slot | – | 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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.