-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathStepperExtendedExample1.razor
More file actions
230 lines (223 loc) · 11.8 KB
/
StepperExtendedExample1.razor
File metadata and controls
230 lines (223 loc) · 11.8 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@namespace MudExtensions.Docs.Examples
@inject ISnackbar Snackbar
@using MudBlazor.Extensions
@using MudExtensions.Utilities
<MudGrid Class="cursor-default">
<MudItem xs="12" sm="8">
<MudStepperExtended @ref="_stepper" Class="mud-width-full" ContentStyle="min-height: 400px" Linear="_linear" Vertical="_vertical" Color="_color" Variant="_variant"
Animation="_animation" ShowPreviousButton="_showPreviousButton" ShowNextButton="_showNextButton"
ShowSkipButton="_showSkipButton" ShowStepResultIndicator="_showStepResultIndicator" HeaderBadgeView="_headerBadgeView"
HeaderTextView="_headerTextView" PreventStepChangeAsync="new Func<StepChangeDirection, int, Task<bool>>(CheckChange)" LocalizedStrings="GetLocalizedStrings()"
MobileView="_mobileView" IconActionButtons="_iconActionButtons" Loading="_loading" HeaderSize="_headerSize"
StepperActionsJustify="_stepperActionsJustify" MobileBreakpoint="_mobileBreakpoint">
<StaticContent>
@if (_showStaticContent)
{
<MudStack Row="true" AlignItems="AlignItems.Center">
<MudAvatar Color="_color">ST</MudAvatar>
<MudText>This is a static content which shows with each step.</MudText>
</MudStack>
}
</StaticContent>
<ChildContent>
<MudStepExtended Icon="@Icons.Material.Filled.Approval" Title="Customer Info" StatusChanged="StatusChanged">
<ChildContent>
<MudForm @ref="_form">
<MudStack>
<MudTextField T="string" Label="Name" Variant="_variant" Required="true" />
<MudTextField T="string" Label="Last Name" Variant="_variant" />
<MudTextField T="string" Label="Adress" Variant="_variant" />
</MudStack>
</MudForm>
</ChildContent>
</MudStepExtended>
<MudStepExtended Title="Booking Spec." Icon="@Icons.Material.Filled.MoreVert" Optional="true">
<ChildContent>
<MudCheckBox T="bool" Label="Early Check-in" Color="_color" />
<MudCheckBox T="bool" Label="Late Check-out" Color="_color" />
<MudCheckBox T="bool" Label="Twin Bed" Color="_color" />
</ChildContent>
</MudStepExtended>
<MudStepExtended Icon="@Icons.Material.Filled.Money" Title="Payment">
<ChildContent>
<MudForm @ref="_form2">
<MudStack>
<MudTextField T="string" Label="Card Number" Variant="_variant" Required="true" />
<MudStack Row="true">
<MudTextField T="string" Label="Expire Date" Variant="_variant" Required="true" />
<MudTextField T="string" Label="CVC" Variant="_variant" Required="true" />
</MudStack>
</MudStack>
</MudForm>
</ChildContent>
</MudStepExtended>
@if (_addResultStep)
{
<MudStepExtended Icon="@Icons.Material.Filled.Alarm" Title="Result Step" IsResultStep="true">
<ChildContent>
<div class="d-flex flex-column align-center justify-center" style="height: 200px">
<MudIconButton Icon="@Icons.Material.Filled.DoneAll" Size="Size.Large" Variant="Variant.Filled" Color="Color.Success" />
<MudText>Your reservation successfully completed.</MudText>
</div>
</ChildContent>
</MudStepExtended>
}
</ChildContent>
<ActionContent>
@if (!_stepper.IsAllStepsCompleted() && _showCustomButton)
{
<MudButton Color="Color.Secondary" Variant="_variant" OnClick="@(() => Snackbar.Add("Custom cancel button clicked.", Severity.Info))">Cancel</MudButton>
}
</ActionContent>
</MudStepperExtended>
</MudItem>
<MudItem xs="12" sm="4">
<MudStack Spacing="4">
<MudNumericField @bind-Value="_activeIndex" Label="Change ActiveIndex" @bind-Value:after="(async() => await _stepper.GoToStepAsync(_activeIndex))" Variant="Variant.Outlined" Margin="Margin.Dense" />
<MudCheckBox @bind-Value="_vertical" Color="Color.Secondary" Label="Vertical" Dense="true" />
<MudCheckBox @bind-Value="_linear" Color="Color.Secondary" Label="Linear" Dense="true" />
<MudCheckBox @bind-Value="_animation" Color="Color.Secondary" Label="Enable Animation" Dense="true" />
<MudCheckBox @bind-Value="_showPreviousButton" Color="Color.Secondary" Label="Show Previous Step Action Button" Dense="true" />
<MudCheckBox @bind-Value="_showNextButton" Color="Color.Secondary" Label="Show Next Step Action Button" Dense="true" />
<MudCheckBox @bind-Value="_showSkipButton" Color="Color.Secondary" Label="Show Skip Step Action Button" Dense="true" />
<MudCheckBox @bind-Value="_showStepResultIndicator" Color="Color.Secondary" Label="Show Step Result Indicator" Dense="true" />
<MudSwitchM3 @bind-Value="_mobileView" Color="Color.Secondary" Label="Mobile View" />
<MudSwitchM3 @bind-Value="_iconActionButtons" Color="Color.Secondary" Label="IconActionButtons" />
<MudSwitchM3 @bind-Value="_addResultStep" Color="Color.Secondary" Label="Has Result Step" />
<MudSwitchM3 @bind-Value="_checkValidationBeforeComplete" Color="Color.Secondary" Label="Check Validation Before Complete Step" />
<MudSwitchM3 @bind-Value="_customLocalization" Color="Color.Secondary" Label="Custom Localization (German)" />
<MudSwitchM3 @bind-Value="_showStaticContent" Color="Color.Secondary" Label="Show Some Static Content" />
<MudSwitchM3 @bind-Value="_showCustomButton" Color="Color.Secondary" Label="Show Custom Button" />
<MudSelect @bind-Value="_variant" Variant="Variant.Outlined" Label="Variant" Margin="Margin.Dense" Dense="true">
@foreach (Variant item in Enum.GetValues<Variant>())
{
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="_color" Variant="Variant.Outlined" Label="Color" Margin="Margin.Dense" Dense="true">
@foreach (Color item in Enum.GetValues<Color>())
{
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="_headerTextView" Variant="Variant.Outlined" Label="Header Text View" Margin="Margin.Dense" Dense="true">
@foreach (HeaderTextView item in Enum.GetValues<HeaderTextView>())
{
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="_headerBadgeView" Variant="Variant.Outlined" Label="Header Badge View" Margin="Margin.Dense" Dense="true">
@foreach (HeaderBadgeView item in Enum.GetValues<HeaderBadgeView>())
{
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="_stepperActionsJustify" Variant="Variant.Outlined" Label="Action Buttons Justify" Margin="Margin.Dense" Dense="true">
@foreach (StepperActionsJustify item in Enum.GetValues<StepperActionsJustify>())
{
<MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem>
}
</MudSelect>
<MudSelectExtended T="Breakpoint ?" @bind-Value="_mobileBreakpoint" Variant="Variant.Outlined" Label="Mobile Breakpoint" Margin="Margin.Dense" Dense="true">
<MudSelectItemExtended T="Breakpoint?" Value="null">None</MudSelectItemExtended>
@foreach (Breakpoint item in Enum.GetValues<Breakpoint>())
{
<MudSelectItemExtended T="Breakpoint ?" Value="item">@item.ToDescriptionString()</MudSelectItemExtended>
}
</MudSelectExtended>
<MudSelectExtended @bind-Value="_headerSize" ItemCollection="@(Enum.GetValues<Size>())" Variant="Variant.Outlined" Label="Header Size" Margin="Margin.Dense" Dense="true" />
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="(() => _stepper?.Reset())">Reset</MudButton>
</MudStack>
</MudItem>
</MudGrid>
@code {
MudStepperExtended _stepper = default!;
MudForm _form = default!;
MudForm _form2 = default!;
bool _checkValidationBeforeComplete = false;
bool _linear;
bool _mobileView;
bool _iconActionButtons;
Variant _variant = Variant.Filled;
HeaderBadgeView _headerBadgeView = HeaderBadgeView.All;
HeaderTextView _headerTextView = HeaderTextView.All;
bool _animation = true;
bool _showPreviousButton = true;
bool _showNextButton = true;
bool _showSkipButton = true;
bool _showStepResultIndicator = true;
bool _addResultStep = true;
bool _customLocalization = false;
Color _color = Color.Primary;
int _activeIndex = 0;
bool _loading;
bool _showStaticContent = false;
bool _showCustomButton = false;
bool _vertical = false;
Size _headerSize = Size.Medium;
StepperActionsJustify _stepperActionsJustify = StepperActionsJustify.SpaceBetween;
Breakpoint? _mobileBreakpoint;
private async Task<bool> CheckChange(StepChangeDirection direction, int targetIndex)
{
if (_checkValidationBeforeComplete == true)
{
// Always allow stepping backwards, even if forms are invalid
if (direction == StepChangeDirection.Backward)
{
return false;
}
if (_stepper?.GetActiveIndex() == 0)
{
_loading = true;
StateHasChanged();
await Task.Delay(1000);
await _form.Validate();
_loading = false;
StateHasChanged();
return !_form.IsValid;
}
else if (_stepper?.GetActiveIndex() == 2)
{
_loading = true;
StateHasChanged();
await Task.Delay(1000);
await _form2.Validate();
_loading = false;
StateHasChanged();
return !_form2.IsValid;
}
else
{
return false;
}
}
else
{
return false;
}
}
private void StatusChanged(StepStatus status)
{
Snackbar.Add($"First step {status.ToDescriptionString()}.", Severity.Info);
}
private StepperLocalizedStrings GetLocalizedStrings()
{
if (_customLocalization == false)
{
return new StepperLocalizedStrings();
}
else
{
return new StepperLocalizedStrings()
{
Completed = "Abgeschlossen",
Finish = "Fertig",
Next = "Nächste",
Optional = "Optional",
Previous = "Früher",
Skip = "überspringen",
Skipped = "übersprungen",
};
}
}
}