Navigation
stepper
Shows progress through a multi-step flow: completed, current, upcoming and failed steps, horizontal or vertical.
- Account (Completed) Your details
- Shipping (Completed) Where it goes
-
Payment (Current) Card or transfer
-
Confirm (Upcoming) Review and place
-
Upload (Completed)
-
Validate (Error)
-
Import (Upcoming)
-
Order placed (Completed)
-
Packed (Completed)
-
Shipped (Completed)
-
Delivered (Completed)
@php
// Normally comes from the controller, e.g. the checkout step stored in the session.
$steps = [
['title' => 'Account', 'description' => 'Your details', 'href' => '#account'],
['title' => 'Shipping', 'description' => 'Where it goes', 'href' => '#shipping'],
['title' => 'Payment', 'description' => 'Card or transfer'],
['title' => 'Confirm', 'description' => 'Review and place'],
];
@endphp
<div class="flex w-full max-w-2xl flex-col gap-10">
<x-ui.stepper :steps="$steps" :current="3" />
<div class="grid gap-10 sm:grid-cols-2">
<x-ui.stepper :steps="['Upload', 'Validate', 'Import']" :current="2" :error="2"
orientation="vertical" />
<x-ui.stepper :steps="['Order placed', 'Packed', 'Shipped', 'Delivered']" :current="5"
orientation="vertical" />
</div>
</div>
Installation
php artisan ui:add stepper
1. Install dependencies
- composer:
gehrisandro/tailwind-merge-laravel
2.
Copy the source into
resources/views/components/ui/
resources/views/components/ui/stepper.blade.php
@props([
// Strings, or ['title' => ..., 'description' => ..., 'href' => ...].
'steps' => [],
// 1-based index of the active step. Past the last step = all complete.
'current' => 1,
'orientation' => 'horizontal',
// 1-based index of a step that failed, or null.
'error' => null,
'label' => 'Progress',
'labels' => [],
])
@php
$labels = array_merge(
[
'complete' => 'Completed',
'current' => 'Current',
'upcoming' => 'Upcoming',
'error' => 'Error',
],
$labels,
);
$vertical = $orientation === 'vertical';
$classes = \TailwindMerge\Laravel\Facades\TailwindMerge::merge(
$vertical ? 'flex flex-col' : 'flex w-full items-start',
$attributes->get('class'),
);
$items = [];
foreach (array_values($steps) as $index => $step) {
$number = $index + 1;
$step = is_array($step) ? $step : ['title' => $step];
$state = match (true) {
$error !== null && (int) $error === $number => 'error',
$number < (int) $current => 'complete',
$number === (int) $current => 'current',
default => 'upcoming',
};
$items[] = [
'number' => $number,
'title' => $step['title'] ?? '',
'description' => $step['description'] ?? null,
// Only finished steps link back; the user cannot skip ahead.
'href' => $state === 'complete' ? $step['href'] ?? null : null,
'state' => $state,
'last' => $number === count($steps),
'connector' => $number < (int) $current ? 'complete' : 'upcoming',
];
}
@endphp
<ol aria-label="{{ $label }}" data-orientation="{{ $orientation }}"
{{ $attributes->except('class')->merge(['class' => $classes]) }}>
@foreach ($items as $item)
@php
$indicator = match ($item['state']) {
'complete' => 'bg-primary text-primary-foreground border-primary',
'current' => 'border-primary bg-background text-primary ring-4 ring-primary/20',
'error' => 'bg-destructive text-destructive-foreground border-destructive',
default => 'border-input bg-background text-muted-foreground',
};
$title = match ($item['state']) {
'upcoming' => 'text-muted-foreground',
'error' => 'text-destructive',
default => 'text-foreground',
};
$connector = match ($item['connector']) {
'complete' => 'bg-primary',
default => 'bg-border',
};
$tag = $item['href'] ? 'a' : 'div';
@endphp
<li data-state="{{ $item['state'] }}"
@if ($item['state'] === 'current') aria-current="step" @endif
class="{{ $vertical ? 'relative flex gap-3 pb-8 last:pb-0' : 'relative flex flex-1 flex-col items-center px-2 text-center' }}">
@unless ($item['last'])
{{-- Logical start/end, so the line runs the right way in RTL. --}}
<span aria-hidden="true"
class="{{ $vertical ? 'absolute top-10 bottom-2 start-[calc(1rem-0.5px)] w-px' : 'absolute top-4 start-[calc(50%+1.5rem)] end-[calc(-50%+1.5rem)] h-px' }} {{ $connector }}"></span>
@endunless
<{{ $tag }} @if ($item['href']) href="{{ $item['href'] }}" @endif
class="{{ $vertical ? 'flex gap-3' : 'flex flex-col items-center gap-2' }} rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 {{ $item['href'] ? 'group/step' : '' }}">
<span aria-hidden="true"
class="relative z-10 flex size-8 shrink-0 items-center justify-center rounded-full border-2 text-sm font-medium transition-colors {{ $indicator }}">
@if ($item['state'] === 'complete')
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round"
class="size-4">
<path d="M20 6 9 17l-5-5" />
</svg>
@elseif ($item['state'] === 'error')
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="3"
stroke-linecap="round" stroke-linejoin="round"
class="size-4">
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
@else
{{ $item['number'] }}
@endif
</span>
<span class="{{ $vertical ? 'flex flex-col pt-1' : 'flex flex-col' }}">
<span
class="text-sm font-medium {{ $title }} group-hover/step:underline">
{{ $item['title'] }}
<span class="sr-only">({{ $labels[$item['state']] }})</span>
</span>
@if ($item['description'])
<span
class="text-xs text-muted-foreground">{{ $item['description'] }}</span>
@endif
</span>
</{{ $tag }}>
</li>
@endforeach
</ol>
Usage
<x-ui.stepper :steps="['Account', 'Billing', 'Confirm']" :current="2" />
{{-- With descriptions, links back to finished steps, vertical. --}}
<x-ui.stepper orientation="vertical" :current="$step" :steps="[
['title' => 'Account', 'description' => 'Your details', 'href' => route('signup', ['step' => 1])],
['title' => 'Billing', 'description' => 'Plan and card', 'href' => route('signup', ['step' => 2])],
['title' => 'Confirm', 'description' => 'Review and finish'],
]" />
{{-- A failed step, plus translated screen-reader labels. --}}
<x-ui.stepper :steps="['Upload', 'Validate', 'Import']" :current="2" :error="2"
:labels="['complete' => 'مكتمل', 'current' => 'الحالي', 'upcoming' => 'قادم', 'error' => 'خطأ']" />
{{-- The controller owns the step. No JavaScript involved:
public function show(Request $request)
{
$step = min(max((int) $request->query('step', 1), 1), 3);
return view('signup', ['step' => $step]);
}
public function store(Request $request)
{
// validate the current step, then move on
return redirect()->route('signup', ['step' => $request->integer('step') + 1]);
}
--}}
Pure markup, no JavaScript: the server decides current (1-based; past the last step marks all complete). steps takes strings or ['title', 'description', 'href'] arrays; href only links completed steps. orientation is horizontal or vertical, error marks a failed step, and labels overrides the screen-reader status words (complete, current, upcoming, error).
Props
Every prop with its default. Pass any of them as attributes, using : to bind a PHP value.
@props([
// Strings, or ['title' => ..., 'description' => ..., 'href' => ...].
'steps' => [],
// 1-based index of the active step. Past the last step = all complete.
'current' => 1,
'orientation' => 'horizontal',
// 1-based index of a step that failed, or null.
'error' => null,
'label' => 'Progress',
'labels' => [],
])