diff --git a/src/Connected.Components/Components/FormWizard.razor.cs b/src/Connected.Components/Components/FormWizard.razor.cs index 84e95fc..f015684 100644 --- a/src/Connected.Components/Components/FormWizard.razor.cs +++ b/src/Connected.Components/Components/FormWizard.razor.cs @@ -1,8 +1,7 @@ using Connected.Enums; using Connected.Utilities; using Microsoft.AspNetCore.Components; -using System.ComponentModel.DataAnnotations; -using System.Text; +using System.Reflection.Metadata; namespace Connected.Components; public partial class FormWizard @@ -16,11 +15,26 @@ public partial class FormWizard [Parameter] public RenderFragment? ChildContent { get; set; } + /// + /// Steps of type FormWizardStep + /// [Parameter] public List Steps { get; set; } = new(); - [Parameter, EditorRequired] - public string Id { get; set; } + /// + /// EventCallback for 'Finish' button click + /// + [Parameter] + public EventCallback OnFinishedClick { get; set; } + + /// + /// EventCallback for 'Cancel' button click + /// + [Parameter] + public EventCallback OnCancelClick { get; set; } + + [Parameter] + public string Id { get; set; } = Guid.NewGuid().ToString(); private string NextBtnText = "Next"; private string PreviousBtnText = "Previous"; @@ -30,10 +44,10 @@ public partial class FormWizard private FinishedState FinishedState { get; set; } = FinishedState.Unfinished; [Parameter] - public int ActiveIndex + public int ActiveIndex { - get - { + get + { return _activeStepIndex; } set @@ -42,7 +56,7 @@ public partial class FormWizard { _activeStepIndex = value; } - } + } } private int _activeStepIndex = 0; @@ -50,7 +64,7 @@ public partial class FormWizard { get { - if (ActiveIndex>0) + if (ActiveIndex > 0) return ActiveIndex - 1; return ActiveIndex; } @@ -62,10 +76,11 @@ public partial class FormWizard { try { - if (ActiveIndex < StepCount-1) + if (ActiveIndex < StepCount - 1) return ActiveIndex + 1; return ActiveIndex; - } catch + } + catch { return ActiveIndex; } @@ -80,38 +95,17 @@ public partial class FormWizard } } - private void NextSlide() + private async Task NextSlide() { if (NextBtnText.ToLower().Equals("finish")) { FinishedState = FinishedState.Finished; Steps[ActiveIndex].Completed = true; WizardFinished = true; + await OnFinishedClick.InvokeAsync(); } if (FinishedState.Equals(FinishedState.Unfinished)) { - /*if (ActiveIndex < StepCount) - { - Steps[ActiveIndex].Completed = true; - ResetValuesForChild(ActiveIndex); - if (ActiveIndex < StepCount) - ResetValuesForChild(NextIndex); - if (ActiveIndex > 0) - ResetValuesForChild(PreviousIndex); - - ActiveIndex = NextIndex; - Steps[ActiveIndex].Active = true; - Steps[PreviousIndex].IsPrevious = true; - if (ActiveIndex != NextIndex) - Steps[NextIndex].IsNext = true; - else Steps[NextIndex].IsNext = false; - - if (ActiveIndex == NextIndex) - NextBtnText = "Finish"; - else - NextBtnText = "Next"; - StateHasChanged(); - }*/ Steps[ActiveIndex].Completed = true; Steps[ActiveIndex].Active = false; Steps[PreviousIndex].IsPrevious = false; @@ -132,7 +126,6 @@ public partial class FormWizard { if (ActiveIndex > 0) { - //Steps[ActiveIndex].Completed = true; Steps[ActiveIndex].Active = false; Steps[PreviousIndex].IsPrevious = false; Steps[ActiveIndex].IsNext = false; @@ -146,13 +139,18 @@ public partial class FormWizard else NextBtnText = "Next"; } - if (ActiveIndex==0) + if (ActiveIndex == 0) { ResetAllChildren(); Steps[ActiveIndex].Active = true; } } + private async Task CancelClick() + { + await OnCancelClick.InvokeAsync(); + } + [Parameter] public string Class { get; set; } = string.Empty; @@ -201,10 +199,10 @@ public partial class FormWizard ResetAllChildren(); Steps[ActiveIndex].Active = true; - if (ActiveIndex!=0) + if (ActiveIndex != 0) { Steps[ActiveIndex].IsNext = true; - Steps[PreviousIndex].IsPrevious= true; + Steps[PreviousIndex].IsPrevious = true; } StateHasChanged(); } @@ -212,7 +210,7 @@ public partial class FormWizard protected override async Task OnParametersSetAsync() { if (Steps is not null) - Steps.Clear(); + Steps.Clear(); await base.OnParametersSetAsync(); }