From fa33cc518924b0be191120af30548de0c29a55be Mon Sep 17 00:00:00 2001 From: markosteger Date: Tue, 7 Mar 2023 12:27:46 +0100 Subject: [PATCH] DatePicker - minor fixes, added methods for back ind forward click in header (selecting year, month..) --- .../Components/DatePicker.razor | 56 +++++++++++++------ .../Components/DatePicker.razor.cs | 53 ++++++++++++++++-- 2 files changed, 87 insertions(+), 22 deletions(-) diff --git a/src/Connected.Components/Components/DatePicker.razor b/src/Connected.Components/Components/DatePicker.razor index e369771..f59ddc5 100644 --- a/src/Connected.Components/Components/DatePicker.razor +++ b/src/Connected.Components/Components/DatePicker.razor @@ -21,16 +21,21 @@ { case Selecting.Years: { -
-
-
Selecting = Selecting.Months)>@SelectedDate.ToString("yyyy")
-
+
+
+
+
+
Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM yyyy")
+ +
+
+
@for (int i = SelectedDate.Year - 7; i < SelectedDate.Year + 8; i++) { int y = i; -
+
@i.ToString()
@@ -46,15 +51,22 @@ } case Selecting.Months: { -
-
+
+
+
+
+
Selecting = Selecting.Years)>@SelectedDate.ToString("MMMM yyyy")
-
+ + +
+
+
@for (int i = 1; i <= @DateTimeFormatInfo.CurrentInfo.MonthNames.Length - 1; i++) { int m = i; -
+
@@ -72,10 +84,17 @@ } case (Selecting.Days): { -
-
+
+
+
+
+
Selecting = Selecting.Months)>@SelectedDate.ToString("MMMM yyyy")
-
+ + +
+
+
@for (int i = 0; i < 7; i++) @@ -93,16 +112,19 @@ {
} - CalendarStart = CalendarStart.AddDays(1); } break; } } -
- -
- + @if (ShowBottomBar) + { + +
+ + +
+ }
}
diff --git a/src/Connected.Components/Components/DatePicker.razor.cs b/src/Connected.Components/Components/DatePicker.razor.cs index 676bedd..0aebe9f 100644 --- a/src/Connected.Components/Components/DatePicker.razor.cs +++ b/src/Connected.Components/Components/DatePicker.razor.cs @@ -32,6 +32,9 @@ public partial class DatePicker [Parameter] public bool UseDateRange { get; set; } = false; + [Parameter] + public bool ShowBottomBar { get; set; } = false; + [Parameter] public string Format { get; set; } = "dd.MM.yyyy"; @@ -50,13 +53,14 @@ public partial class DatePicker } private bool Shown { get; set; } = false; - public async Task SetDate(DateTime Date) + public async Task SetDate(DateTime Date, bool HideOnSet=false) { SelectedDate = Date; SetStartStop(); if (CloseOnDateSelect) Shown = false; await SelectedDateChanged.InvokeAsync(SelectedDate); + if (HideOnSet) Shown = false; StateHasChanged(); } @@ -168,17 +172,17 @@ public partial class DatePicker public string MonthChipClass(int month) { if (month.CompareTo(SelectedDate.Month) == 0) - return "bg-info text-light"; + return "bg-info text-white"; else - return "bg-core text-dark"; + return "bg-core text-light"; } public string YearChipClass(int year) { if (year.CompareTo(SelectedDate.Year) == 0) - return "bg-info text-light"; + return "bg-info text-white"; else - return "bg-core text-dark"; + return "bg-core text-light"; } protected override async Task OnInitializedAsync() @@ -196,12 +200,51 @@ public partial class DatePicker 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 NavBarClick(bool forward = true) + { + int multiplier = 1; + if (!forward) multiplier = -1; + switch (Selecting) + { + case Selecting.Years: + { + SelectedDate=SelectedDate.AddYears(8 * multiplier); + break; + } + case Selecting.Months: + { + SelectedDate = SelectedDate.AddYears(1 * multiplier); + break; + } + case Selecting.Days: + { + SelectedDate = SelectedDate.AddMonths(1*multiplier); + break; + } + } + SetStartStop(); + await InvokeAsync(StateHasChanged); + } + } public enum Selecting