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.
---
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 }}
/>Text logo
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
---
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.
---
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).
---
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.
---
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.
---
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={{}}
/>Sticky header
Header that sticks to top on scroll (scroll down to see effect).
---
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.
---
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.
---
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.
---
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.
---
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
| Prop | Type | Default | Description |
|---|---|---|---|
| isSticky | boolean | false | Makes the header stick to the top of the viewport on scroll (default: false) |
| isFloating | boolean | false | Makes the header float with margin instead of spanning full width (default: false) |
| buttonsGap | HeaderButtonsGap | 'normal' | Space between buttons in each button group (default: 'normal') |
| buttonsClass | string | — | Custom classes for both button-group wrappers (default: 'flex flex-row flex-wrap gap-1') |
| container | ContainerProps | — | Container configuration wrapping the header content |
| logo | LogoProps | — | 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). |
| leftNavigationTreeHorizontal | NavigationTreeHorizontalProps | — | Horizontal navigation tree in the left zone |
| rightNavigationTreeHorizontal | NavigationTreeHorizontalProps | — | Horizontal navigation tree in the right zone |
| defaultNavigationTreeHorizontalConfig | LayerConfig<Omit<NavigationTreeHorizontalProps, 'items'>> | — | NavigationTreeHorizontal config merged under both navigation trees; share nav button defaults through its `defaultItemConfig` |
| themeToggle | ThemeToggleProps | — | Theme toggle in the right zone; rendered when set (`{}` for defaults) |
| leftButtons | ButtonProps[] | [] | Buttons in the left zone |
| rightButtons | ButtonProps[] | [] | Buttons in the right zone |
| defaultButtonConfig | LayerConfig<ButtonProps> | — | Button config merged under every entry in `leftButtons` and `rightButtons` |
| class | string | '' | Classes merged onto the zones row (flex, wraps when the zones don't fit); a consumer `grid` replaces `flex`. |