Notification center
Header bell trigger with unread badge opening an activity inbox with read/unread toggles, expandable details and bulk clear.
pnpm dlx shadcn@latest add @haze/notification-center---
import { Bell, CheckCheck, ChevronDown, Trash2 } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Notification {
id: string;
group: "Today" | "Earlier";
title: string;
detail: string;
time: string;
unread: boolean;
}
interface Props {
id?: string;
notifications?: Notification[];
class?: string;
}
const {
id = "haze-notification-center",
notifications = [
{ id: "n1", group: "Today", title: "Nina approved PR 492", detail: "Token contrast checks passed across all 148 pairs; branch is ready to squash-merge.", time: "4m ago", unread: true },
{ id: "n2", group: "Today", title: "Production deploy succeeded", detail: "Release v2.8.1 went live in 34s with zero health-check errors.", time: "42m ago", unread: true },
{ id: "n3", group: "Earlier", title: "Weekly usage digest ready", detail: "Compute spend is 14% below forecast for the current billing cycle.", time: "Yesterday", unread: false },
],
class: className,
} = Astro.props;
const initialUnread = notifications.filter((n) => n.unread).length;
---
<section aria-labelledby={`${id}-title`} data-haze-notif-center class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-lg space-y-3">
<div class="flex items-center justify-between gap-2">
<h2 id={`${id}-title`} class="text-sm/5 font-semibold text-foreground">Notifications</h2>
<button
type="button"
data-nc-trigger
aria-expanded="true"
aria-controls={`${id}-panel`}
class="relative inline-flex h-9 cursor-pointer items-center gap-2 rounded-lg border border-frame-strong bg-field px-3 text-xs font-medium text-foreground shadow-key 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"
>
<Bell class="size-4" aria-hidden="true" />
<span>Inbox</span>
<span data-nc-badge class="inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 font-mono text-[0.6875rem] font-semibold text-primary-foreground tabular-nums">{initialUnread}</span>
</button>
</div>
<div id={`${id}-panel`} data-nc-panel class="overflow-hidden rounded-2xl border border-border bg-popover shadow-float">
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-border px-4 py-3">
<span class="text-xs font-semibold text-foreground">Activity inbox</span>
<div class="flex items-center gap-1.5">
<button type="button" data-nc-read-all class="inline-flex h-7 cursor-pointer items-center gap-1 rounded-md px-2 text-xs text-muted-foreground hover:bg-accent hover:text-foreground 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">
<CheckCheck class="size-3.5" aria-hidden="true" />
Mark all read
</button>
<button type="button" data-nc-clear class="inline-flex h-7 cursor-pointer items-center gap-1 rounded-md px-2 text-xs text-muted-foreground hover:bg-destructive/14 hover:text-destructive 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">
<Trash2 class="size-3.5" aria-hidden="true" />
Clear all
</button>
</div>
</div>
<ul role="list" data-nc-list class="divide-y divide-border">
{
notifications.map((n) => (
<li data-nc-item data-unread={String(n.unread)} class="p-3.5 transition-colors duration-150 data-[unread=true]:bg-muted/40">
<div class="flex items-start justify-between gap-2">
<div class="flex min-w-0 items-start gap-2.5">
<span data-nc-dot class={cn("mt-1.5 size-2 shrink-0 rounded-full", n.unread ? "bg-foreground" : "bg-muted")} aria-hidden="true"></span>
<div class="min-w-0">
<p class="text-sm/5 font-medium text-foreground">{n.title}</p>
<p class="text-[0.6875rem]/4 text-muted-foreground">{n.group} · {n.time}</p>
</div>
</div>
<button type="button" data-nc-toggle-read class="inline-flex h-7 shrink-0 cursor-pointer items-center rounded-md border border-frame bg-field px-2 text-[0.6875rem] font-medium text-muted-foreground hover:border-frame-strong hover:text-foreground 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">
{n.unread ? "Mark read" : "Unread"}
</button>
</div>
<details class="group mt-2 pl-4.5">
<summary class="flex cursor-pointer list-none items-center gap-1 text-xs text-muted-foreground hover:text-foreground select-none focus-visible:outline-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
<span>Details</span>
<ChevronDown class="size-3 transition-transform duration-150 ease-snappy group-open:rotate-180" aria-hidden="true" />
</summary>
<p class="mt-1.5 text-xs/5 text-pretty text-muted-foreground">{n.detail}</p>
</details>
</li>
))
}
</ul>
<p data-nc-empty hidden class="py-10 text-center text-xs text-muted-foreground">You are all caught up.</p>
<p data-nc-status role="status" class="border-t border-border bg-muted/40 px-4 py-2 text-xs/4 text-muted-foreground">{initialUnread} unread notifications</p>
</div>
</div>
</section>
<script>
function initNotifCenters() {
document.querySelectorAll<HTMLElement>("[data-haze-notif-center]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const trigger = root.querySelector<HTMLButtonElement>("[data-nc-trigger]");
const panel = root.querySelector<HTMLElement>("[data-nc-panel]");
const badge = root.querySelector<HTMLElement>("[data-nc-badge]");
const list = root.querySelector<HTMLElement>("[data-nc-list]");
const empty = root.querySelector<HTMLElement>("[data-nc-empty]");
const status = root.querySelector<HTMLElement>("[data-nc-status]");
const syncCount = (msg?: string) => {
const items = Array.from(root.querySelectorAll<HTMLElement>("[data-nc-item]"));
const unread = items.filter((i) => i.dataset.unread === "true").length;
if (badge) { badge.textContent = String(unread); badge.hidden = unread === 0; }
if (empty) empty.hidden = items.length > 0;
if (status) status.textContent = msg ?? `${unread} unread notifications`;
};
trigger?.addEventListener("click", () => {
if (!panel) return;
panel.hidden = !panel.hidden;
trigger.setAttribute("aria-expanded", String(!panel.hidden));
});
list?.addEventListener("click", (ev) => {
const btn = (ev.target as HTMLElement | null)?.closest<HTMLButtonElement>("[data-nc-toggle-read]");
if (!btn) return;
const item = btn.closest<HTMLElement>("[data-nc-item]");
if (!item) return;
const next = item.dataset.unread !== "true";
item.dataset.unread = String(next);
btn.textContent = next ? "Mark read" : "Unread";
const dot = item.querySelector<HTMLElement>("[data-nc-dot]");
if (dot) dot.className = next ? "mt-1.5 size-2 shrink-0 rounded-full bg-foreground" : "mt-1.5 size-2 shrink-0 rounded-full bg-muted";
syncCount(next ? "Marked unread." : "Marked read.");
});
root.querySelector<HTMLButtonElement>("[data-nc-read-all]")?.addEventListener("click", () => {
root.querySelectorAll<HTMLElement>("[data-nc-item]").forEach((item) => {
item.dataset.unread = "false";
const b = item.querySelector<HTMLButtonElement>("[data-nc-toggle-read]");
if (b) b.textContent = "Unread";
const dot = item.querySelector<HTMLElement>("[data-nc-dot]");
if (dot) dot.className = "mt-1.5 size-2 shrink-0 rounded-full bg-muted";
});
syncCount("All notifications marked as read.");
});
root.querySelector<HTMLButtonElement>("[data-nc-clear]")?.addEventListener("click", () => {
root.querySelectorAll("[data-nc-item]").forEach((i) => i.remove());
syncCount("Cleared all notifications.");
});
});
}
initNotifCenters();
document.addEventListener("astro:page-load", initNotifCenters);
</script>When to use
- Providing a header notifications dropdown with live unread count and per-item read toggling
- Letting users inspect notification details inline or clear the entire inbox
When not to use
- Showing transient corner toast alerts; use toast or notification-stack
Installation
Add the Haze registry to components.json once, then install Notification center with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/notification-centernpx shadcn@latest add @haze/notification-centeryarn dlx shadcn@latest add @haze/notification-centerbunx --bun shadcn@latest add @haze/notification-centerFirst 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-notification-center" | Unique prefix for panel aria-controls and heading IDs. |
| notifications | Notification[] | 3 demo notifications | Grouped notification records with unread state and expandable details. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across the bell trigger, Mark all read, Clear all, read toggles and Details summaries
- EnterSpace
- Open/close the inbox, toggle read state, expand details or clear all
Accessibility
- The bell trigger exposes aria-expanded and aria-controls, and each notification expands details via native details/summary.
- Unread badge counts and bulk actions announce changes in a polite role="status" footer.
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 "Notification center" with `npx shadcn@latest add @haze/notification-center`. 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 NotificationCenter from "@/components/haze/blocks/notification-center.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/notification-center.md
Customize with real content
Adapt the Haze notification-center block for our product. Replace the demo values of these props with our real content: id, notifications, class. Keep the layout, the heading level rules and these accessibility details: The bell trigger exposes aria-expanded and aria-controls, and each notification expands details via native details/summary. Unread badge counts and bulk actions announce changes in a polite role="status" footer. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using notification-center, check it fits: use it when providing a header notifications dropdown with live unread count and per-item read toggling; letting users inspect notification details inline or clear the entire inbox. Avoid it when showing transient corner toast alerts; use toast or notification-stack. Alternatives: @haze/notification-stack, @haze/inbox-list.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.