v0.0.2
Demos (demo panel, opens in a new tab)

Form wizard

A wizard that splits a long form into steps; finished steps can be clicked to go back.

zb:stepper zubazar/ui-pro

PRO

This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →

Basic usage

Basic usage: view
BLADE

steps is a key => title array; put each step's content in an zb:stepper.step with the same key and give the buttons data-stepper-next and data-stepper-previous.

blade
<zb:stepper :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
    <zb:stepper.step name="project"><zb:input name="t_name" label="Project name" /></zb:stepper.step>
    <zb:stepper.step name="team"><zb:input name="t_people" label="Number of people" type="number" /></zb:stepper.step>
    <zb:stepper.step name="confirm"><zb:alert variant="success">The details are ready. Press Save to create the project.</zb:alert></zb:stepper.step>
    <div class="mt-6 flex justify-between">
        <zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
        <zb:button data-stepper-next class="group-data-last/stepper:hidden">Next</zb:button>
        <zb:button variant="success" class="hidden group-data-last/stepper:inline-flex" x-on:click="$dispatch('toast', { type: 'success', message: 'Project saved.' })">Save</zb:button>
    </div>
</zb:stepper>
PropValues
stepskey => title
zb:stepper.step nameThe key in steps
data-stepper-next · data-stepper-previousGoes to the next / previous step
group-data-first/stepper · group-data-last/stepperClasses for the first / last step

Steps with descriptions

Steps with descriptions: view
BLADE

Give a step as a ['title' => …, 'description' => …] array; the description shows below the title.

blade
<zb:stepper :steps="[
    'project' => ['title' => 'Project', 'description' => 'Basic details'],
    'team' => ['title' => 'Team', 'description' => 'Team members'],
    'confirm' => ['title' => 'Confirmation', 'description' => 'Review and save'],
]">
    <zb:stepper.step name="project"><zb:input name="a_name" label="Project name" /></zb:stepper.step>
    <zb:stepper.step name="team"><zb:input name="a_people" label="Number of people" type="number" /></zb:stepper.step>
    <zb:stepper.step name="confirm"><p class="text-sm text-dim">Review the details and save.</p></zb:stepper.step>

    <div class="mt-6 flex justify-between">
        <zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
        <zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
    </div>
</zb:stepper>
PropValues
titleStep title
descriptionShort description below the title

With icons

With icons: view
BLADE

variant="icons" shows each step's icon instead of a number; finished steps keep the icon too.

blade
<zb:stepper variant="icons" :steps="[
    'account' => ['title' => 'Account', 'icon' => 'user'],
    'security' => ['title' => 'Security', 'icon' => 'lock-closed'],
    'notifications' => ['title' => 'Notifications', 'icon' => 'bell'],
]">
    <zb:stepper.step name="account"><zb:input name="i_name" label="Full name" /></zb:stepper.step>
    <zb:stepper.step name="security"><zb:input name="i_password" type="password" label="Password" viewable /></zb:stepper.step>
    <zb:stepper.step name="notifications"><zb:switch name="i_sms" label="SMS notifications" checked /></zb:stepper.step>

    <div class="mt-6 flex justify-between">
        <zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
        <zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
    </div>
</zb:stepper>
PropValues
variantnumbered | icons
iconzb:icon name

Starting step

Starting step: view
BLADE

current picks the step the wizard opens on, and the steps before it count as finished.

blade
<zb:stepper current="team" :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
    <zb:stepper.step name="project"><zb:input name="b_name" label="Project name" value="Mobile app" /></zb:stepper.step>
    <zb:stepper.step name="team"><zb:input name="b_people" label="Number of people" type="number" /></zb:stepper.step>
    <zb:stepper.step name="confirm"><p class="text-sm text-dim">Review the details and save.</p></zb:stepper.step>

    <div class="mt-6 flex items-center justify-between">
        <zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
        <zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
    </div>
</zb:stepper>
PropValues
currentKey of the step shown on open
data-stepThe current step's key on the root

With Livewire

BLADE

Wrap the wizard in a form and make the last step's button type="submit"; the fields of all steps are validated together.

blade
<form wire:submit="save">
    <zb:stepper :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
        <zb:stepper.step name="project"><zb:input wire:model="name" label="Project name" required /></zb:stepper.step>
        <zb:stepper.step name="team"><zb:input wire:model="peopleCount" label="Number of people" type="number" /></zb:stepper.step>
        <zb:stepper.step name="confirm">…</zb:stepper.step>

        <div class="mt-6 flex justify-between">
            <zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
            <zb:button data-stepper-next class="group-data-last/stepper:hidden">Next</zb:button>
            <zb:button class="hidden group-data-last/stepper:inline-flex" type="submit">Save</zb:button>
        </div>
    </zb:stepper>
</form>
PropValues
type="submit"Submits the form on the last step

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
steps—[]key => title or key => ['title', 'description', 'icon']
current—nullKey of the step shown on open; the first step when empty
variant—numberednumbered · icons
backwardbooleantrueA finished step can be reopened; false: the server leads the steps and a finished step stays closed
wire:model / x-model— — Binds the current step both ways; the component checks a step and moves on itself
step: name— — Key of the step (required); same as in steps
data-stepper-next · data-stepper-previous— — A button in the content: goes to the next / previous step
data-step · data-first · data-last— — On the root: the current step, on the first / last step (classes with group/stepper)
Alpine: step— — Key of the current step (the 2.x way, on a page with Alpine)
Alpine: index, steps— — Current position (zero-based) and the step keys
Alpine: next(), previous()— — Goes to the next / previous step
Alpine: goTo(key)— — Goes back to a finished step (while backward is true)
Alpine: isFirst, isLast— — true on the first / last step

Slots: zb:stepper: zb:stepper.step items and buttons. zb:stepper.step: the step's content; attributes such as class are added to the step's container.

Developer notes

Events, hooks and details
  • Later steps are reached with the buttons only; the buttons need no Alpine.
  • The root shows the current step with data-step and the first and last steps with data-first / data-last: group-data-last/stepper:hidden hides a button on the last step.
  • On pages with Alpine the 2.x style (next(), isLast…) works too.
  • Steps are only hidden, not removed; an error in a hidden step shows when the user returns to it.
Zubazar UI · ZubazarDesigned for people.