Empty states
Tabbed empty-state pattern switching across No results, Offline, Caught up and Not found scenes with clear recovery actions.
pnpm dlx shadcn@latest add @haze/empty-states---
import { CheckCircle2, Compass, RotateCw, SearchX, WifiOff } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id?: string;
class?: string;
}
const { id = "haze-empty-states", class: className } = Astro.props;
const states = [
{ id: "no-results", label: "No results", title: "No matching issues", body: "Try removing one of your active filters or broadening your search term.", action: "Clear filters" },
{ id: "offline", label: "Offline", title: "You are currently offline", body: "Your draft edits are saved locally and will sync automatically when the connection returns.", action: "Retry connection" },
{ id: "caught-up", label: "Caught up", title: "Inbox zero", body: "Every review request and mention has been resolved. Enjoy the quiet.", action: "View archive" },
{ id: "not-found", label: "Not found", title: "Page could not be found", body: "This document may have been moved or its sharing link expired.", action: "Go to workspace" },
] as const;
---
<section aria-labelledby={`${id}-title`} data-haze-empty-states class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-xl space-y-4">
<div class="flex flex-wrap items-center justify-between gap-2">
<h2 id={`${id}-title`} class="text-sm/5 font-semibold text-foreground">Empty state gallery</h2>
<div role="tablist" aria-label="Empty state scene" class="inline-flex flex-wrap rounded-lg border border-border bg-card p-0.5">
{
states.map((s, i) => (
<button
type="button"
role="tab"
data-es-tab={s.id}
aria-selected={i === 0 ? "true" : "false"}
class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground aria-selected:bg-accent aria-selected:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
{s.label}
</button>
))
}
</div>
</div>
<div class="rounded-2xl border border-dashed border-border-strong bg-card px-6 py-12 text-center">
{
states.map((s, i) => (
<div data-es-pane={s.id} hidden={i !== 0} class="mx-auto flex max-w-sm flex-col items-center">
<span class="grid size-12 place-items-center rounded-2xl border border-frame bg-muted/40 text-muted-foreground shadow-key" aria-hidden="true">
{s.id === "no-results" ? <SearchX class="size-5" /> : s.id === "offline" ? <WifiOff class="size-5" /> : s.id === "caught-up" ? <CheckCircle2 class="size-5" /> : <Compass class="size-5" />}
</span>
<h3 class="mt-4 text-base/6 font-semibold tracking-tight text-foreground">{s.title}</h3>
<p class="mt-1.5 text-xs/5 text-pretty text-muted-foreground">{s.body}</p>
<button
type="button"
data-es-act={s.action}
class="mt-5 inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3.5 text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75"
>
<RotateCw class="size-3.5" aria-hidden="true" />
{s.action}
</button>
</div>
))
}
<p data-es-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</div>
</section>
<script>
function initEmptyStates() {
document.querySelectorAll<HTMLElement>("[data-haze-empty-states]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const status = root.querySelector<HTMLElement>("[data-es-status]");
root.querySelectorAll<HTMLButtonElement>("[data-es-tab]").forEach((tab) => {
tab.addEventListener("click", () => {
const id = tab.dataset.esTab;
root.querySelectorAll<HTMLButtonElement>("[data-es-tab]").forEach((t) => t.setAttribute("aria-selected", String(t === tab)));
root.querySelectorAll<HTMLElement>("[data-es-pane]").forEach((p) => (p.hidden = p.dataset.esPane !== id));
if (status) status.textContent = "";
});
});
root.querySelectorAll<HTMLButtonElement>("[data-es-act]").forEach((btn) => {
btn.addEventListener("click", () => {
if (status) status.textContent = `Triggered "${btn.dataset.esAct}".`;
});
});
});
}
initEmptyStates();
document.addEventListener("astro:page-load", initEmptyStates);
</script>When to use
- Standardizing empty, offline, inbox-zero and not-found states across an application
- Pairing concise recovery copy with a single primary action button
When not to use
- You only need one static empty placeholder inside a small card; use empty
Installation
Add the Haze registry to components.json once, then install Empty states with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/empty-statesnpx shadcn@latest add @haze/empty-statesyarn dlx shadcn@latest add @haze/empty-statesbunx --bun shadcn@latest add @haze/empty-statesFirst 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 | "haze-empty-states" | Unique prefix for section heading IDs. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across scene tabs and the active recovery action button
- EnterSpace
- Switch empty-state scenes or trigger the recovery action
Accessibility
- Scene tabs expose aria-selected and swap visible panels cleanly without focus traps.
- Recovery buttons announce their triggered action via a polite role="status" message.
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 block "Empty states" with `npx shadcn@latest add @haze/empty-states`. 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 EmptyStates from "@/components/haze/blocks/empty-states.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/blocks/empty-states.md
Customize with real content
Adapt the Haze empty-states block for our product. Replace the demo values of these props with our real content: id, class. Keep the layout, the heading level rules and these accessibility details: Scene tabs expose aria-selected and swap visible panels cleanly without focus traps. Recovery buttons announce their triggered action via a polite role="status" message. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using empty-states, check it fits: use it when standardizing empty, offline, inbox-zero and not-found states across an application; pairing concise recovery copy with a single primary action button. Avoid it when you only need one static empty placeholder inside a small card; use empty. Alternatives: @haze/empty, @haze/error-not-found.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.