# Site header with destination menu (带目的地菜单的站点顶栏)

Navigation bar for a boutique hotel booking site: logo, a two-column dropdown with regions and a featured stay, plain links, sign-in and a booking action. Collapses to a sheet menu on narrow containers.

- Ref: `component/site-header` (component · navbars)
- Page: https://uifino.com/en/components/navbars/site-header
- Markdown: https://uifino.com/md/components/site-header.md
- Preview image: https://uifino.com/blocks/covers/site-header-dark.webp

## Install

- shadcn: `npx shadcn@latest add "https://uifino.com/r/blocks/site-header.json"`
- UIFino CLI: `npx uifino@latest add component/site-header`

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

- `button`, `navigation-menu`, `separator`, `sheet`. The shadcn CLI installs them together with the block.

## Layout borrowed from

- https://stripe.com: Left-aligned logo with triggers beside it, sign-in and primary action pinned right, and a dropdown that pairs a list of icon-led items with a tinted side panel. Menus, copy and the featured stay are our own.

## Theme

The block reads the project's shadcn theme variables, so it follows whatever DESIGN.md the project uses and needs no options of its own.
To give the project the look of a UIFino brand or style, install its theme: `npx shadcn@latest add "https://uifino.com/r/themes/airbnb.json"`.

## Usage

The files under `examples/` show the block wired with content, including its loading, empty and error states where it has them.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| components/blocks/site-header/examples/content.ts | demo | 3.6 KB |
| components/blocks/site-header/examples/default.tsx | demo | 2.4 KB |
| components/blocks/site-header/examples/menu-open.tsx | demo | 348 B |
| components/blocks/site-header/site-header.tsx | source | 9.5 KB |

### components/blocks/site-header/site-header.tsx

```tsx
"use client";

import { useState, type ReactNode } from "react";
import {
  ArrowUpRight,
  Building2,
  Compass,
  Flame,
  Flower2,
  Menu,
  Mountain,
  TreePine,
  Utensils,
  Waves,
  type LucideIcon
} from "lucide-react";
import { Button } from "@/components/ui/button";
import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle
} from "@/components/ui/navigation-menu";
import { Separator } from "@/components/ui/separator";
import {
  Sheet,
  SheetClose,
  SheetContent,
  SheetDescription,
  SheetHeader,
  SheetTitle,
  SheetTrigger
} from "@/components/ui/sheet";
import { cn } from "@/lib/utils";

const ICONS = {
  coast: Waves,
  mountain: Mountain,
  forest: TreePine,
  city: Building2,
  guide: Compass,
  food: Utensils,
  garden: Flower2,
  fire: Flame
} satisfies Record<string, LucideIcon>;

export type SiteHeaderIcon = keyof typeof ICONS;

export interface SiteHeaderMenuItem {
  readonly title: string;
  readonly description: string;
  readonly icon: SiteHeaderIcon;
  readonly href: string;
}

export interface SiteHeaderFeatured {
  readonly eyebrow: string;
  readonly title: string;
  readonly description: string;
  readonly facts: readonly string[];
  readonly cta: string;
  readonly href: string;
}

export interface SiteHeaderMenu {
  readonly id: string;
  readonly label: string;
  readonly items: readonly SiteHeaderMenuItem[];
  readonly featured?: SiteHeaderFeatured;
}

export interface SiteHeaderLink {
  readonly label: string;
  readonly href: string;
}

export interface SiteHeaderLabels {
  readonly signIn: string;
  readonly action: string;
  readonly openMenu: string;
  readonly menuTitle: string;
  readonly menuDescription: string;
}

export interface SiteHeaderProps {
  readonly brand: string;
  readonly menus: readonly SiteHeaderMenu[];
  readonly links: readonly SiteHeaderLink[];
  readonly labels: SiteHeaderLabels;
  readonly defaultOpenMenu?: string;
  readonly defaultMobileOpen?: boolean;
  readonly logo?: ReactNode;
  readonly brandHref?: string;
  readonly actionHref?: string;
  readonly signInHref?: string;
  readonly className?: string;
}

function Brand({ name, logo, href }: { readonly name: string; readonly logo?: ReactNode; readonly href: string }) {
  return (
    <a href={href} className="flex shrink-0 items-center gap-2 rounded-md font-semibold tracking-tight">
      {logo ?? (
        <span className="flex size-8 items-center justify-center rounded-full bg-primary text-primary-foreground">
          <Waves className="size-4" aria-hidden="true" />
        </span>
      )}
      <span className="text-base">{name}</span>
    </a>
  );
}

function MenuPanel({ menu }: { readonly menu: SiteHeaderMenu }) {
  const { featured } = menu;
  return (
    <div className="flex w-xl max-w-full gap-2 p-1">
      <ul className="flex flex-1 flex-col gap-1">
        {menu.items.map((item) => {
          const Icon = ICONS[item.icon];
          return (
            <li key={item.title}>
              <NavigationMenuLink href={item.href} className="flex-row items-start gap-3 p-3">
                <span className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-foreground">
                  <Icon className="size-4" aria-hidden="true" />
                </span>
                <span className="flex min-w-0 flex-col gap-0.5">
                  <span className="font-medium text-foreground">{item.title}</span>
                  <span className="text-xs leading-snug text-muted-foreground">{item.description}</span>
                </span>
              </NavigationMenuLink>
            </li>
          );
        })}
      </ul>
      {featured ? (
        <a
          href={featured.href}
          className="group/featured flex w-56 shrink-0 flex-col gap-4 rounded-lg bg-muted p-4 outline-none transition-colors hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50"
        >
          <span className="text-xs font-medium text-muted-foreground">{featured.eyebrow}</span>
          <span className="flex flex-col gap-1">
            <span className="text-base font-semibold leading-snug text-foreground">{featured.title}</span>
            <span className="text-sm leading-snug text-muted-foreground">{featured.description}</span>
          </span>
          <ul className="flex flex-col gap-1 text-xs text-foreground">
            {featured.facts.map((fact) => (
              <li key={fact}>{fact}</li>
            ))}
          </ul>
          <span className="flex items-center gap-1 text-sm font-medium text-foreground">
            {featured.cta}
            <ArrowUpRight
              className="size-4 transition-transform group-hover/featured:translate-x-0.5 group-hover/featured:-translate-y-0.5"
              aria-hidden="true"
            />
          </span>
        </a>
      ) : null}
    </div>
  );
}

function MobileMenu({
  menus,
  links,
  labels,
  signInHref,
  defaultOpen
}: Pick<SiteHeaderProps, "menus" | "links" | "labels" | "signInHref"> & { readonly defaultOpen: boolean }) {
  const [open, setOpen] = useState(defaultOpen);
  return (
    <Sheet open={open} onOpenChange={setOpen}>
      <SheetTrigger asChild>
        <Button variant="outline" size="icon" aria-label={labels.openMenu}>
          <Menu aria-hidden="true" />
        </Button>
      </SheetTrigger>
      <SheetContent side="right" className="w-full gap-0 overflow-y-auto sm:max-w-sm">
        <SheetHeader>
          <SheetTitle>{labels.menuTitle}</SheetTitle>
          <SheetDescription className="sr-only">{labels.menuDescription}</SheetDescription>
        </SheetHeader>
        <nav className="flex flex-col gap-6 px-4 pb-6">
          {menus.map((menu) => (
            <section key={menu.id} className="flex flex-col gap-1">
              <h3 className="px-2 pb-1 text-sm font-medium text-muted-foreground">{menu.label}</h3>
              <ul className="flex flex-col">
                {menu.items.map((item) => {
                  const Icon = ICONS[item.icon];
                  return (
                    <li key={item.title}>
                      <SheetClose asChild>
                        <a
                          href={item.href}
                          className="flex items-center gap-3 rounded-md p-2 text-sm font-medium outline-none transition-colors hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50"
                        >
                          <span className="flex size-8 shrink-0 items-center justify-center rounded-md bg-muted">
                            <Icon className="size-4" aria-hidden="true" />
                          </span>
                          <span className="min-w-0 truncate">{item.title}</span>
                        </a>
                      </SheetClose>
                    </li>
                  );
                })}
              </ul>
            </section>
          ))}
          <Separator />
          <ul className="flex flex-col">
            {links.map((link) => (
              <li key={link.label}>
                <SheetClose asChild>
                  <a
                    href={link.href}
                    className="block rounded-md p-2 text-sm font-medium outline-none transition-colors hover:bg-accent focus-visible:ring-[3px] focus-visible:ring-ring/50"
                  >
                    {link.label}
                  </a>
                </SheetClose>
              </li>
            ))}
          </ul>
          <Button variant="outline" className="w-full" asChild>
            <a href={signInHref ?? "#"}>{labels.signIn}</a>
          </Button>
        </nav>
      </SheetContent>
    </Sheet>
  );
}

export function SiteHeader({
  brand,
  menus,
  links,
  labels,
  defaultOpenMenu,
  defaultMobileOpen = false,
  logo,
  brandHref = "#",
  actionHref = "#",
  signInHref = "#",
  className
}: SiteHeaderProps) {
  return (
    <header className={cn("@container border-b border-border bg-background text-foreground", className)}>
      <div className="mx-auto flex h-16 w-full max-w-6xl items-center gap-6 px-4 @3xl:px-6">
        <Brand name={brand} logo={logo} href={brandHref} />
        <NavigationMenu defaultValue={defaultOpenMenu} className="hidden justify-start @3xl:flex">
          <NavigationMenuList>
            {menus.map((menu) => (
              <NavigationMenuItem key={menu.id} value={menu.id}>
                <NavigationMenuTrigger className="bg-transparent">{menu.label}</NavigationMenuTrigger>
                <NavigationMenuContent>
                  <MenuPanel menu={menu} />
                </NavigationMenuContent>
              </NavigationMenuItem>
            ))}
            {links.map((link) => (
              <NavigationMenuItem key={link.label}>
                <NavigationMenuLink href={link.href} className={cn(navigationMenuTriggerStyle(), "bg-transparent")}>
                  {link.label}
                </NavigationMenuLink>
              </NavigationMenuItem>
            ))}
          </NavigationMenuList>
        </NavigationMenu>
        <div className="ml-auto flex items-center gap-2">
          <Button variant="ghost" className="hidden @3xl:inline-flex" asChild>
            <a href={signInHref}>{labels.signIn}</a>
          </Button>
          <Button asChild>
            <a href={actionHref}>{labels.action}</a>
          </Button>
          <div className="@3xl:hidden">
            <MobileMenu
              menus={menus}
              links={links}
              labels={labels}
              signInHref={signInHref}
              defaultOpen={defaultMobileOpen}
            />
          </div>
        </div>
      </div>
    </header>
  );
}
```

Not inlined (3 files, 6.4 KB). Full sources: https://uifino.com/r/blocks/site-header.json
