Design System
Layout

Topbar

The header strip: search, theme toggle, notifications and the account menu.

Purpose

The topbar is the shell's header strip: global search on the left, then — right-aligned — the theme toggle, a notifications bell with an unread badge, and the account menu. It sits above the content region, beside the App sidebar; App layout composes and theme-wires it for you. The Footer is its counterpart at the other end of portal pages.

Example

Topbar is controlled: it takes the current theme and a toggle callback. The useTheme hook provides both, already wired to the dark class on <html> and persisted to storage — this is exactly what App layout does internally.

The strip below is live: the theme toggle drives the same useTheme hook as this site's own toggle (so it flips the whole page), and the account menu opens for real.

The demo above is exactly this composition:

Composing the topbar yourself
"use client";

import { Topbar } from "@healthmetrics/ui/topbar";
import { useTheme } from "@healthmetrics/ui/use-theme";

export function Header() {
  const { theme, toggle } = useTheme();
  return (
    <Topbar
      theme={theme}
      onToggleTheme={toggle}
      userName="Aisyah Rahman"
      userRole="Claims Manager"
      notifications={5}
    />
  );
}

What the strip contains

The content is fixed — four zones, no slots. What each does today:

  • Search — a styled Input with a leading glyph. It is visual only: there is no change or submit prop yet, so nothing is wired to it.
  • Theme toggle — calls onToggleTheme. Which glyph shows (sun/moon) is driven by the .dark class on <html> via CSS, so the correct icon paints before hydration; the theme prop only sets the button's accessible label.
  • Notifications — a bell with a --destructive count badge, hidden when notifications is 0. The bell is not a menu; it fires no callback.
  • Account menu — avatar, name and role opening a Dropdown menu. The items (Profile, Settings, Switch account, Log out) are fixed and expose no handlers yet. The name/role block hides below sm; the avatar initials are currently fixed to the default user rather than derived from userName.

Structure

PropertyValue
Height64px (h-16)
Surface--background fill, 1px --border bottom rule
Padding16px horizontal (px-4), 12px gap between zones
Searchmax 384px wide (max-w-sm), 18px leading glyph
Icon buttonsghost variant, 20px glyphs
Badge16px --destructive disc, 10px / Inter 600 count
Avatar32px (size-8)

Best practices

Do

  • Let App layout compose it when the defaults suffice; take over only when you need to drive the user identity or the unread count.
  • Pass the signed-in user's real userName and userRole — they are what the account menu announces.
  • Keep notifications a true unread count and pass 0 to clear it — the badge hides itself.

Don't

  • Render more than one topbar — it is app chrome, not a page header; page titles belong in the content region.
  • Fake the notification count to draw attention — a number that never clears trains users to ignore it.
  • Manage theme state by hand — useTheme already owns the dark class, storage and the OS preference.

Accessibility & keyboard

  • Renders a <header> landmark.
  • Every icon-only control is named: the search input has aria-label="Search", the bell aria-label="Notifications", and the theme toggle's label states the result ("Switch to dark theme"), flipping with the current theme.
  • The unread count is visual only — the bell's accessible name stays "Notifications", so don't rely on the badge alone to convey urgency to screen-reader users.
  • The account trigger shows a 2px --ring outline on focus; its menu is a Radix Dropdown menu, with that component's full keyboard behaviour.
  • Keyboard: Tab moves search → theme → notifications → account; Enter/Space or ArrowDown opens the account menu, arrows move within it, Esc closes and returns focus to the trigger.

Props

PropTypeDefaultDescription
themerequired"light" | "dark"—Current theme. Used for the toggle's accessible label only — which glyph is visible is driven by the `.dark` class on `<html>` via CSS, so the correct icon paints immediately without waiting for hydration.
onToggleThemerequired() => void—Called when the theme toggle is pressed.
userNamestring | undefined"Josephine Lim"Name shown in the account menu.
userRolestring | undefined"HR Admin"Role shown under the name in the account menu.
notificationsnumber | undefined0Unread count on the notifications bell; the badge is hidden when 0.

The topbar with live controls in Storybook

On this page