-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathStepperExtendedExample3.razor
More file actions
179 lines (151 loc) · 7.54 KB
/
StepperExtendedExample3.razor
File metadata and controls
179 lines (151 loc) · 7.54 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
@namespace MudExtensions.Docs.Examples
@inject ISnackbar Snackbar
@inject IDialogService DialogService
<MudGrid Class="cursor-default">
<MudItem xs="12" sm="8" Class="d-flex align-center">
<MudStepperExtended @ref="_stepper"
Class="mud-width-full" ContentStyle="min-height: 400px"
Linear="_linear" Vertical="_vertical"
PreventStepChangeAsync="CheckChange" BeforeFinishedAsync="BeforeFinishedAsync" OnFinished="OnFinished"
Variant="Variant.Filled" Color="Color.Secondary" ContentClass="d-flex align-center justify-center mud-height-full"
MobileView="_mobileView" Loading="_loading" HeaderTextView="HeaderTextView.All" StepperActionsJustify="_stepperActionsJustify">
<ChildContent>
<MudStepExtended Icon="@Icons.Material.Filled.DoneAll" Title="Start Your Reservation" IsIntroStep="true">
<div class="d-flex flex-column align-center justify-center mud-height-full">
<MudIcon Icon="@Icons.Material.Filled.Book" Size="Size.Large" Color="Color.Secondary" />
<MudText Typo="Typo.h6" Class="mt-2">This is your reservation wizard.</MudText>
<MudText Typo="Typo.h6" Class="mt-2">Press start when you are ready.</MudText>
</div>
</MudStepExtended>
<MudStepExtended Icon="@Icons.Material.Filled.Approval" Title="Customer Info" StatusChanged="OnStatusChanged" Order="_infoStepOrder">
<MudForm @ref="_form">
<MudStack>
<MudTextField T="string" Label="Name" Variant="Variant.Filled" Required="true" />
<MudTextField T="string" Label="Last Name" Variant="Variant.Filled" Required="true" />
<MudTextField T="string" Label="Address" Variant="Variant.Filled" />
</MudStack>
</MudForm>
</MudStepExtended>
<MudStepExtended Title="Booking Options" Icon="@Icons.Material.Filled.MoreVert" Optional="true" Order="_optionsStepOrder">
<MudCheckBox T="bool" Label="Early Check-in" />
<MudCheckBox T="bool" Label="Late Check-out" />
<MudCheckBox T="bool" Label="Twin Bed" />
</MudStepExtended>
<MudStepExtended Icon="@Icons.Material.Filled.Money" Title="Payment" Order="_paymentStepOrder">
<MudForm @ref="_form2">
<MudStack>
<MudTextField T="string" Label="Card Number" Variant="Variant.Filled" Required="true" />
<MudStack Row="true">
<MudTextField T="string" Label="Expire Date" Required="true" />
<MudTextField T="string" Label="CVC" Required="true" />
</MudStack>
</MudStack>
</MudForm>
</MudStepExtended>
@if (_hasResultStep)
{
<MudStepExtended Icon="@Icons.Material.Filled.DoneAll" Title="Reservation Completed" IsResultStep="true">
<div class="d-flex flex-column align-center justify-center" style="height: 200px">
<MudIcon Icon="@Icons.Material.Filled.CheckCircle" Size="Size.Large" Color="Color.Secondary" />
<MudText Typo="Typo.h6" Class="mt-2">Your reservation is completed successfully.</MudText>
</div>
</MudStepExtended>
}
</ChildContent>
</MudStepperExtended>
</MudItem>
<MudItem xs="12" sm="4">
<MudStack Spacing="4">
<MudNumericField @bind-Value="_infoStepOrder"
Label="Info Step Order"
@bind-Value:after="@(() => _stepper.ForceRender())"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Immediate="true" />
<MudNumericField @bind-Value="_optionsStepOrder"
Label="Options Step Order"
@bind-Value:after="@(() => _stepper.ForceRender())"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Immediate="true" />
<MudNumericField @bind-Value="_paymentStepOrder"
Label="Payment Step Order"
@bind-Value:after="@(() => _stepper.ForceRender())"
Variant="Variant.Outlined"
Margin="Margin.Dense"
Immediate="true" />
<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>
<MudCheckBox @bind-Value="_vertical" Label="Vertical" />
<MudCheckBox @bind-Value="_linear" Label="Linear" />
<MudSwitchM3 @bind-Value="_mobileView" Label="Mobile View" Color="Color.Secondary" />
<MudSwitchM3 @bind-Value="_hasResultStep" Label="Has Result Step" Color="Color.Secondary" />
<MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="(() => _stepper?.Reset())">
Reset
</MudButton>
</MudStack>
</MudItem>
</MudGrid>
@code {
MudStepperExtended? _stepper;
MudForm _form = new();
MudForm _form2 = new();
bool _linear;
bool _mobileView;
bool _vertical;
bool _loading;
bool _hasResultStep = true;
int _infoStepOrder;
int _optionsStepOrder;
int _paymentStepOrder;
StepperActionsJustify _stepperActionsJustify = StepperActionsJustify.SpaceBetween;
private void OnStatusChanged(StepStatus status)
{
Snackbar.Add($"Customer Info step is now: {status}.", Severity.Info);
}
private async Task<bool> CheckChange(StepChangeDirection direction, int targetIndex)
{
if (direction == StepChangeDirection.Backward)
return false;
if (_stepper?.GetActiveIndex() == 0)
{
_loading = true;
StateHasChanged();
await Task.Delay(500);
await _form.Validate();
_loading = false;
StateHasChanged();
return !_form.IsValid;
}
if (_stepper?.GetActiveIndex() == 2)
{
_loading = true;
StateHasChanged();
await Task.Delay(500);
await _form2.Validate();
_loading = false;
StateHasChanged();
return !_form2.IsValid;
}
return false;
}
private async Task<bool> BeforeFinishedAsync()
{
var result = await DialogService.ShowMessageBoxAsync(
"Confirm",
"All steps are completed. Do you want to finish?",
yesText: "Finish",
cancelText: "Cancel"
);
return result == true;
}
private Task OnFinished()
{
Snackbar.Add("Reservation process finished successfully!", Severity.Success);
return Task.CompletedTask;
}
}