Navbar: centered brand with mobile menu
A centered desktop brand with navigation on one side and a native mobile disclosure.
pnpm dlx shadcn@latest add @haze/navbar-centered---
import { Menu, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Button from "../ui/button.astro";
import LogoMark from "../ui/logo-mark.astro";
interface Props {
brand?: string;
homeHref?: string;
links?: { label: string; href: string }[];
actionLabel?: string;
actionHref?: string;
class?: string;
}
const {
brand = "Driftwork",
homeHref = "/",
links = [{ label: "Product", href: "#product" }, { label: "Customers", href: "#customers" }, { label: "About", href: "#about" }],
actionLabel = "Get started",
actionHref = "#start",
class: className,
} = Astro.props;
---
<header class={cn("border-b border-border bg-muted/40", className)}>
<nav aria-label="Main" class="relative mx-auto grid h-16 max-w-6xl grid-cols-[1fr_auto] items-center gap-4 px-6 lg:grid-cols-[1fr_auto_1fr]">
<ul class="hidden flex-wrap items-center gap-1 lg:flex">
{links.map((link) => <li><a href={link.href} class="inline-flex min-h-10 items-center rounded-md px-3 text-sm/5 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:bg-foreground/8 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring">{link.label}</a></li>)}
</ul>
<a href={homeHref} aria-label={`${brand} home`} class="inline-flex w-fit rounded-md focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ring"><LogoMark name={brand} shape="diamond" class="text-foreground" /></a>
<div class="hidden justify-end lg:flex">{actionHref && <Button href={actionHref} size="sm">{actionLabel}</Button>}</div>
<details class="group lg:hidden">
<summary aria-label="Navigation menu" class="flex size-10 cursor-pointer list-none items-center justify-center rounded-lg text-foreground transition-colors duration-150 ease-snappy hover:bg-foreground/8 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
<Menu aria-hidden="true" class="size-5 group-open:hidden" /><X aria-hidden="true" class="hidden size-5 group-open:block" />
</summary>
<div class="absolute inset-x-0 top-full z-10 max-h-[calc(100dvh-4rem)] overflow-y-auto border-b border-border-strong bg-popover p-4 text-popover-foreground shadow-float">
<ul class="grid gap-1">
{links.map((link) => <li><a href={link.href} class="flex min-h-10 items-center rounded-md px-3 text-sm/5 font-medium text-foreground transition-colors duration-150 ease-snappy hover:bg-foreground/8 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring">{link.label}</a></li>)}
</ul>
{actionHref && <div class="mt-4 border-t border-border pt-4"><Button href={actionHref} class="w-full">{actionLabel}</Button></div>}
</div>
</details>
</nav>
</header>When to use
- A short primary navigation should flank a centered brand
- The mobile navigation should remain usable without JavaScript
When not to use
- A large navigation needs the popover menu used by navbar-simple
- Many desktop links would wrap beyond one row
Installation
Add the Haze registry to components.json once, then install Navbar: centered brand with mobile menu with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/navbar-centerednpx shadcn@latest add @haze/navbar-centeredyarn dlx shadcn@latest add @haze/navbar-centeredbunx --bun shadcn@latest add @haze/navbar-centeredFirst 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 |
|---|---|---|---|
| brand | string | "Driftwork" | Brand name in the logo and home link. |
| homeHref | string | "/" | Home destination for the brand. |
| links | { label: string; href: string }[] | 3 example anchors | Short list of navigation links; replace example anchors with real destinations. |
| actionLabel | string | "Get started" | Text for the optional action link. |
| actionHref | string | "#start" | Action destination; pass an empty string to hide it. |
| class | string | – | Additional header classes. |
Keyboard interactions
- Tab, Enter or Space
- Focus and toggle the mobile navigation, then visit its links.
Accessibility
- The mobile menu uses native details and summary, which expose its expanded state without a script.
- The icon changes with the disclosure state; the summary retains a stable accessible name.
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 "Navbar: centered brand with mobile menu" with `npx shadcn@latest add @haze/navbar-centered`. 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 NavbarCentered from "@/components/haze/blocks/navbar-centered.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/navbar-centered.md
Customize with real content
Adapt the Haze navbar-centered block for our product. Replace the demo values of these props with our real content: brand, homeHref, links, actionLabel, actionHref, class. Keep the layout, the heading level rules and these accessibility details: The mobile menu uses native details and summary, which expose its expanded state without a script. The icon changes with the disclosure state; the summary retains a stable accessible name. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using navbar-centered, check it fits: use it when a short primary navigation should flank a centered brand; the mobile navigation should remain usable without javascript. Avoid it when a large navigation needs the popover menu used by navbar-simple; many desktop links would wrap beyond one row. Alternatives: @haze/navbar-simple.
Dependencies
- npm: @lucide/astro
- @haze/button
- @haze/logo-mark
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.