Skip to content

Commit

Permalink
Fixed #14
Browse files Browse the repository at this point in the history
  • Loading branch information
nheath99 committed Oct 6, 2018
1 parent e706668 commit 5022521
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/BlazorNodaTimeDateTimePicker/CssClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ internal static string Main(bool inline)

internal static string Day(LocalDate Date, DatePickerState State)
{
bool Disabled = State.IsDayDisabled(Date);
bool IsToday = Date == State.Today;
bool IsOld = Date.Month < State.MonthToDisplay.Month;
bool IsNew = Date.Month > State.MonthToDisplay.Month;
bool disabled = State.IsDayDisabled(Date);
bool isToday = Date == State.Today;
bool isOld = Date.Month < State.MonthToDisplay.Month;
bool isNew = Date.Month > State.MonthToDisplay.Month;

var sb = new List<string>
{
"day",
Date.DayOfWeek.IsWeekday() ? "weekday" : "weekend"
};

if (IsOld)
if (isOld)
sb.Add("old");
if (IsNew)
if (isNew)
sb.Add("new");
if (IsToday)
if (isToday)
sb.Add("today");
if (State.SelectedDate == Date)
sb.Add("active");
if (Disabled)
if (disabled)
sb.Add("disabled");

return string.Join(" ", sb);
Expand Down
14 changes: 11 additions & 3 deletions src/BlazorNodaTimeDateTimePicker/DatePicker.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
[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; } = "250px;";
[Parameter] protected bool ShowToday { get; set; } = true;
Expand All @@ -132,6 +130,16 @@
[Parameter] protected string ClearText { get; set; } = "Clear";
[Parameter] protected string CloseText { get; set; } = "Close";

[Parameter] protected bool Visible
{
get => State.Visible;
set => State.Visible = value;
}
[Parameter] protected bool Inline
{
get => State.Inline;
set => State.Inline = value;
}
[Parameter] protected IsoDayOfWeek FirstDayOfWeek
{
get => State.FirstDayOfWeek;
Expand Down Expand Up @@ -537,7 +545,7 @@
State.Log(nameof(CloseClicked));

if (!Inline)
Visible = false;
State.Close();
}

void OnUpdated()
Expand Down
23 changes: 22 additions & 1 deletion src/BlazorNodaTimeDateTimePicker/DatePickerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public DatePickerState()
internal LocalDate? SelectedDate { get; set; }
internal LocalDate MonthToDisplay { get; private set; }
internal ViewMode ViewMode { get; private set; } = ViewMode.Days;
internal bool Visible { get; set; }
internal bool Inline { get; set; }
internal IsoDayOfWeek FirstDayOfWeek { get; set; } = IsoDayOfWeek.Monday;

internal LocalDate MinDate { get; set; } = LocalDate.MinIsoValue;
Expand Down Expand Up @@ -64,6 +66,7 @@ void SelectedDateChanged()

void Updated() => OnUpdated?.Invoke();
void Opened() => OnOpened?.Invoke();
void Closed() => OnClosed?.Invoke();
void TodaySelected() => OnToday?.Invoke();
void StateChanged() => OnStateChanged?.Invoke();
void MonthToDisplayChanged() => OnMonthToDisplayChanged?.Invoke();
Expand Down Expand Up @@ -267,7 +270,7 @@ internal bool IsDayDisabled(LocalDate date)
if (DisabledDates != null)
{
if (DisabledDates.Contains(date))
return false;
return true;
}

if (date < MinDate)
Expand Down Expand Up @@ -360,5 +363,23 @@ internal bool IsDecadeDisabled(int decade)

return false;
}

internal void Open()
{
if (!Inline)
{
Visible = true;
Opened();
}
}

internal void Close()
{
if (!Inline)
{
Visible = false;
Closed();
}
}
}
}

0 comments on commit 5022521

Please sign in to comment.