diff --git a/src/BlazorNodaTimeDateTimePicker.Demo/Pages/Index.cshtml b/src/BlazorNodaTimeDateTimePicker.Demo/Pages/Index.cshtml index 1561692..7b4a438 100644 --- a/src/BlazorNodaTimeDateTimePicker.Demo/Pages/Index.cshtml +++ b/src/BlazorNodaTimeDateTimePicker.Demo/Pages/Index.cshtml @@ -80,23 +80,20 @@ LocalDate? selectedDate1; void changed1(LocalDate? localDate) { - Console.WriteLine("changed1"); selectedDate1 = localDate; StateHasChanged(); } void selected1(LocalDate localDate) - { - Console.WriteLine("selected1"); + { selectedDate1 = localDate; StateHasChanged(); } void cleared1() - { - Console.WriteLine("cleared1"); + { selectedDate1 = null; StateHasChanged(); } diff --git a/src/BlazorNodaTimeDateTimePicker/BlazorNodaTimeDateTimePicker.csproj b/src/BlazorNodaTimeDateTimePicker/BlazorNodaTimeDateTimePicker.csproj index 7e48eb4..7371eb5 100644 --- a/src/BlazorNodaTimeDateTimePicker/BlazorNodaTimeDateTimePicker.csproj +++ b/src/BlazorNodaTimeDateTimePicker/BlazorNodaTimeDateTimePicker.csproj @@ -7,9 +7,10 @@ false 7.3 BlazorNodaTimeDateTimePicker - 0.0.2 + 0.0.3 Nick Heath Blazor NodaTime Date Time Picker + A Date Time Picker for Blazor using NodaTime https://github.com/nheath99/BlazorNodaTimeDateTimePicker blazor;nodatime;datepicker;datepicker;timepicker https://github.com/nheath99/BlazorNodaTimeDateTimePicker diff --git a/src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml b/src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml index 1933e0a..58f0173 100644 --- a/src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml +++ b/src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml @@ -1,7 +1,7 @@ @using NodaTime @using NodaTime.Extensions -
+
@if (State.ViewMode == ViewMode.Days) { @@ -108,10 +108,22 @@
@functions { - protected DatePickerState State { get; set; } = new DatePickerState(); + protected DatePickerState State { get; set; } + [Parameter] protected string Class { get; set; } + [Parameter] protected string Style { get; set; } + [Parameter] protected bool Logging { get; set; } = false; [Parameter] protected System.Globalization.CultureInfo FormatProvider { get; set; } = System.Globalization.CultureInfo.InvariantCulture; [Parameter] protected bool DisplayDaysOfWeek { get; set; } = true; + [Parameter] protected string DayViewHeaderFormat { get; set; } = "MMMM yyyy"; + [Parameter] protected string MonthViewHeaderFormat { get; set; } = "yyyy"; + [Parameter] protected bool Visible { get; set; } = false; + [Parameter] protected bool Inline { get; set; } = false; + [Parameter] protected string MaxWidth { get; set; } + [Parameter] protected string Width { get; set; } + [Parameter] protected bool ShowToday { get; set; } = true; + [Parameter] protected bool ShowClear { get; set; } = true; + [Parameter] protected IsoDayOfWeek FirstDayOfWeek { get => State.FirstDayOfWeek; @@ -154,15 +166,6 @@ set => State.DisabledDateIntervals = value; } - [Parameter] protected string DayViewHeaderFormat { get; set; } = "MMMM yyyy"; - [Parameter] protected string MonthViewHeaderFormat { get; set; } = "yyyy"; - [Parameter] protected bool Visible { get; set; } = false; - [Parameter] protected bool Inline { get; set; } = false; - [Parameter] protected string MaxWidth { get; set; } - [Parameter] protected string Width { get; set; } - [Parameter] protected bool ShowToday { get; set; } = true; - [Parameter] protected bool ShowClear { get; set; } = true; - // Events in use [Parameter] protected Action Changed { get; set; } [Parameter] protected Action Selected { get; set; } @@ -185,7 +188,12 @@ protected override void OnInit() { - Console.WriteLine(nameof(OnInit)); + State = new DatePickerState() + { + WriteToLog = Logging + }; + + State.Log(nameof(OnInit)); State.OnStateChanged += StateHasChanged; @@ -201,28 +209,28 @@ protected override void OnParametersSet() { - Console.WriteLine(nameof(OnParametersSet)); + State.Log(nameof(OnParametersSet)); RenderDays(); } private void OnChanged(LocalDate? localDate) { - Console.WriteLine(nameof(OnChanged)); + State.Log(nameof(OnChanged)); Changed?.Invoke(localDate); } private void OnSelected(LocalDate localDate) { - Console.WriteLine(nameof(OnSelected)); + State.Log(nameof(OnSelected)); Selected?.Invoke(localDate); } private void OnCleared() { - Console.WriteLine(nameof(OnCleared)); + State.Log(nameof(OnCleared)); Cleared?.Invoke(); } @@ -231,7 +239,7 @@ void RenderDays() { - Console.WriteLine(nameof(RenderDays)); + State.Log(nameof(RenderDays)); var startOfWeekOfMonth = State.MonthToDisplay.StartOfWeek(FirstDayOfWeek); @@ -243,7 +251,7 @@ void DayClicked(LocalDate date) { - Console.WriteLine(nameof(DayClicked)); + State.Log(nameof(DayClicked)); if (!State.IsDayDisabled(date)) State.SetSelectedDate(date); @@ -263,6 +271,17 @@ } while (start <= end); } + private string ClassName + { + get + { + if (!string.IsNullOrEmpty(Class)) + return $"{CssClassGenerator.Main(Inline)} {Class}"; + else + return CssClassGenerator.Main(Inline); + } + } + protected string MainStyle { get @@ -276,6 +295,8 @@ if (!string.IsNullOrEmpty(MaxWidth)) str.Add($"max-width:{MaxWidth};"); + str.Add(Style); + return string.Join(" ", str); } } @@ -310,7 +331,7 @@ void RenderMonths() { - Console.WriteLine(nameof(RenderMonths)); + State.Log(nameof(RenderMonths)); disabledMonths = new bool[12]; @@ -322,7 +343,7 @@ void MonthClicked(int month) { - Console.WriteLine(nameof(MonthClicked)); + State.Log(nameof(MonthClicked)); if (disabledMonths[month - 1] == false) { @@ -333,7 +354,7 @@ void NextMonth() { - Console.WriteLine(nameof(NextMonth)); + State.Log(nameof(NextMonth)); State.NextMonth(); RenderDays(); @@ -342,7 +363,7 @@ void PreviousMonth() { - Console.WriteLine(nameof(PreviousMonth)); + State.Log(nameof(PreviousMonth)); State.PreviousMonth(); RenderDays(); @@ -351,7 +372,7 @@ void SelectMonth() { - Console.WriteLine(nameof(SelectMonth)); + State.Log(nameof(SelectMonth)); RenderMonths(); State.NextViewMode(); @@ -366,7 +387,7 @@ void RenderYears() { - Console.WriteLine(nameof(RenderYears)); + State.Log(nameof(RenderYears)); (yearStart, yearEnd) = State.MonthToDisplay.GetDecade(); @@ -380,7 +401,7 @@ void YearClicked(int year) { - Console.WriteLine(nameof(YearClicked)); + State.Log(nameof(YearClicked)); if (disabledYears[year] == false) { @@ -392,7 +413,7 @@ void NextYear() { - Console.WriteLine(nameof(NextYear)); + State.Log(nameof(NextYear)); State.NextYear(); OnUpdated(); @@ -400,7 +421,7 @@ void PreviousYear() { - Console.WriteLine(nameof(PreviousYear)); + State.Log(nameof(PreviousYear)); State.PreviousYear(); OnUpdated(); @@ -408,7 +429,7 @@ void SelectYear() { - Console.WriteLine(nameof(SelectYear)); + State.Log(nameof(SelectYear)); RenderYears(); State.NextViewMode(); @@ -423,7 +444,7 @@ void RenderDecades() { - Console.WriteLine(nameof(RenderDecades)); + State.Log(nameof(RenderDecades)); (decadeStart, decadeEnd) = State.MonthToDisplay.GetCentury(); @@ -437,7 +458,7 @@ void DecadeClicked(int decade) { - Console.WriteLine(nameof(DecadeClicked)); + State.Log(nameof(DecadeClicked)); if (disabledDecades[decade] == false) { @@ -449,7 +470,7 @@ void NextDecade() { - Console.WriteLine(nameof(NextDecade)); + State.Log(nameof(NextDecade)); State.NextDecade(); OnUpdated(); @@ -457,7 +478,7 @@ void PreviousDecade() { - Console.WriteLine(nameof(PreviousDecade)); + State.Log(nameof(PreviousDecade)); State.PreviousDecade(); OnUpdated(); @@ -465,7 +486,7 @@ void SelectDecade() { - Console.WriteLine(nameof(SelectDecade)); + State.Log(nameof(SelectDecade)); RenderDecades(); State.NextViewMode(); @@ -477,7 +498,7 @@ void NextCentury() { - Console.WriteLine(nameof(NextCentury)); + State.Log(nameof(NextCentury)); State.NextCentury(); OnUpdated(); @@ -485,7 +506,7 @@ void PreviousCentury() { - Console.WriteLine(nameof(PreviousCentury)); + State.Log(nameof(PreviousCentury)); State.PreviousCentury(); OnUpdated(); @@ -495,21 +516,21 @@ void TodayClicked() { - Console.WriteLine(nameof(TodayClicked)); + State.Log(nameof(TodayClicked)); State.SetSelectedDateToday(); } void ClearClicked() { - Console.WriteLine(nameof(ClearClicked)); + State.Log(nameof(ClearClicked)); State.ClearSelectedDate(); } void OnUpdated() { - Console.WriteLine(nameof(OnUpdated)); + State.Log(nameof(OnUpdated)); Updated?.Invoke(); } diff --git a/src/BlazorNodaTimeDateTimePicker/DatePickerState.cs b/src/BlazorNodaTimeDateTimePicker/DatePickerState.cs index 4539566..caef138 100644 --- a/src/BlazorNodaTimeDateTimePicker/DatePickerState.cs +++ b/src/BlazorNodaTimeDateTimePicker/DatePickerState.cs @@ -10,7 +10,7 @@ public class DatePickerState public DatePickerState() { Today = SystemClock.Instance.Today(); - MonthToDisplay = Today.StartOfMonth(); + MonthToDisplay = Today.StartOfMonth(); } public LocalDate Today { get; } @@ -27,7 +27,8 @@ public DatePickerState() internal IEnumerable DaysOfWeekDisabled { get; set; } internal IEnumerable<(LocalDate start, LocalDate end)> DisabledDateIntervals { get; set; } internal Func DaysEnabledFunction { get; set; } - + internal bool WriteToLog { get; set; } + internal event Action OnSelected; // when a date is selected internal event Action OnCleared; // when the date is set to null internal event Action OnSelectedDateChanged; // when the selected date is changed @@ -43,6 +44,12 @@ public DatePickerState() internal event Action OnYearToDisplayChanged; internal event Action OnDecadeToDisplayChanged; internal event Action OnCenturyToDisplayChanged; + + internal void Log(string data) + { + if (WriteToLog) + Log(data); + } void SelectedDateChanged() { @@ -78,7 +85,7 @@ internal int? SelectedDecade internal void SetSelectedDate(LocalDate selectedDate) { - Console.WriteLine(nameof(SetSelectedDate)); + Log(nameof(SetSelectedDate)); if (SelectedDate != selectedDate) { @@ -94,14 +101,14 @@ internal void SetSelectedDate(LocalDate selectedDate) internal void SetSelectedDateToday() { - Console.WriteLine(nameof(SetSelectedDateToday)); + Log(nameof(SetSelectedDateToday)); SetSelectedDate(Today); } internal void ClearSelectedDate() { - Console.WriteLine(nameof(ClearSelectedDate)); + Log(nameof(ClearSelectedDate)); SelectedDate = null; @@ -111,21 +118,21 @@ internal void ClearSelectedDate() internal void SetDisplayMonth(int month) { - Console.WriteLine(nameof(SetDisplayMonth)); + Log(nameof(SetDisplayMonth)); MonthToDisplay = new LocalDate(MonthToDisplay.Year, month, 1); } internal void SetDisplayYear(int year) { - Console.WriteLine(nameof(SetDisplayYear)); + Log(nameof(SetDisplayYear)); MonthToDisplay = new LocalDate(year, MonthToDisplay.Month, 1); } internal void SetViewMode(ViewMode viewMode) { - Console.WriteLine(nameof(SetViewMode)); + Log(nameof(SetViewMode)); ViewMode = viewMode; MonthToDisplayChanged(); @@ -134,7 +141,7 @@ internal void SetViewMode(ViewMode viewMode) internal void NextViewMode() { - Console.WriteLine(nameof(NextViewMode)); + Log(nameof(NextViewMode)); switch (ViewMode) { @@ -155,7 +162,7 @@ internal void NextViewMode() internal void PreviousViewMode() { - Console.WriteLine(nameof(PreviousViewMode)); + Log(nameof(PreviousViewMode)); switch (ViewMode) { @@ -176,7 +183,7 @@ internal void PreviousViewMode() internal void NextMonth() { - Console.WriteLine(nameof(NextMonth)); + Log(nameof(NextMonth)); MonthToDisplay = MonthToDisplay.PlusMonths(1); MonthToDisplayChanged(); @@ -184,7 +191,7 @@ internal void NextMonth() internal void PreviousMonth() { - Console.WriteLine(nameof(PreviousMonth)); + Log(nameof(PreviousMonth)); MonthToDisplay = MonthToDisplay.PlusMonths(-1); MonthToDisplayChanged(); @@ -192,7 +199,7 @@ internal void PreviousMonth() internal void NextYear() { - Console.WriteLine(nameof(NextYear)); + Log(nameof(NextYear)); MonthToDisplay = MonthToDisplay.PlusYears(1); YearToDisplayChanged(); @@ -200,7 +207,7 @@ internal void NextYear() internal void PreviousYear() { - Console.WriteLine(nameof(PreviousYear)); + Log(nameof(PreviousYear)); MonthToDisplay = MonthToDisplay.PlusYears(-1); YearToDisplayChanged(); @@ -208,7 +215,7 @@ internal void PreviousYear() internal void NextDecade() { - Console.WriteLine(nameof(NextDecade)); + Log(nameof(NextDecade)); MonthToDisplay = MonthToDisplay.PlusYears(10); DecadeToDisplayChanged(); @@ -217,7 +224,7 @@ internal void NextDecade() internal void PreviousDecade() { - Console.WriteLine(nameof(PreviousDecade)); + Log(nameof(PreviousDecade)); MonthToDisplay = MonthToDisplay.PlusYears(-10); DecadeToDisplayChanged(); @@ -226,7 +233,7 @@ internal void PreviousDecade() internal void NextCentury() { - Console.WriteLine(nameof(NextCentury)); + Log(nameof(NextCentury)); MonthToDisplay = MonthToDisplay.PlusYears(100); CentureToDisplayChanged(); @@ -235,7 +242,7 @@ internal void NextCentury() internal void PreviousCentury() { - Console.WriteLine(nameof(PreviousCentury)); + Log(nameof(PreviousCentury)); MonthToDisplay = MonthToDisplay.PlusYears(-100); CentureToDisplayChanged();