Header

Header wraps top-level navigation and branding.

Live code

Storybook

Storybook failed to load. Please connect to the VPN to access.

Usage

Header and HeaderDialog

The Header is a highly variable and customizable component. It comes in several design variants and provides a handful of building blocks you can use to achieve your specific design goals.

The Header is a composition of several subcomponents:

Accessibility Guidelines

👉 The animation effect of this component is dependent on the prefers-reduced-motion media query.

🌍 Although we don't need it yet, this component experimentally supports RTL languages (because just a single line had to be added to make it all work 🎉).

Minimal Header

Without any modifier, Header is ready to contain necessary blocks in a classic left-to-right layout (in LTR documents). Please note it is fully transparent unless you specify a color variant.


                                                
                                                <Header>
                                                  <Link href="/">
                                                    <img src="https://www.example.com/logo.png" width="65" height="24" alt="Spirit" />
                                                  </Link>
                                                </Header>

Color Variants

Currently, Header comes in two color variants: transparent (for dark backgrounds) and inverted (for light backgrounds). Use the color property to apply the desired background color to Header.


                                                
                                                <Header color="inverted">
                                                  <Link href="/">
                                                    <img src="https://www.example.com/logo.png" width="65" height="24" alt="Spirit" />
                                                  </Link>
                                                </Header>

Simple Header

The isSimple modifier makes the header bar slightly shorter and aligns its content to the center. Use this design variant when all you need on the page is just branding.


                                                
                                                <Header isSimple>
                                                  <a href="/">
                                                    <img src="https://www.example.com/logo.png" width="65" height="24" alt="Spirit" />
                                                  </a>
                                                </Header>

API

Name Type Default Required Description
children ReactNode Children node
color [transparent | inverted] transparent Color variant
isSimple bool false Shorter, centered version of Header

The component implements the HTMLElement interface.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Supported Content

To create a responsive header with top-level navigation, there are the following building blocks to use:

  1. Inside Header:
    1. mobile-only actions, including toggle button by default,
    2. desktop-only actions with primary and secondary action slots.
  2. Inside Header Dialog:
    1. primary actions slot (all breakpoints),
    2. secondary actions slot (all breakpoints).

Mobile-Only Actions

Slot for actions that are intended to display on mobile and tablet screens only. It holds the toggle button by default, but you can add as many custom elements as the free space in Header allows.


                                                
                                                <HeaderMobileActions dialogId="my-header-dialog" />

Toggle button is already part of the mobile actions component. It is linked to the Header Dialog via the dialogId prop.

Custom Mobile Actions

You can place any custom content into the mobile actions component:


                                                
                                                <HeaderMobileActions dialogId="my-header-dialog">{/* Mobile-only actions */}</HeaderMobileActions>

API

Name Type Default Required Description
children ReactNode Children node
dialogId string ID of the linked HeaderDialog
isOpen bool false Dialog open state
menuToggleLabel string Menu Label of the menu toggle button
onOpen (event: ClickEvent or KeyboardEvent) => void Callback for dialog when opened

The component implements the HTMLElement interface.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Desktop-Only Actions

As the name suggests, desktop-only actions are intended to display on desktop screens only. They generally work as flex containers that define vertical alignment and spacing.

There are two slots you can use: primary actions (aligned to left in LTR documents), and secondary actions (aligned to right).

👉 It is critical to make sure all your actions fit the Header on the desktop breakpoint. Spirit intentionally does not provide any overflow control here.


                                                
                                                <HeaderDesktopActions aria-label="Main navigation">
                                                  {/* Desktop-only primary actions */}
                                                </HeaderDesktopActions>
                                                <HeaderDesktopActions color="secondary">
                                                  {/* Desktop-only secondary actions */}
                                                </HeaderDesktopActions>

API

Name Type Default Required Description
children ReactNode Children node
color [primary | secondary] primary Color and alignment variant

The component implements the HTMLElement interface.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Navigation is designed to live in either of the action slots.

👉 As of now, only single-level navigation is supported. You may consider using the Header Dialog for other use cases such as the user menu.


                                                
                                                <HeaderNav>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/" isCurrent>
                                                      Job offers
                                                    </HeaderLink>
                                                  </HeaderNavItem>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/">Part-time jobs</HeaderLink>
                                                  </HeaderNavItem>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/">Inspiration</HeaderLink>
                                                  </HeaderNavItem>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/">Replies</HeaderLink>
                                                  </HeaderNavItem>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/">Employers</HeaderLink>
                                                  </HeaderNavItem>
                                                </HeaderNav>

Both links and buttons are supported:


                                                
                                                <HeaderNav>
                                                  <HeaderNavItem>
                                                    <HeaderLink href="/">Link item</HeaderLink>
                                                  </HeaderNavItem>
                                                  <HeaderNavItem>
                                                    <HeaderButton>Button item</HeaderButton>
                                                  </HeaderNavItem>
                                                </HeaderNav>

Other Content

You can avoid using the HeaderNav for standalone links. That way, you can combine links and buttons in the same container:


                                                
                                                <HeaderDesktopActions color="secondary">
                                                  <HeaderButton>Marian</HeaderButton>
                                                  <Button color="primary">Sign in</Button>
                                                </HeaderDesktopActions>
HeaderNav API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <ul> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

HeaderNavItem API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <li> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Name Type Default Required Description
children ReactNode Children node
elementType ElementType a Type of element
isCurrent bool false Mark link as current

The component further inherits properties from the <a> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

HeaderButton API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <button> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Header Dialog

Header Dialog is Spirit's solution for responsive navigation and selected use cases such as the user menu. Please note Header Dialog is not intended to be used for second-level navigation in general.


                                                
                                                const [isOpen, setOpen] = useState(false);
                                                
                                                <HeaderDialog id="my-header-dialog" isOpen={isOpen} onClose={() => setOpen(false)}>
                                                  {/* Close button with primary and secondary actions */}
                                                </HeaderDialog>;

API

Name Type Default Required Description
children ReactNode Children node
id string ID to be linked in HeaderMobileActions
isOpen bool false Open state
onClose (event: ClickEvent or KeyboardEvent) => void Callback for dialog when closed

The component further inherits properties from the <dialog> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Close Button

HeaderDialogCloseButton contains all necessary handles to control parent dialog.


                                                
                                                <HeaderDialogCloseButton />

API

Name Type Default Required Description
label string Close Label of the menu toggle button

The component further inherits properties from the <button> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Primary and Secondary Actions

There are two slots for actions inside Header Dialog: primary actions slot and the optional secondary actions slot.


                                                
                                                <HeaderDialogActions aria-label="Main navigation">
                                                  {/* Primary actions */}
                                                </HeaderDialogActions>
                                                <HeaderDialogActions color="secondary">
                                                  {/* Secondary actions */}
                                                </HeaderDialogActions>

API

Name Type Default Required Description
children ReactNode Children node
color [primary | secondary] primary Color variant

The component implements the HTMLElement interface.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Navigation capabilities are very similar to those of Header. All principles apply here as well, with the only difference in component names starting with HeaderDialog instead of Header.


                                                
                                                <HeaderDialogNav>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/" isCurrent>
                                                      Job offers
                                                    </HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/">Part-time jobs</HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/">Inspiration</HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/">Replies</HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/">Employers</HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                </HeaderDialogNav>

Navigation items can be links, buttons, or just text:


                                                
                                                <HeaderDialogNav>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogLink href="/">Link item</HeaderDialogLink>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogButton>Button item</HeaderDialogButton>
                                                  </HeaderDialogNavItem>
                                                  <HeaderDialogNavItem>
                                                    <HeaderDialogText>Text item</HeaderDialogText>
                                                  </HeaderDialogNavItem>
                                                </HeaderDialogNav>
HeaderDialogNav API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <ul> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

HeaderDialogNavItem API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <li> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Name Type Default Required Description
children ReactNode Children node
elementType ElementType a Type of element
isCurrent bool false Mark link as current

The component further inherits properties from the <a> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

HeaderDialogButton API
Name Type Default Required Description
children ReactNode Children node

The component further inherits properties from the <button> element.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

HeaderDialogText API
Name Type Default Required Description
children ReactNode Children node

The component implements the HTMLElement interface.

On top of the API options, the components accept additional attributes. If you need more control over the styling of a component, you can use style props and escape hatches.

Composition

This is how all supported building blocks of the Header build up the complete composition:


                                                
                                                <Header color="inverted">
                                                  {/* Branding */}
                                                  <HeaderMobileActions dialogId="header_dialog_example" isOpen={isOpen} onOpen={handleOpen}>
                                                    {/* Optional mobile-only actions */}
                                                  </HeaderMobileActions>
                                                  <HeaderDesktopActions aria-label="Navigation">
                                                    {/* Desktop-only primary actions */}
                                                    <HeaderNav>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/">Job offers</HeaderLink>
                                                      </HeaderNavItem>
                                                      {/* … */}
                                                    </HeaderNav>
                                                  </HeaderDesktopActions>
                                                  <HeaderDesktopActions color="secondary">{/* Desktop-only secondary actions */}</HeaderDesktopActions>
                                                </Header>

And the complete Header Dialog:


                                                
                                                <HeaderDialog id="header_dialog_example" aria-label="Menu" isOpen={isOpen} onClose={handleClose}>
                                                  <HeaderDialogCloseButton />
                                                  <HeaderDialogActions>
                                                    <HeaderDialogNav>
                                                      {/* Primary actions */}
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/">Job offers</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                      {/* … */}
                                                    </HeaderDialogNav>
                                                  </HeaderDialogActions>
                                                  <HeaderDialogActions color="secondary">{/* Secondary actions */}</HeaderDialogActions>
                                                </HeaderDialog>

Show full example code of Header with responsive navigation


                                                
                                                const [isOpen, setOpen] = React.useState(false);
                                                
                                                const handleOpen = () => setOpen(true);
                                                const handleClose = () => setOpen(false);
                                                
                                                <Header color="inverted">
                                                  <Link href="/" aria-label="Spirit homepage">
                                                    <img src="…" width="65" height="24" alt="Spirit" />
                                                  </Link>
                                                  <HeaderMobileActions dialogId="my-menu" isOpen={isOpen} onOpen={handleOpen} />
                                                  <HeaderDesktopActions aria-label="Navigation">
                                                    <HeaderNav>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/" isCurrent>Job offers</HeaderLink>
                                                      </HeaderNavItem>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/">Part-time jobs</HeaderLink>
                                                      </HeaderNavItem>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/">Inspiration</HeaderLink>
                                                      </HeaderNavItem>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/">Replies</HeaderLink>
                                                      </HeaderNavItem>
                                                      <HeaderNavItem>
                                                        <HeaderLink href="/">Employers</HeaderLink>
                                                      </HeaderNavItem>
                                                    </HeaderNav>
                                                  </HeaderDesktopActions>
                                                  <HeaderDesktopActions color="secondary">
                                                    <ButtonLink color="primary" href="/">Sign in</ButtonLink>
                                                    <ButtonLink color="inverted" href="/">Enterprise</ButtonLink>
                                                  </HeaderDesktopActions>
                                                </Header>
                                                
                                                <HeaderDialog
                                                  id="my-menu"
                                                  aria-label="Menu"
                                                  isOpen={isOpen}
                                                  onClose={handleClose}
                                                >
                                                  <HeaderDialogCloseButton />
                                                  <HeaderDialogActions aria-label="Main navigation">
                                                    <HeaderDialogNav>
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/" isCurrent>Job offers</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/">Part-time jobs</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/">Inspiration</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/">Replies</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                      <HeaderDialogNavItem>
                                                        <HeaderDialogLink href="/">Employers</HeaderDialogLink>
                                                      </HeaderDialogNavItem>
                                                    </HeaderDialogNav>
                                                  </HeaderDialogActions>
                                                  <HeaderDialogActions color="secondary">
                                                    <ButtonLink color="primary" href="/">Sign in</ButtonLink>
                                                    <ButtonLink color="inverted" href="/">Enterprise</ButtonLink>
                                                  </HeaderDialogActions>
                                                </HeaderDialog>