Repository navigation
Expand file tree
/
Copy pathWizard.php
More file actions
130 lines (113 loc) · 3.32 KB
/
Copy pathWizard.php
File metadata and controls
130 lines (113 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Modals;
use NyonCode\WireCore\Foundation\Concerns\HasModalProperties;
use NyonCode\WireCore\Foundation\Contracts\WizardStep;
use NyonCode\WireCore\Modals\Concerns\HasFooterActions;
use NyonCode\WireCore\Modals\Concerns\HasModalIcon;
use NyonCode\WireCore\Modals\Contracts\ModalContract;
/**
* Multi-step wizard modal configuration.
*
* Provides a step-by-step wizard experience inside a modal.
* Each step can have its own schema, validation, and lifecycle hooks.
*
* Usage:
* Wizard::make()
* ->heading('Create User')
* ->steps([
* ModalStep::make('Basic Info')
* ->icon('user')
* ->schema([...])
* ->validation([...]),
* ModalStep::make('Settings')
* ->schema([...]),
* ]);
*
* @phpstan-consistent-constructor
*/
class Wizard implements ModalContract
{
use HasFooterActions;
use HasModalIcon;
use HasModalProperties;
/** @var array<int, WizardStep|array<string, mixed>> */
protected array $steps = [];
protected bool $skippable = false;
public static function make(): static
{
return new static;
}
/**
* Define wizard steps.
*
* @param array<int, WizardStep|array<string, mixed>> $steps
*/
public function steps(array $steps): static
{
$this->steps = $steps;
return $this;
}
/**
* Allow skipping steps (non-linear navigation).
*/
public function skippable(bool $skippable = true): static
{
$this->skippable = $skippable;
return $this;
}
/**
* @return array<int, WizardStep|array<string, mixed>>
*/
public function getSteps(): array
{
return $this->steps;
}
public function getTotalSteps(): int
{
return count($this->steps);
}
public function isSkippable(): bool
{
return $this->skippable;
}
/**
* Serialize steps for frontend config.
*
* @return array<int, array<string, mixed>>
*/
public function getStepsConfig(mixed $context = null): array
{
return array_map(function ($step) use ($context) {
if ($step instanceof WizardStep) {
return $step->toArray($context);
}
return $step;
}, $this->steps);
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'id' => $this->getId(),
'heading' => $this->getHeading(),
'description' => $this->getDescription(),
'icon' => $this->getIcon(),
'iconColor' => $this->getIconColor(),
'color' => $this->getColor(),
'width' => $this->getWidth(),
'maxHeight' => $this->getMaxHeight(),
'closeOnClickAway' => $this->shouldCloseOnClickAway(),
'closeOnEscape' => $this->shouldCloseOnEscape(),
'submitLabel' => $this->getSubmitLabel(),
'cancelLabel' => $this->getCancelLabel(),
'stickyFooter' => $this->hasStickyFooter(),
'stickyHeader' => $this->hasStickyHeader(),
'steps' => $this->getStepsConfig(),
'totalSteps' => $this->getTotalSteps(),
'skippable' => $this->isSkippable(),
];
}
}