Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #621 [HxInputDate] Add CalendarDisplayMonth #626

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions BlazorAppTest/Pages/HxInputDate_Issue621_Test.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@page "/HxInputDate_Issue621_Test"
@using Havit;

<h1>HxInputDate Display Month</h1>

<HxInputDate Label="No DisplayMonth" @bind-Value="value1"/>
<HxInputDate Label="Next Month Value" @bind-Value="nextMonth" />
<HxInputDate Label="Next Month Display Month" @bind-Value="value2" CalendarDisplayMonth="@nextMonth" />
<HxInputDateRange Label="DateRange No DisplayMonth" @bind-Value="holidays" />
<HxInputDateRange Label="DateRange From DisplayMonth" @bind-Value="unset1" FromCalendarDisplayMonth="@nextMonthNextYear" />
<HxInputDateRange Label="DateRange To DisplayMonth" @bind-Value="unset2" ToCalendarDisplayMonth="@nextMonthNextYear" />
<HxInputDateRange Label="DateRange Both DisplayMonth" @bind-Value="unset3" FromCalendarDisplayMonth="@nextMonth" ToCalendarDisplayMonth="@nextMonthNextYear"/>

@code {
private DateTime nextMonth;
private DateTime nextMonthNextYear;
private DateTime value1;
private DateTime value2;

private DateTimeRange holidays;
private DateTimeRange unset1;
private DateTimeRange unset2;
private DateTimeRange unset3;

protected override async Task OnInitializedAsync()
{
nextMonth = DateTime.Now.AddDays(1-DateTime.Now.Day).AddMonths(1);
nextMonthNextYear = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddYears(1);
holidays = new DateTimeRange
{
StartDate = nextMonth,
};
await base.OnInitializedAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3875,6 +3875,11 @@
Input-group at the end of the input.
</summary>
</member>
<member name="P:Havit.Blazor.Components.Web.Bootstrap.HxInputDate`1.CalendarDisplayMonth">
<summary>
Month to display.
</summary>
</member>
<member name="M:Havit.Blazor.Components.Web.Bootstrap.HxInputDate`1.FormatValueAsString(`0)">
<inheritdocs />
</member>
Expand Down Expand Up @@ -3975,6 +3980,16 @@
Default customization is configurable with <see cref="P:Havit.Blazor.Components.Web.Bootstrap.HxInputDateRange.Defaults"/>.
</summary>
</member>
<member name="P:Havit.Blazor.Components.Web.Bootstrap.HxInputDateRange.FromCalendarDisplayMonth">
<summary>
Month to display the from calendar, when no start date selected.
</summary>
</member>
<member name="P:Havit.Blazor.Components.Web.Bootstrap.HxInputDateRange.ToCalendarDisplayMonth">
<summary>
Month to display the to calendar, when no end date or start date selected, will default to <see cref="P:Havit.Blazor.Components.Web.Bootstrap.HxInputDateRange.FromCalendarDisplayMonth"/>.
</summary>
</member>
<member name="M:Havit.Blazor.Components.Web.Bootstrap.HxInputDateRange.FormatValueAsString(Havit.DateTimeRange)">
<inheritdocs />
</member>
Expand Down
5 changes: 5 additions & 0 deletions Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public class HxInputDate<TValue> : HxInputBase<TValue>, IInputWithPlaceholder, I
/// </summary>
[Parameter] public RenderFragment InputGroupEndTemplate { get; set; }

/// <summary>
/// Month to display.
/// </summary>
[Parameter] public DateTime CalendarDisplayMonth { get; set; }

[Inject] private IStringLocalizer<HxInputDate> StringLocalizer { get; set; }

Expand Down Expand Up @@ -175,6 +179,7 @@ protected virtual void BuildRenderInputCore(RenderTreeBuilder builder)
builder.AddAttribute(216, nameof(HxInputDateInternal<TValue>.InputGroupStartTemplate), this.InputGroupStartTemplate);
builder.AddAttribute(217, nameof(HxInputDateInternal<TValue>.InputGroupEndTemplate), this.InputGroupEndTemplate);
builder.AddAttribute(218, nameof(HxInputDateInternal<TValue>.InputGroupCssClass), this.InputGroupCssClass);
builder.AddAttribute(219, nameof(HxInputDateInternal<TValue>.CalendarDisplayMonth), this.CalendarDisplayMonth);

builder.AddMultipleAttributes(300, this.AdditionalAttributes);

Expand Down
11 changes: 11 additions & 0 deletions Havit.Blazor.Components.Web.Bootstrap/Forms/HxInputDateRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ static HxInputDateRange()
[Parameter] public CalendarDateCustomizationProviderDelegate CalendarDateCustomizationProvider { get; set; }
protected CalendarDateCustomizationProviderDelegate CalendarDateCustomizationProviderEffective => this.CalendarDateCustomizationProvider ?? this.GetSettings()?.CalendarDateCustomizationProvider ?? GetDefaults().CalendarDateCustomizationProvider;

/// <summary>
/// Month to display the from calendar, when no start date selected.
/// </summary>
[Parameter] public DateTime FromCalendarDisplayMonth { get; set; }
/// <summary>
/// Month to display the to calendar, when no end date or start date selected, will default to <see cref="HxInputDateRange.FromCalendarDisplayMonth"/>.
/// </summary>
[Parameter] public DateTime ToCalendarDisplayMonth { get; set; }

[Inject] private IStringLocalizer<HxInputDateRange> StringLocalizer { get; set; }

protected override void BuildRenderInput(RenderTreeBuilder builder)
Expand Down Expand Up @@ -133,6 +142,8 @@ protected virtual void BuildRenderInputCore(RenderTreeBuilder builder)
builder.AddAttribute(210, nameof(HxInputDateRangeInternal.ShowClearButtonEffective), ShowClearButtonEffective);
builder.AddAttribute(211, nameof(HxInputDateRangeInternal.MinDateEffective), MinDateEffective);
builder.AddAttribute(212, nameof(HxInputDateRangeInternal.MaxDateEffective), MaxDateEffective);
builder.AddAttribute(213, nameof(HxInputDateRangeInternal.FromCalendarDisplayMonth), this.FromCalendarDisplayMonth);
builder.AddAttribute(214, nameof(HxInputDateRangeInternal.ToCalendarDisplayMonth), this.ToCalendarDisplayMonth);
builder.AddAttribute(220, nameof(HxInputDateRangeInternal.CalendarDateCustomizationProviderEffective), CalendarDateCustomizationProviderEffective);

builder.AddMultipleAttributes(300, this.AdditionalAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@if (EnabledEffective)
{
<div class="hx-input-date-calendar">
<HxCalendar Value="@GetDateTimeFromValue(Value)" ValueChanged="HandleCalendarValueChangedAsync" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomization" KeyboardNavigation="false" />
<HxCalendar Value="@GetDateTimeFromValue(Value)" ValueChanged="HandleCalendarValueChangedAsync" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomization" KeyboardNavigation="false" DisplayMonth="@GetCalendarDisplayMonthEffective" />
</div>
<div class="hx-input-date-dropdown-buttons">
@if (ShowClearButtonEffective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public partial class HxInputDateInternal<TValue> : InputBase<TValue>, IAsyncDisp

[Parameter] public IFormValueComponent FormValueComponent { get; set; }

[Parameter] public DateTime CalendarDisplayMonth { get; set; }

[Inject] protected IStringLocalizerFactory StringLocalizerFactory { get; set; }
[Inject] protected IJSRuntime JSRuntime { get; set; }
Expand All @@ -68,6 +69,8 @@ public partial class HxInputDateInternal<TValue> : InputBase<TValue>, IAsyncDisp
protected bool RenderPredefinedDates => ShowPredefinedDatesEffective && (this.PredefinedDatesEffective != null) && PredefinedDatesEffective.Any();
protected bool RenderIcon => CalendarIconEffective is not null && !HasInputGroupsEffective;

protected DateTime GetCalendarDisplayMonthEffective => GetDateTimeFromValue(CurrentValue) ?? CalendarDisplayMonth;

private TValue previousValue;

private bool previousParsingAttemptFailed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@if (EnabledEffective)
{
<div class="hx-input-date-range-calendar">
<HxCalendar Value="@Value.StartDate" ValueChanged="HandleFromCalendarValueChangedAsync" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomizationFrom" KeyboardNavigation="false" />
<HxCalendar Value="@Value.StartDate" ValueChanged="HandleFromCalendarValueChangedAsync" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomizationFrom" KeyboardNavigation="false" DisplayMonth="@GetFromCalendarDisplayMonthEffective" />
</div>
<div class="hx-input-date-range-buttons">
@if (ShowClearButtonEffective)
Expand Down Expand Up @@ -66,7 +66,7 @@
@if (EnabledEffective)
{
<div class="hx-input-date-range-calendar">
<HxCalendar Value="@Value.EndDate" ValueChanged="HandleToCalendarValueChanged" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomizationTo" KeyboardNavigation="false" />
<HxCalendar Value="@Value.EndDate" ValueChanged="HandleToCalendarValueChanged" MinDate="@MinDateEffective" MaxDate="@MaxDateEffective" DateCustomizationProvider="GetCalendarDateCustomizationTo" KeyboardNavigation="false" DisplayMonth="@GetToCalendarDisplayMonthEffective" />
</div>
<div class="hx-input-date-range-buttons">
@if (ShowClearButtonEffective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public partial class HxInputDateRangeInternal : InputBase<DateTimeRange>, IAsync

[Parameter] public CalendarDateCustomizationProviderDelegate CalendarDateCustomizationProviderEffective { get; set; }

[Parameter] public DateTime FromCalendarDisplayMonth { get; set; }
[Parameter] public DateTime ToCalendarDisplayMonth { get; set; }

[Inject] protected IStringLocalizerFactory StringLocalizerFactory { get; set; }

private DateTimeRange previousValue;
Expand All @@ -45,6 +48,32 @@ public partial class HxInputDateRangeInternal : InputBase<DateTimeRange>, IAsync
private HxDropdownToggleElement fromDropdownToggleElement;
private HxDropdownToggleElement toDropdownToggleElement;

private DateTime GetFromCalendarDisplayMonthEffective => CurrentValue.StartDate ?? FromCalendarDisplayMonth;

private DateTime GetToCalendarDisplayMonthEffective
{
get
{
if (CurrentValue.EndDate != null)
{
return CurrentValue.EndDate.Value;
}
if (CurrentValue.StartDate != null && CurrentValue.StartDate != default)
{
if (ToCalendarDisplayMonth != default && ToCalendarDisplayMonth > CurrentValue.StartDate)
{
return ToCalendarDisplayMonth;
}
return CurrentValue.StartDate.Value;
}
if (ToCalendarDisplayMonth != default)
{
return ToCalendarDisplayMonth;
}
return FromCalendarDisplayMonth;
}
}

private bool firstRenderCompleted;

protected override void OnParametersSet()
Expand Down