Heading
Page-level heading with a title and an optional action slot for buttons.
The heading displays the title at the top of a page, with an optional slot for the buttons that act on the page. Every index page of the admin panel starts with one: products, categories, customers and the others.
Preview
The preview shows a page title with a primary button on the right.
Usage
Pass the title as an attribute and the buttons in the action slot. The products page opens its creation slide-over this way:
<x-shopper::heading title="Products">
<x-slot:action>
@can('products.create')
<x-filament::button
type="button"
wire:click="$dispatch('openPanel', { component: 'shopper-slide-overs.add-product' })"
>
Add Product
</x-filament::button>
@endcan
</x-slot:action>
</x-shopper::heading>On small screens the title and the action stack. From the sm breakpoint they sit on one line, the action aligned to the right.
Props and Slots
The heading takes one prop and one named slot.
| Prop | Default | Description |
|---|---|---|
x-shopper::headingrenders a <div> element | ||
titlestring | Slot | null | The page title. A string is rendered in an |
actionSlot | - | Buttons or other controls, displayed on the right of the title. |
Examples
The examples below cover a title alone, one or several actions, and a custom title.
Simple Heading
Without the action slot, the heading only shows the title.
This Blade renders the heading with its title only:
<x-shopper::heading title="Dashboard" />Heading with Action Button
The categories page opens the category form in a slide-over:
This Blade puts the button in the action slot, shows it only to users with the categories.create permission, and opens the shopper-slide-overs.category-form slide-over on click:
<x-shopper::heading title="Categories">
<x-slot:action>
@can('categories.create')
<x-filament::button
type="button"
wire:click="$dispatch('openPanel', { component: 'shopper-slide-overs.category-form' })"
>
Add Category
</x-filament::button>
@endcan
</x-slot:action>
</x-shopper::heading>Heading with Multiple Actions
Wrap several buttons in a flex container. The methods called here, export and create, belong to your Livewire component:
This Blade puts the two buttons in the action slot, inside a div that lines them up with a gap:
<x-shopper::heading title="Gift Cards">
<x-slot:action>
<div class="flex items-center gap-2">
<x-filament::button color="gray" wire:click="export">
Export
</x-filament::button>
<x-filament::button wire:click="create">
New Gift Card
</x-filament::button>
</div>
</x-slot:action>
</x-shopper::heading>Custom Title Slot
Pass a title slot to show more than text, like a badge above the title. The slot replaces the h2, so add it yourself with the same classes. The product edit page does this to show the product type:
<x-shopper::heading>
<x-slot:title>
<div class="space-y-2">
<x-filament::badge color="success" class="inline-flex">
Published
</x-filament::badge>
<h2 class="font-heading text-sh-fg text-2xl font-bold sm:truncate sm:text-3xl sm:leading-9">
Leather Weekender Bag
</h2>
</div>
</x-slot:title>
<x-slot:action>
<x-filament::button color="danger" wire:click="unpublish">
Unpublish
</x-filament::button>
</x-slot:action>
</x-shopper::heading>Blade Component Source
The view is resources/views/components/heading.blade.php in the shopper/framework package:
@blaze
@props([
'title' => null,
])
<div
{{ $attributes->twMerge(['class' => 'space-y-3 sm:flex sm:items-center sm:justify-between sm:space-x-4 sm:space-y-0']) }}
>
@if ($title instanceof \Illuminate\View\ComponentSlot)
{{ $title }}
@else
<h2 class="font-heading text-sh-fg text-2xl font-bold sm:truncate sm:text-3xl">
{{ $title }}
</h2>
@endif
@isset($action)
{{ $action }}
@endisset
</div>Last updated on
Edit on GitHub