PHP code example of la-souris / filament-state-stepper

1. Go to this page and download the library: Download la-souris/filament-state-stepper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

la-souris / filament-state-stepper example snippets


use LaSouris\FilamentStateStepper\StateStepperPlugin;

$panel->plugin(StateStepperPlugin::make());

use LaSouris\FilamentStateStepper\Infolists\Components\StateStepper;

StateStepper::make('status')
    ->stateClass(OrderState::class)
    ->completedStates(fn ($record) => $record->getCompletedStates())
    ->errorStates(['cancelled']);

StateStepper::make('status')
    ->options([
        'draft' => 'Draft',
        'review' => 'In Review',
        'approved' => 'Approved',
    ])
    ->icons([
        'draft' => 'heroicon-o-pencil',
        'review' => 'heroicon-o-eye',
        'approved' => 'heroicon-o-check-circle',
    ])
    ->completedStates(['draft'])
    ->errorStates(['rejected']);

use LaSouris\FilamentStateStepper\Contracts\HasStepperLabel;
use Filament\Support\Contracts\HasLabel;

class ProcessingState extends OrderState implements HasStepperLabel, HasLabel
{
    public function getLabel(): string
    {
        return 'Processed';        // shown when completed
    }

    public function getCurrentLabel(): string
    {
        return 'Processing...';    // shown when current
    }

    public function getUpcomingLabel(): string
    {
        return 'Processing';       // shown when upcoming
    }
}

StateStepper::make('status')
    ->stateClass(OrderState::class)
    ->completedColor('info')
    ->currentColor('primary')
    ->upcomingColor('gray')
    ->errorColor('danger');

StateStepper::make('status')
    ->stateClass(OrderState::class)
    ->hideStatesFor(fn ($record) => $record->isCancelled() ? [] : ['cancelled']);