From b67973cb68a6c129ede0bc32eb4d3b9b20a53934 Mon Sep 17 00:00:00 2001 From: markosteger Date: Fri, 10 Mar 2023 10:08:47 +0100 Subject: [PATCH] FormWizard, FormWizardStep - fixed not showing steps in certain conditions, DatePicker - code cleanup, showing selected month and year --- .../Components/DatePicker.razor.cs | 37 +++---------------- .../Components/FormWizard.razor.cs | 7 ++-- .../Components/FormWizardStep.razor.cs | 18 +++++++-- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/Connected.Components/Components/DatePicker.razor.cs b/src/Connected.Components/Components/DatePicker.razor.cs index f77984b..6be2192 100644 --- a/src/Connected.Components/Components/DatePicker.razor.cs +++ b/src/Connected.Components/Components/DatePicker.razor.cs @@ -1,5 +1,4 @@ -using Connected.Utilities; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; namespace Connected.Components; public partial class DatePicker @@ -131,17 +130,17 @@ public partial class DatePicker public string MonthChipClass(int month) { if (month.CompareTo(SelectedDate.Month) == 0) - return "bg-info text-white"; + return "active"; else - return "bg-core text-light"; + return ""; } public string YearChipClass(int year) { if (year.CompareTo(SelectedDate.Year) == 0) - return "bg-info text-white"; + return "active"; else - return "bg-core text-light"; + return ""; } protected override async Task OnInitializedAsync() @@ -153,32 +152,6 @@ public partial class DatePicker await base.OnInitializedAsync(); } - private string NavBarClass - { - get - { - return new CssBuilder("text-justify") - .AddClass("text-md-justify") - //.AddClass("bg-warning") - .AddClass("p-2") - .AddClass("text-small") - .AddClass("text-dark") - .Build(); - } - } - - private string NavBarStyle - { - get - { - return new StyleBuilder("display","flex") - .AddStyle("flex-direction","row") - .AddStyle("flex-wrap","nowrap") - .AddStyle("justify-content","space-between") - .Build(); - } - } - private async Task ClosePicker(bool resetDate=true) { if (resetDate) diff --git a/src/Connected.Components/Components/FormWizard.razor.cs b/src/Connected.Components/Components/FormWizard.razor.cs index f015684..ba28428 100644 --- a/src/Connected.Components/Components/FormWizard.razor.cs +++ b/src/Connected.Components/Components/FormWizard.razor.cs @@ -207,13 +207,14 @@ public partial class FormWizard StateHasChanged(); } - protected override async Task OnParametersSetAsync() + /*protected override async Task OnParametersSetAsync() { - if (Steps is not null) + if (Steps is null) Steps = new(); Steps.Clear(); + InitializeSteps(); await base.OnParametersSetAsync(); - } + }*/ protected override async Task OnAfterRenderAsync(bool firstRender) { diff --git a/src/Connected.Components/Components/FormWizardStep.razor.cs b/src/Connected.Components/Components/FormWizardStep.razor.cs index fbaa5b9..f3defdd 100644 --- a/src/Connected.Components/Components/FormWizardStep.razor.cs +++ b/src/Connected.Components/Components/FormWizardStep.razor.cs @@ -9,8 +9,11 @@ public partial class FormWizardStep [CascadingParameter] public FormWizard Parent { get; set; } - [Parameter, EditorRequired] - public string Name { get; set; } + /// + /// Unique name of the step (used for properly identifying steps) + /// + [Parameter] + public string? Id { get; set; } = Guid.NewGuid().ToString(); /// /// Text shown inside the button @@ -88,10 +91,17 @@ public partial class FormWizardStep #region Lifecycle + private bool ItemExists() + { + if (Parent.Steps.Where(step => step.Id.Equals(this.Id)).Count() > 0) return true; + return false; + } + - protected override async Task OnInitializedAsync() + protected override async Task OnParametersSetAsync() { - Parent.Steps.Add(this); + if (!ItemExists()) + Parent.Steps.Add(this); await base.OnInitializedAsync(); }