Banner
Compact dismissible top or inline status strip for announcements, trial notices, and system warnings.
pnpm dlx shadcn@latest add @haze/banner---
import { ArrowRight, CircleCheck, Info, Sparkles, TriangleAlert, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id: string;
title: string;
description?: string;
variant?: "default" | "brand" | "info" | "success" | "warning" | "destructive";
actionLabel?: string;
actionHref?: string;
dismissible?: boolean;
dismissLabel?: string;
class?: string;
}
const {
id,
title,
description,
variant = "brand",
actionLabel,
actionHref = "#",
dismissible = true,
dismissLabel = "Dismiss banner",
class: className,
} = Astro.props;
const frames = {
default: "border-frame bg-card text-foreground",
brand: "border-frame-strong bg-muted text-foreground",
info: "border-frame-brand bg-brand/8 text-foreground",
success: "border-frame-success bg-success/8 text-foreground",
warning: "border-frame-warning bg-warning/8 text-foreground",
destructive: "border-frame-destructive bg-destructive/8 text-foreground",
};
const iconColors = {
default: "text-muted-foreground",
brand: "text-foreground",
info: "text-brand",
success: "text-success",
warning: "text-warning",
destructive: "text-destructive",
};
const icons = {
default: Info,
brand: Sparkles,
info: Info,
success: CircleCheck,
warning: TriangleAlert,
destructive: TriangleAlert,
};
const Icon = icons[variant];
---
<div
id={id}
data-haze-banner
role="region"
aria-label={title}
class={cn(
"flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between rounded-xl border px-4 py-3 text-[0.8125rem]/5 shadow-key transition-[opacity,translate] duration-200 ease-snappy",
frames[variant],
className,
)}
>
<div class="flex min-w-0 basis-full items-start gap-2.5 sm:flex-1 sm:basis-0 sm:items-center">
<Icon class={cn("mt-0.5 size-4 shrink-0 sm:mt-0", iconColors[variant])} aria-hidden="true" />
<div class="min-w-0 flex-1">
<span class="font-medium text-foreground">{title}</span>
{description && <span class="text-muted-foreground"> · {description}</span>}
</div>
</div>
<div class="flex shrink-0 items-center gap-2 max-sm:w-full max-sm:justify-between">
{
actionLabel && (
<a
href={actionHref}
class="inline-flex h-8 items-center gap-1 rounded-md border border-frame-strong bg-field px-2.5 text-[0.8125rem] font-medium text-foreground shadow-key transition-[background-color,scale] duration-150 ease-snappy hover:bg-accent active:scale-[0.97] active:duration-75 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<span>{actionLabel}</span>
<ArrowRight class="size-3.5" aria-hidden="true" />
</a>
)
}
{
dismissible && (
<button
type="button"
data-banner-dismiss
aria-label={dismissLabel}
class="inline-flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground transition-[background-color,color,scale] duration-150 ease-snappy hover:bg-accent hover:text-foreground active:scale-90 active:duration-75 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<X class="size-3.5" aria-hidden="true" />
</button>
)
}
</div>
<span role="status" data-banner-status class="sr-only"></span>
</div>
<script>
function initBanners() {
document.querySelectorAll<HTMLElement>("[data-haze-banner]:not([data-enhanced])").forEach((root) => {
root.setAttribute("data-enhanced", "");
const btn = root.querySelector<HTMLButtonElement>("[data-banner-dismiss]");
const status = root.querySelector<HTMLElement>("[data-banner-status]");
let leaving = false;
btn?.addEventListener("click", () => {
if (leaving) return;
if (status) status.textContent = "Banner dismissed";
if (matchMedia("(prefers-reduced-motion: reduce)").matches) { root.hidden = true; return; }
// Fade and lift out first, then hide once the transition has finished (timer as a fallback).
leaving = true;
const finish = () => {
if (!leaving) return;
leaving = false;
root.removeEventListener("transitionend", onEnd);
clearTimeout(timer);
root.hidden = true;
root.classList.remove("opacity-0", "-translate-y-1");
};
const onEnd = (event: TransitionEvent) => { if (event.target === root && event.propertyName === "opacity") finish(); };
const timer = window.setTimeout(finish, 260);
root.addEventListener("transitionend", onEnd);
root.classList.add("opacity-0", "-translate-y-1");
});
});
}
initBanners();
if (!document.documentElement.hasAttribute("data-haze-banner-listener")) {
document.documentElement.setAttribute("data-haze-banner-listener", "");
document.addEventListener("astro:page-load", initBanners);
}
</script>When to use
- Surfacing a workspace-wide release announcement or billing alert
- Inline dismissible trial or migration reminder with an action link
When not to use
- Multi-paragraph callouts belong in alert
- Blocking confirmation prompts belong in alert-dialog
Installation
Add the Haze registry to components.json once, then install Banner with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/bannernpx shadcn@latest add @haze/banneryarn dlx shadcn@latest add @haze/bannerbunx --bun shadcn@latest add @haze/bannerFirst 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 |
|---|---|---|---|
| id* | string | – | Unique DOM id for the banner region. |
| title* | string | – | Lead headline text inside the banner. |
| description | string | – | Optional short supporting detail. |
| variant | "default" | "brand" | "info" | "success" | "warning" | "destructive" | "brand" | Semantic tone for border, tint, and icon. |
| actionLabel | string | – | Optional button link label. |
| dismissible | boolean | true | Whether to render a dismiss button. |
Accessibility
- Wrapped in a named landmark region with an icon reinforced by explicit text.
- Dismiss button updates an aria-live status region before hiding the bar.
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 "Banner" with `npx shadcn@latest add @haze/banner`. 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 Banner from "@/components/haze/ui/banner.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/banner.md
Customize with real content
Adapt the Haze banner ui for our product. Replace the demo values of these props with our real content: id, title, description, variant, actionLabel, dismissible. Keep the layout, the heading level rules and these accessibility details: Wrapped in a named landmark region with an icon reinforced by explicit text. Dismiss button updates an aria-live status region before hiding the bar. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using banner, check it fits: use it when surfacing a workspace-wide release announcement or billing alert; inline dismissible trial or migration reminder with an action link. Avoid it when multi-paragraph callouts belong in alert; blocking confirmation prompts belong in alert-dialog. Alternatives: @haze/alert, @haze/toast.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.