Skip to content
Brok UI

Loading…

No results

Header

Open source

Site headers — a navbar (bar or floating pill shape), dropdown nav, a mega-menu and a product-site header with grouped panels.

Preview

4 of 8

resources/views/blocks/header-centered.blade.php Blade
@props([
    'brand' => 'Acme',
    'brandHref' => '#',
    'links' => null,
    'signInCta' => 'Sign in',
    'signInHref' => '#',
    'primaryCta' => 'Get started',
    'primaryHref' => '#',
])

@php
    // Centered-logo header: the wordmark sits in the middle, with navigation
    // split to the start side and the auth/CTA pair to the end side. Logical
    // (start/end) alignment keeps the split correct under dir="rtl".
    $links ??= [
        ['label' => 'Getting started', 'href' => '#'],
        ['label' => 'Components', 'href' => '#'],
        ['label' => 'Documentation', 'href' => '#'],
    ];
@endphp

<header
    x-data="{ open: false }"
    {{ $attributes->merge(['class' => 'sticky top-0 z-40 w-full border-b border-border bg-background/90 text-foreground backdrop-blur']) }}
>
    <nav class="mx-auto grid max-w-7xl grid-cols-2 items-center gap-4 px-4 py-4 sm:px-6 md:grid-cols-3 lg:px-8" aria-label="{{ __('Main') }}">
        {{-- Start: primary navigation (desktop) / menu toggle (mobile) --}}
        <div class="flex items-center">
            <ul class="hidden items-center gap-2 md:flex">
                @foreach ($links as $link)
                    <li>
                        <a href="{{ $link['href'] }}" class="rounded-md px-4 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
                            {{ __($link['label']) }}
                        </a>
                    </li>
                @endforeach
            </ul>

            <button
                type="button"
                class="inline-flex size-10 items-center justify-center rounded-md text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring md:hidden"
                :aria-expanded="open.toString()"
                aria-controls="navbar-centered-mobile"
                @click="open = ! open"
            >
                <span class="sr-only">{{ __('Toggle menu') }}</span>
                <svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                    <path x-show="! open" d="M4 6h16M4 12h16M4 18h16" stroke-linecap="round" />
                    <path x-show="open" x-cloak d="M6 6l12 12M18 6L6 18" stroke-linecap="round" />
                </svg>
            </button>
        </div>

        {{-- Center: brand --}}
        <div class="flex justify-end md:justify-center">
            <x-ui.brand :href="$brandHref" :label="$brand" collapse />
        </div>

        {{-- End: auth + primary CTA --}}
        <div class="hidden items-center justify-end gap-2 md:flex">
            <x-ui.button :href="$signInHref" size="sm" variant="ghost">{{ __($signInCta) }}</x-ui.button>
            <x-ui.button :href="$primaryHref" size="sm">{{ __($primaryCta) }}</x-ui.button>
        </div>
    </nav>

    {{-- Mobile menu --}}
    <div id="navbar-centered-mobile" x-show="open" x-cloak @click.outside="open = false" class="border-t border-border md:hidden">
        <ul class="space-y-2 px-4 py-4">
            @foreach ($links as $link)
                <li>
                    <a href="{{ $link['href'] }}" class="block rounded-md px-4 py-2 text-sm font-medium text-muted-foreground hover:bg-muted hover:text-foreground">
                        {{ __($link['label']) }}
                    </a>
                </li>
            @endforeach
            <li class="flex flex-col gap-2 pt-2">
                <x-ui.button :href="$signInHref" size="sm" variant="outline" class="w-full">{{ __($signInCta) }}</x-ui.button>
                <x-ui.button :href="$primaryHref" size="sm" class="w-full">{{ __($primaryCta) }}</x-ui.button>
            </li>
        </ul>
    </div>
</header>

Installation

terminal
php artisan ui:add blocks/header-centered

Installs these dependencies automatically:

Registry contract

Install confidence

php artisan ui:add blocks/header-centered writes only the generated targets below. The CLI validates each file hash before writing and prompts before replacing local changes unless --force is used.

Version
1.0.5
License
open
Stability
stable
Contract
v1
Foundation
≥ 1.0.0
Type Generated target
blade resources/views/blocks/header-centered.blade.php

Registry dependencies

brand button

Package dependencies

composer: jml/brok:^0.2

Use with AI

A brief for your coding agent: what the block is, the install command, how to render it, its props and the rules. Copy it, or open a prompt about this block in an assistant.

header-centered.md
# Brok UI block: Navbar Centered (`header-centered`)

A sticky header with a centered wordmark, navigation on the start side, and an auth + primary call-to-action pair on the end side, with a mobile menu.

Brok UI is a Laravel Blade registry. `ui:add` copies this block into the app as plain Blade the app owns; it composes installed `<brok:*>` primitives and semantic design tokens.

## Install

```bash
php artisan ui:add blocks/header-centered
```

## Render it

```blade
<x-blocks.header-centered />
```

## Props

- `brand` (string, default `Acme`) — Brand wordmark text.
- `brand-href` (string, default `#`) — URL the brand mark links to.
- `links` (mixed|null, default `null`) — Array of nav links ({label, href}) shown on the start side; defaults to a built-in set of three links.
- `sign-in-cta` (string, default `Sign in`) — Text for the sign-in button.
- `sign-in-href` (string, default `#`) — URL the sign-in button points to.
- `primary-cta` (string, default `Get started`) — Text for the primary call-to-action button.
- `primary-href` (string, default `#`) — URL the call-to-action button points to.

## Use when

- Building a sticky header with the brand wordmark centered and navigation split to the start and end sides.
- Pairing a sign-in link with a primary call-to-action on the end side, collapsing into a mobile menu below md.

## Avoid when

- Use header-navbar instead when the brand should sit at the start of the bar rather than centered.

## Rules

- Render the installed block with `<x-blocks.header-centered />` and pass data through its props; edit the copied file only for structural changes.
- Keep the semantic design tokens (`bg-background`, `text-muted-foreground`); never swap in raw colour utilities.
- Keep the `data-slot` attributes and the logical (start/end) spacing so the markup still mirrors under `dir="rtl"`.

## Links

- Docs: https://brokui.dev/blocks/header-centered
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/header-centered.json

Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.

Guidance

Use when

  • Building a sticky header with the brand wordmark centered and navigation split to the start and end sides.
  • Pairing a sign-in link with a primary call-to-action on the end side, collapsing into a mobile menu below md.

Avoid when

  • Use header-navbar instead when the brand should sit at the start of the bar rather than centered.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.
Anatomy
start nav links centered brand mark sign-in and CTA actions mobile menu toggle mobile menu panel

Usage

Render the block as a component, passing data where useful:

resources/views/welcome.blade.php Blade
<x-blocks.header-centered />

Built from primitives

Composes <brok:*> Semantic tokens Re-themeable RTL-ready

This block composes installed <brok:*> primitives and semantic design tokens only — it does not reimplement any primitive. Re-theme it (light, dark, admin, customer) by editing CSS variables; flip the preview to RTL to confirm it mirrors.

Source

The exact, editable file ui:add writes into your app. The preview above renders this same source — there are no preview-only blocks.

resources/views/blocks/header-centered.blade.php Blade
@props([
    'brand' => 'Acme',
    'brandHref' => '#',
    'links' => null,
    'signInCta' => 'Sign in',
    'signInHref' => '#',
    'primaryCta' => 'Get started',
    'primaryHref' => '#',
])

@php
    // Centered-logo header: the wordmark sits in the middle, with navigation
    // split to the start side and the auth/CTA pair to the end side. Logical
    // (start/end) alignment keeps the split correct under dir="rtl".
    $links ??= [
        ['label' => 'Getting started', 'href' => '#'],
        ['label' => 'Components', 'href' => '#'],
        ['label' => 'Documentation', 'href' => '#'],
    ];
@endphp

<header
    x-data="{ open: false }"
    {{ $attributes->merge(['class' => 'sticky top-0 z-40 w-full border-b border-border bg-background/90 text-foreground backdrop-blur']) }}
>
    <nav class="mx-auto grid max-w-7xl grid-cols-2 items-center gap-4 px-4 py-4 sm:px-6 md:grid-cols-3 lg:px-8" aria-label="{{ __('Main') }}">
        {{-- Start: primary navigation (desktop) / menu toggle (mobile) --}}
        <div class="flex items-center">
            <ul class="hidden items-center gap-2 md:flex">
                @foreach ($links as $link)
                    <li>
                        <a href="{{ $link['href'] }}" class="rounded-md px-4 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
                            {{ __($link['label']) }}
                        </a>
                    </li>
                @endforeach
            </ul>

            <button
                type="button"
                class="inline-flex size-10 items-center justify-center rounded-md text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring md:hidden"
                :aria-expanded="open.toString()"
                aria-controls="navbar-centered-mobile"
                @click="open = ! open"
            >
                <span class="sr-only">{{ __('Toggle menu') }}</span>
                <svg class="size-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                    <path x-show="! open" d="M4 6h16M4 12h16M4 18h16" stroke-linecap="round" />
                    <path x-show="open" x-cloak d="M6 6l12 12M18 6L6 18" stroke-linecap="round" />
                </svg>
            </button>
        </div>

        {{-- Center: brand --}}
        <div class="flex justify-end md:justify-center">
            <x-ui.brand :href="$brandHref" :label="$brand" collapse />
        </div>

        {{-- End: auth + primary CTA --}}
        <div class="hidden items-center justify-end gap-2 md:flex">
            <x-ui.button :href="$signInHref" size="sm" variant="ghost">{{ __($signInCta) }}</x-ui.button>
            <x-ui.button :href="$primaryHref" size="sm">{{ __($primaryCta) }}</x-ui.button>
        </div>
    </nav>

    {{-- Mobile menu --}}
    <div id="navbar-centered-mobile" x-show="open" x-cloak @click.outside="open = false" class="border-t border-border md:hidden">
        <ul class="space-y-2 px-4 py-4">
            @foreach ($links as $link)
                <li>
                    <a href="{{ $link['href'] }}" class="block rounded-md px-4 py-2 text-sm font-medium text-muted-foreground hover:bg-muted hover:text-foreground">
                        {{ __($link['label']) }}
                    </a>
                </li>
            @endforeach
            <li class="flex flex-col gap-2 pt-2">
                <x-ui.button :href="$signInHref" size="sm" variant="outline" class="w-full">{{ __($signInCta) }}</x-ui.button>
                <x-ui.button :href="$primaryHref" size="sm" class="w-full">{{ __($primaryCta) }}</x-ui.button>
            </li>
        </ul>
    </div>
</header>

Ownership & lifecycle

Owner, release state, review evidence and adoption for this item.
Owner
Platform UI (@JoshJML)
Current version
1.0.5
Status
Stable
License
open
Deprecation
Not deprecated
Contract
v1
Foundation
≥ 1.0.0