|
| 1 | +@namespace MudExtensions.Docs.Examples |
| 2 | +@inject ISnackbar Snackbar |
| 3 | +@inject IDialogService DialogService |
| 4 | + |
| 5 | +<MudGrid Class="cursor-default"> |
| 6 | + <MudItem xs="12" sm="8" Class="d-flex align-center"> |
| 7 | + |
| 8 | + <MudStepperExtended @ref="_stepper" |
| 9 | + Class="mud-width-full" ContentStyle="min-height: 400px" |
| 10 | + Linear="_linear" Vertical="_vertical" |
| 11 | + PreventStepChangeAsync="CheckChange" BeforeFinishedAsync="BeforeFinishedAsync" OnFinished="OnFinished" |
| 12 | + Variant="Variant.Filled" Color="Color.Secondary" ContentClass="d-flex align-center justify-center mud-height-full" |
| 13 | + MobileView="_mobileView" Loading="_loading" HeaderTextView="HeaderTextView.All" StepperActionsJustify="_stepperActionsJustify"> |
| 14 | + |
| 15 | + <ChildContent> |
| 16 | + <MudStepExtended Icon="@Icons.Material.Filled.DoneAll" Title="Start Your Reservation" IsIntroStep="true"> |
| 17 | + <div class="d-flex flex-column align-center justify-center mud-height-full"> |
| 18 | + <MudIcon Icon="@Icons.Material.Filled.Book" Size="Size.Large" Color="Color.Secondary" /> |
| 19 | + <MudText Typo="Typo.h6" Class="mt-2">This is your reservation wizard.</MudText> |
| 20 | + <MudText Typo="Typo.h6" Class="mt-2">Press start when you are ready.</MudText> |
| 21 | + </div> |
| 22 | + </MudStepExtended> |
| 23 | + |
| 24 | + <MudStepExtended Icon="@Icons.Material.Filled.Approval" Title="Customer Info" StatusChanged="OnStatusChanged" Order="_infoStepOrder"> |
| 25 | + <MudForm @ref="_form"> |
| 26 | + <MudStack> |
| 27 | + <MudTextField T="string" Label="Name" Variant="Variant.Filled" Required="true" /> |
| 28 | + <MudTextField T="string" Label="Last Name" Variant="Variant.Filled" Required="true" /> |
| 29 | + <MudTextField T="string" Label="Address" Variant="Variant.Filled" /> |
| 30 | + </MudStack> |
| 31 | + </MudForm> |
| 32 | + </MudStepExtended> |
| 33 | + |
| 34 | + <MudStepExtended Title="Booking Options" Icon="@Icons.Material.Filled.MoreVert" Optional="true" Order="_optionsStepOrder"> |
| 35 | + <MudCheckBox T="bool" Label="Early Check-in" /> |
| 36 | + <MudCheckBox T="bool" Label="Late Check-out" /> |
| 37 | + <MudCheckBox T="bool" Label="Twin Bed" /> |
| 38 | + </MudStepExtended> |
| 39 | + |
| 40 | + <MudStepExtended Icon="@Icons.Material.Filled.Money" Title="Payment" Order="_paymentStepOrder"> |
| 41 | + <MudForm @ref="_form2"> |
| 42 | + <MudStack> |
| 43 | + <MudTextField T="string" Label="Card Number" Variant="Variant.Filled" Required="true" /> |
| 44 | + <MudStack Row="true"> |
| 45 | + <MudTextField T="string" Label="Expire Date" Required="true" /> |
| 46 | + <MudTextField T="string" Label="CVC" Required="true" /> |
| 47 | + </MudStack> |
| 48 | + </MudStack> |
| 49 | + </MudForm> |
| 50 | + </MudStepExtended> |
| 51 | + |
| 52 | + @if (_hasResultStep) |
| 53 | + { |
| 54 | + <MudStepExtended Icon="@Icons.Material.Filled.DoneAll" Title="Reservation Completed" IsResultStep="true"> |
| 55 | + <div class="d-flex flex-column align-center justify-center" style="height: 200px"> |
| 56 | + <MudIcon Icon="@Icons.Material.Filled.CheckCircle" Size="Size.Large" Color="Color.Secondary" /> |
| 57 | + <MudText Typo="Typo.h6" Class="mt-2">Your reservation is completed successfully.</MudText> |
| 58 | + </div> |
| 59 | + </MudStepExtended> |
| 60 | + } |
| 61 | + |
| 62 | + </ChildContent> |
| 63 | + |
| 64 | + </MudStepperExtended> |
| 65 | + |
| 66 | + </MudItem> |
| 67 | + |
| 68 | + <MudItem xs="12" sm="4"> |
| 69 | + <MudStack Spacing="4"> |
| 70 | + <MudNumericField @bind-Value="_infoStepOrder" |
| 71 | + Label="Info Step Order" |
| 72 | + @bind-Value:after="@(() => _stepper.ForceRender())" |
| 73 | + Variant="Variant.Outlined" |
| 74 | + Margin="Margin.Dense" |
| 75 | + Immediate="true" /> |
| 76 | + |
| 77 | + <MudNumericField @bind-Value="_optionsStepOrder" |
| 78 | + Label="Options Step Order" |
| 79 | + @bind-Value:after="@(() => _stepper.ForceRender())" |
| 80 | + Variant="Variant.Outlined" |
| 81 | + Margin="Margin.Dense" |
| 82 | + Immediate="true" /> |
| 83 | + |
| 84 | + <MudNumericField @bind-Value="_paymentStepOrder" |
| 85 | + Label="Payment Step Order" |
| 86 | + @bind-Value:after="@(() => _stepper.ForceRender())" |
| 87 | + Variant="Variant.Outlined" |
| 88 | + Margin="Margin.Dense" |
| 89 | + Immediate="true" /> |
| 90 | + <MudSelect @bind-Value="_stepperActionsJustify" Variant="Variant.Outlined" Label="Action Buttons Justify" Margin="Margin.Dense" Dense="true"> |
| 91 | + @foreach (StepperActionsJustify item in Enum.GetValues<StepperActionsJustify>()) |
| 92 | + { |
| 93 | + <MudSelectItem Value="item">@item.ToDescriptionString()</MudSelectItem> |
| 94 | + } |
| 95 | + </MudSelect> |
| 96 | + <MudCheckBox @bind-Value="_vertical" Label="Vertical" /> |
| 97 | + <MudCheckBox @bind-Value="_linear" Label="Linear" /> |
| 98 | + <MudSwitchM3 @bind-Value="_mobileView" Label="Mobile View" Color="Color.Secondary" /> |
| 99 | + <MudSwitchM3 @bind-Value="_hasResultStep" Label="Has Result Step" Color="Color.Secondary" /> |
| 100 | + |
| 101 | + <MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="(() => _stepper?.Reset())"> |
| 102 | + Reset |
| 103 | + </MudButton> |
| 104 | + </MudStack> |
| 105 | + </MudItem> |
| 106 | + |
| 107 | +</MudGrid> |
| 108 | + |
| 109 | +@code { |
| 110 | + MudStepperExtended? _stepper; |
| 111 | + MudForm _form = new(); |
| 112 | + MudForm _form2 = new(); |
| 113 | + bool _linear; |
| 114 | + bool _mobileView; |
| 115 | + bool _vertical; |
| 116 | + bool _loading; |
| 117 | + bool _hasResultStep = true; |
| 118 | + int _infoStepOrder; |
| 119 | + int _optionsStepOrder; |
| 120 | + int _paymentStepOrder; |
| 121 | + StepperActionsJustify _stepperActionsJustify = StepperActionsJustify.SpaceBetween; |
| 122 | + |
| 123 | + private void OnStatusChanged(StepStatus status) |
| 124 | + { |
| 125 | + Snackbar.Add($"Customer Info step is now: {status}.", Severity.Info); |
| 126 | + } |
| 127 | + |
| 128 | + private async Task<bool> CheckChange(StepChangeDirection direction, int targetIndex) |
| 129 | + { |
| 130 | + if (direction == StepChangeDirection.Backward) |
| 131 | + return false; |
| 132 | + |
| 133 | + if (_stepper?.GetActiveIndex() == 0) |
| 134 | + { |
| 135 | + _loading = true; |
| 136 | + StateHasChanged(); |
| 137 | + await Task.Delay(500); |
| 138 | + |
| 139 | + await _form.Validate(); |
| 140 | + _loading = false; |
| 141 | + StateHasChanged(); |
| 142 | + |
| 143 | + return !_form.IsValid; |
| 144 | + } |
| 145 | + |
| 146 | + if (_stepper?.GetActiveIndex() == 2) |
| 147 | + { |
| 148 | + _loading = true; |
| 149 | + StateHasChanged(); |
| 150 | + await Task.Delay(500); |
| 151 | + |
| 152 | + await _form2.Validate(); |
| 153 | + _loading = false; |
| 154 | + StateHasChanged(); |
| 155 | + |
| 156 | + return !_form2.IsValid; |
| 157 | + } |
| 158 | + |
| 159 | + return false; |
| 160 | + } |
| 161 | + |
| 162 | + private async Task<bool> BeforeFinishedAsync() |
| 163 | + { |
| 164 | + var result = await DialogService.ShowMessageBox( |
| 165 | + "Confirm", |
| 166 | + "All steps are completed. Do you want to finish?", |
| 167 | + yesText: "Finish", |
| 168 | + cancelText: "Cancel" |
| 169 | + ); |
| 170 | + |
| 171 | + return result == true; |
| 172 | + } |
| 173 | + |
| 174 | + private Task OnFinished() |
| 175 | + { |
| 176 | + Snackbar.Add("Reservation process finished successfully!", Severity.Success); |
| 177 | + return Task.CompletedTask; |
| 178 | + } |
| 179 | +} |
0 commit comments