Composite

Header

Site header with logo, navigation, and actions.

Header component combining logo, horizontal navigation menu, theme toggle, and action buttons.

Basic header

Simple header with logo and navigation.

basic
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  logo={{
    image: {
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 48,
      height: 48,
    },
  }}
  rightNavigationTreeHorizontal={{ items: navItems }}
/>

Header with text logo instead of image. Defaults to SITE.name from config if not provided. Logo is rendered as a Button, so you can use all Button props for styling.

Using SITE.name (default)

Custom styling with logo

text-logo
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<div class="space-y-6">
  <div>
    <p class="text-sm font-semibold">Using SITE.name (default)</p>
    <HeaderBlock rightNavigationTreeHorizontal={{ items: navItems }} />
  </div>
  <div>
    <p class="text-sm font-semibold">Custom text</p>
    <HeaderBlock logo={{ label: 'My Brand' }} rightNavigationTreeHorizontal={{ items: navItems }} />
  </div>
  <div>
    <p class="text-sm font-semibold">Custom styling with logo</p>
    <HeaderBlock
      logo={{
        label: 'Styled Brand',
        labelClass: '!text-2xl !font-extrabold !text-primary',
        class: 'hover:scale-105 transition-transform',
      }}
      rightNavigationTreeHorizontal={{ items: navItems }}
    />
  </div>
</div>

Theme toggle

Header with theme toggle button.

theme-toggle
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  logo={{
    image: {
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 48,
      height: 48,
    },
  }}
  rightNavigationTreeHorizontal={{ items: navItems }}
  themeToggle={{ size: 'md' }}
/>

Mobile menu

Header with hamburger menu for mobile (resize browser to see).

Logo
mobile-menu
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import ModalBlock from '@alfadormx/blocks/layout/Modal.astro';
import NavigationTree from '@alfadormx/blocks/composite/NavigationTree.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  {
    label: 'Products',
    children: [
      { label: 'Product 1', href: '/products/1' },
      { label: 'Product 2', href: '/products/2' },
      { label: 'Product 3', href: '/products/3' },
    ],
  },
  {
    label: 'Services',
    children: [
      { label: 'Consulting', href: '/services/consulting' },
      { label: 'Development', href: '/services/development' },
      { label: 'Design', href: '/services/design' },
    ],
  },
];
---

<HeaderBlock
  logo={{
    image: {
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 48,
      height: 48,
    },
  }}
  leftButtons={[
    {
      'data-modal-trigger': 'mobile-menu-basic',
      icon: { name: 'heroicons:bars-3' },
      variant: 'ghost',
      intent: 'neutral',
      class: 'lg:hidden',
    },
  ]}
/>

<ModalBlock id="mobile-menu-basic" position="left" size="sm">
  <div class="p-4">
    <p class="font-semibold">Menu</p>
    <NavigationTree items={navItems} />
  </div>
</ModalBlock>

Button spacing

Control spacing between the buttons in each group using the buttonsGap prop.

Tight

Logo

Normal (default)

Logo

Loose

Logo
button-spacing
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<div class="space-y-6">
  <div>
    <p class="text-sm font-semibold">Tight</p>
    <HeaderBlock
      themeToggle={{}}
      buttonsGap="tight"
      logo={{
        image: {
          src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
          alt: 'Logo',
          width: 48,
          height: 48,
        },
      }}
      rightNavigationTreeHorizontal={{ items: navItems }}
      rightButtons={[
        { label: 'Login', variant: 'outline', size: 'sm' },
        { label: 'Sign Up', variant: 'solid', size: 'sm' },
      ]}
    />
  </div>
  <div>
    <p class="text-sm font-semibold">Normal (default)</p>
    <HeaderBlock
      themeToggle={{}}
      buttonsGap="normal"
      logo={{
        image: {
          src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
          alt: 'Logo',
          width: 48,
          height: 48,
        },
      }}
      rightNavigationTreeHorizontal={{ items: navItems }}
      rightButtons={[
        { label: 'Login', variant: 'outline', size: 'sm' },
        { label: 'Sign Up', variant: 'solid', size: 'sm' },
      ]}
    />
  </div>
  <div>
    <p class="text-sm font-semibold">Loose</p>
    <HeaderBlock
      themeToggle={{}}
      buttonsGap="loose"
      logo={{
        image: {
          src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
          alt: 'Logo',
          width: 48,
          height: 48,
        },
      }}
      rightNavigationTreeHorizontal={{ items: navItems }}
      rightButtons={[
        { label: 'Login', variant: 'outline', size: 'sm' },
        { label: 'Sign Up', variant: 'solid', size: 'sm' },
      ]}
    />
  </div>
</div>

Left-side navigation and actions

Demonstrates leftNavigationTreeHorizontal and leftButtons to place navigation and actions on the left.

left-nav
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  logo={{
    image: {
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 48,
      height: 48,
    },
  }}
  leftNavigationTreeHorizontal={{ items: navItems }}
  rightNavigationTreeHorizontal={{ items: navItems }}
  leftButtons={[{ label: 'Docs', variant: 'solid', size: 'sm' }]}
  rightButtons={[{ label: 'Sign In', variant: 'solid', size: 'sm' }]}
  themeToggle={{}}
/>

Header that sticks to top on scroll (scroll down to see effect).

Scroll down to see the sticky header in action...

Content area

sticky
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<div class="h-96 overflow-y-scroll">
  <HeaderBlock
    isSticky
    themeToggle={{}}
    logo={{
      image: {
        src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
        alt: 'Logo',
        width: 48,
        height: 48,
      },
    }}
    rightNavigationTreeHorizontal={{ items: navItems }}
    container={{
      background: { class: 'bg-background/10 backdrop-blur-sm' },
      border: { width: 'border-b', color: 'border-border' },
    }}
  />
  <div class="p-8 bg-elevated/50">
    <p>Scroll down to see the sticky header in action...</p>
    <div class="h-200 flex items-center justify-center">
      <p class="text-muted">Content area</p>
    </div>
  </div>
</div>

Floating header

Header floats above page content using fixed positioning. Best used on full pages with hero sections or full-page layouts.

isFloating uses fixed positioning relative to the viewport, making it float above all content and stay visible during scroll. It cannot be demonstrated in a scrollable container.

<Header isFloating themeToggle={{}} rightNavigationTreeHorizontal={{ items }} />

Vector logo with colour inheritance

Use Vector component for SVG logos that can inherit colours via text classes. Perfect for logos that adapt to themes or scroll states.

vector-logo
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  logo={{
    vector: {
      src: 'https://www.svgrepo.com/show/530609/compass.svg',
    },
    class: 'text-primary hover:text-accent transition-colors duration-300',
  }}
  rightNavigationTreeHorizontal={{ items: navItems }}
  themeToggle={{}}
/>

Custom styling

Customize container styling with background, borders, and padding.

Logo
custom-styling
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  themeToggle={{}}
  logo={{
    image: {
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 48,
      height: 48,
    },
  }}
  rightNavigationTreeHorizontal={{ items: navItems }}
  container={{
    background: { class: 'bg-accent/10 backdrop-blur-sm' },
    border: { width: 'border-b', color: 'border-primary' },
    content: { air: 'loose' },
  }}
  rightButtons={[{ label: 'Get Started', variant: 'solid', intent: 'primary', size: 'sm' }]}
/>

Shared navigation config

defaultNavigationTreeHorizontalConfig is merged under both navigations. Share nav button styling through its defaultItemConfig.

navigation-layer
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';

const navItems: NavigationTreeItem[] = [
  { label: 'Home', href: '/' },
  { label: 'About', href: '/about' },
];
---

<HeaderBlock
  leftNavigationTreeHorizontal={{ items: navItems }}
  rightNavigationTreeHorizontal={{ items: navItems }}
  defaultNavigationTreeHorizontalConfig={{
    defaultItemConfig: { intent: 'primary', variant: 'ghost' },
  }}
/>

HTML attributes

id and aria-label land on the header root.

The logo’s id, name and media id appear once in the page.

attributes
---
import HeaderBlock from '@alfadormx/blocks/composite/Header.astro';
---

<HeaderBlock
  id="doc-header"
  aria-label="Site header"
  logo={{
    id: 'doc-header-logo',
    name: 'doc-header-logo',
    image: {
      id: 'doc-header-logo-image',
      src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=200&h=200&fit=crop',
      alt: 'Logo',
      width: 32,
      height: 32,
    },
  }}
/>

Usage notes

Mobile menu pattern. The Header provides the layout and hamburger button, but the mobile menu Modal is placed separately. Connect them using the data-modal-trigger attribute on the hamburger button.

Sticky positioning. When isSticky is enabled, consider adding a semi-transparent background with opacity to maintain readability over content.

API Reference

PropTypeDefaultDescription
isStickybooleanfalseMakes the header stick to the top of the viewport on scroll (default: false)
isFloatingbooleanfalseMakes the header float with margin instead of spanning full width (default: false)
buttonsGapHeaderButtonsGap'normal'Space between buttons in each button group (default: 'normal')
buttonsClassstring—Custom classes for both button-group wrappers (default: 'flex flex-row flex-wrap gap-1')
containerContainerProps—Container configuration wrapping the header content
logoLogoProps—Logo rendered once between the zones; centred while the zones fit, pushed aside rather than covered, and wrapped onto its own line with the zones when they don't fit (A16).
leftNavigationTreeHorizontalNavigationTreeHorizontalProps—Horizontal navigation tree in the left zone
rightNavigationTreeHorizontalNavigationTreeHorizontalProps—Horizontal navigation tree in the right zone
defaultNavigationTreeHorizontalConfigLayerConfig<Omit<NavigationTreeHorizontalProps, 'items'>>—NavigationTreeHorizontal config merged under both navigation trees; share nav button defaults through its `defaultItemConfig`
themeToggleThemeToggleProps—Theme toggle in the right zone; rendered when set (`{}` for defaults)
leftButtonsButtonProps[][]Buttons in the left zone
rightButtonsButtonProps[][]Buttons in the right zone
defaultButtonConfigLayerConfig<ButtonProps>—Button config merged under every entry in `leftButtons` and `rightButtons`
classstring''Classes merged onto the zones row (flex, wraps when the zones don't fit); a consumer `grid` replaces `flex`.