skip to content
mpkcn

~/components/site-header

Site Header

A sticky terminal-style top bar with a logo slot and block cursor, numbered links with a sliding active marker, an actions slot and a drop-down mobile menu.

mysite

$ cat ~/home/index.md

Installation

terminal
npx mpkcn add site-header
deps:framer-motion@13.4.4· tested with react@19.3.0

Usage

A sticky top bar: your logo on the left, numbered links in the middle, your own buttons on the right. Tell it which link is current.

tsx
"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import { SiteHeader } from "@/components/mpkcn/site-header";
import { ThemeToggle } from "@/components/mpkcn/theme-toggle";

export function Header() {
  const pathname = usePathname();
  return (
    <SiteHeader
      logo="mysite"
      linkComponent={Link}
      links={[
        { label: "home", href: "/" },
        { label: "docs", href: "/docs" },
        { label: "blog", href: "/blog" },
      ]}
      current={pathname}
      actions={<ThemeToggle />}
    />
  );
}

current is compared with each link's id, then its href, then its label. Pass next/link's Link as linkComponent for client-side navigation; without it, links are plain <a>.

Examples

Narrow widths

Below 672px of its own width (a container query, not the viewport) the links move into a menu that drops down under the bar. menuFooter adds your own content at its bottom.

mysite

$ cat ~/home/index.md

Plain bar

Turn off the numbers and the cursor, and let the header hide while the page scrolls down.

mysite

$ cat ~/home/index.md

Props

PropTypeDefaultDescription
links{ label; href?; onSelect?; id? }[]—Links, left to right. With `href` they are links, with only `onSelect` buttons.
currentstring—id, href or label of the active link.
logoReactNode"~/"Logo slot: text, an image or any element.
logoHrefstring"/"Where the logo points.
logoLabelstring—Accessible name of the logo link when the logo is not text.
cursorbooleantrueBlinking block cursor after the logo.
numberedbooleantrueShow 01, 02… before each link.
actionsReactNode—Slot on the right, shown at every width.
menuFooterReactNode—Extra content at the bottom of the mobile menu.
linkComponentComponentType<{ href; className; onClick; … }>"a"Your link component, e.g. next/link.
stickybooleantrueStick to the top of the nearest scroll container.
hideOnScrollbooleanfalseSlide out on window scroll down, come back on scroll up.
navLabelstring"Main"Accessible name of the nav landmark.
classNamestring—Extra classes for the header.

Accessibility

  • Links sit in a <nav> landmark with a list; the active one has aria-current="page". Every link and button has a visible amber focus ring.
  • The menu button has aria-expanded and aria-controls. Opening the menu focuses its first link; Escape closes it and puts focus back on the button, and so does a click outside.
  • The cursor stops blinking, the active marker stops sliding and the header stops sliding away under prefers-reduced-motion.