Story Header

A floating glass bar for a long, chaptered page. It names the chapter you are reading and fills a line as you scroll.

import { ActionLink, StoryHeader } from '@brand-studio/ui';
import { cup } from '@/demos/assets';

export default function StoryHeaderDemo() {
  // The transform keeps the fixed header inside this frame instead of the docs page.
  return (
    <div style={{ position: 'relative', width: '100%', height: 260, overflow: 'hidden', transform: 'translateZ(0)', background: `url(${cup.src}) center / cover` }}>
      <StoryHeader
        brand={<a href="#">Still</a>}
        items={[
          { label: 'Coffee', href: '#coffee' },
          { label: 'Brew guides', href: '#guides' },
        ]}
        current={{ label: 'The pour', href: '#pour', marker: 'II' }}
        actions={<ActionLink href="#visit" shape="pill">Visit</ActionLink>}
      />
    </div>
  );
}

Installation

pnpm add @brand-studio/ui

Usage

import { StoryHeader } from '@brand-studio/ui';
<StoryHeader
  brand={<a href="/">Still</a>}
  items={[{ label: 'Coffee', href: '/coffee' }]}
  current={{ label: 'The pour', href: '#pour', marker: 'II' }}
  actions={<ActionLink href="/visit" shape="pill">Visit</ActionLink>}
/>

The bar is fixed to the top of the window, so the page's first section should start under it. Update current as the reader moves between chapters, for example from an IntersectionObserver.

Accessibility

  • Built on Header: a <header> with a labelled <nav>, and a Mobile Navigation button when the bar is narrower than 40rem.
  • The current chapter is a link back to that chapter's heading. It hides when the bar is narrower than 56rem.
  • The scroll line is decoration. Browsers without scroll-driven animation leave it out.

API Reference

PropTypeDefault
brandReact.ReactNode
items?NavLink[]
current?{ label: React.ReactNode; href: string; marker?: React.ReactNode; }
actions?React.ReactNode
label?string'Main'
className?string''

Still, Deskhand and Hollis are fictional brands. The coffee photographs are original generated artwork. @brand-studio/ui is MIT licensed.