Skip to content

Commit

Permalink
Fixed #8
Browse files Browse the repository at this point in the history
  • Loading branch information
nheath99 committed Oct 5, 2018
1 parent 76df1fb commit 21bc7ed
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 62 deletions.
7 changes: 2 additions & 5 deletions src/BlazorNodaTimeDateTimePicker.Demo/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<LangVersion>7.3</LangVersion>
<PackageId>BlazorNodaTimeDateTimePicker</PackageId>
<Version>0.0.2</Version>
<Version>0.0.3</Version>
<Authors>Nick Heath</Authors>
<Title>Blazor NodaTime Date Time Picker</Title>
<Description>A Date Time Picker for Blazor using NodaTime</Description>
<PackageProjectUrl>https://github.com/nheath99/BlazorNodaTimeDateTimePicker</PackageProjectUrl>
<PackageTags>blazor;nodatime;datepicker;datepicker;timepicker</PackageTags>
<RepositoryUrl>https://github.com/nheath99/BlazorNodaTimeDateTimePicker</RepositoryUrl>
Expand Down
97 changes: 59 additions & 38 deletions src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using NodaTime
@using NodaTime.Extensions

<div class="@CssClassGenerator.Main(Inline)" style="@MainStyle">
<div class="@ClassName" style="@MainStyle">
<div class="datepicker-content">
@if (State.ViewMode == ViewMode.Days)
{
Expand Down Expand Up @@ -108,10 +108,22 @@
</div>

@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;
Expand Down Expand Up @@ -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<LocalDate?> Changed { get; set; }
[Parameter] protected Action<LocalDate> Selected { get; set; }
Expand All @@ -185,7 +188,12 @@

protected override void OnInit()
{
Console.WriteLine(nameof(OnInit));
State = new DatePickerState()
{
WriteToLog = Logging
};

State.Log(nameof(OnInit));

State.OnStateChanged += StateHasChanged;

Expand All @@ -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();
}
Expand All @@ -231,7 +239,7 @@

void RenderDays()
{
Console.WriteLine(nameof(RenderDays));
State.Log(nameof(RenderDays));

var startOfWeekOfMonth = State.MonthToDisplay.StartOfWeek(FirstDayOfWeek);

Expand All @@ -243,7 +251,7 @@

void DayClicked(LocalDate date)
{
Console.WriteLine(nameof(DayClicked));
State.Log(nameof(DayClicked));

if (!State.IsDayDisabled(date))
State.SetSelectedDate(date);
Expand All @@ -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
Expand All @@ -276,6 +295,8 @@
if (!string.IsNullOrEmpty(MaxWidth))
str.Add($"max-width:{MaxWidth};");

str.Add(Style);

return string.Join(" ", str);
}
}
Expand Down Expand Up @@ -310,7 +331,7 @@

void RenderMonths()
{
Console.WriteLine(nameof(RenderMonths));
State.Log(nameof(RenderMonths));

disabledMonths = new bool[12];

Expand All @@ -322,7 +343,7 @@

void MonthClicked(int month)
{
Console.WriteLine(nameof(MonthClicked));
State.Log(nameof(MonthClicked));

if (disabledMonths[month - 1] == false)
{
Expand All @@ -333,7 +354,7 @@

void NextMonth()
{
Console.WriteLine(nameof(NextMonth));
State.Log(nameof(NextMonth));

State.NextMonth();
RenderDays();
Expand All @@ -342,7 +363,7 @@

void PreviousMonth()
{
Console.WriteLine(nameof(PreviousMonth));
State.Log(nameof(PreviousMonth));

State.PreviousMonth();
RenderDays();
Expand All @@ -351,7 +372,7 @@

void SelectMonth()
{
Console.WriteLine(nameof(SelectMonth));
State.Log(nameof(SelectMonth));

RenderMonths();
State.NextViewMode();
Expand All @@ -366,7 +387,7 @@

void RenderYears()
{
Console.WriteLine(nameof(RenderYears));
State.Log(nameof(RenderYears));

(yearStart, yearEnd) = State.MonthToDisplay.GetDecade();

Expand All @@ -380,7 +401,7 @@

void YearClicked(int year)
{
Console.WriteLine(nameof(YearClicked));
State.Log(nameof(YearClicked));

if (disabledYears[year] == false)
{
Expand All @@ -392,23 +413,23 @@

void NextYear()
{
Console.WriteLine(nameof(NextYear));
State.Log(nameof(NextYear));

State.NextYear();
OnUpdated();
}

void PreviousYear()
{
Console.WriteLine(nameof(PreviousYear));
State.Log(nameof(PreviousYear));

State.PreviousYear();
OnUpdated();
}

void SelectYear()
{
Console.WriteLine(nameof(SelectYear));
State.Log(nameof(SelectYear));

RenderYears();
State.NextViewMode();
Expand All @@ -423,7 +444,7 @@

void RenderDecades()
{
Console.WriteLine(nameof(RenderDecades));
State.Log(nameof(RenderDecades));

(decadeStart, decadeEnd) = State.MonthToDisplay.GetCentury();

Expand All @@ -437,7 +458,7 @@

void DecadeClicked(int decade)
{
Console.WriteLine(nameof(DecadeClicked));
State.Log(nameof(DecadeClicked));

if (disabledDecades[decade] == false)
{
Expand All @@ -449,23 +470,23 @@

void NextDecade()
{
Console.WriteLine(nameof(NextDecade));
State.Log(nameof(NextDecade));

State.NextDecade();
OnUpdated();
}

void PreviousDecade()
{
Console.WriteLine(nameof(PreviousDecade));
State.Log(nameof(PreviousDecade));

State.PreviousDecade();
OnUpdated();
}

void SelectDecade()
{
Console.WriteLine(nameof(SelectDecade));
State.Log(nameof(SelectDecade));

RenderDecades();
State.NextViewMode();
Expand All @@ -477,15 +498,15 @@

void NextCentury()
{
Console.WriteLine(nameof(NextCentury));
State.Log(nameof(NextCentury));

State.NextCentury();
OnUpdated();
}

void PreviousCentury()
{
Console.WriteLine(nameof(PreviousCentury));
State.Log(nameof(PreviousCentury));

State.PreviousCentury();
OnUpdated();
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit 21bc7ed

Please sign in to comment.