Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,14 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentCalendar.OnSelectDayMouseOverAsync(System.DateTime,System.Boolean)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentCalendar.AllDaysAreDisabled(System.DateTime,System.DateTime)">
<summary>
Check if all days between two dates are disabled.
</summary>
<param name="start"></param>
<param name="end"></param>
<returns></returns>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentCalendarBase.Culture">
<summary>
Gets or sets the culture of the component.
Expand All @@ -2742,6 +2750,12 @@
Function to know if a specific day must be disabled.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentCalendarBase.DisabledCheckAllDaysOfMonthYear">
<summary>
By default, the <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentCalendarBase.DisabledDateFunc" /> check only the first day of the month and the first day of the year for the Month and Year views.
Set this property to `true` to check if all days of the month and year are disabled (more time consuming).
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentCalendarBase.DisabledSelectable">
<summary>
Apply the disabled style to the <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentCalendarBase.DisabledDateFunc"/> days.
Expand Down Expand Up @@ -14600,6 +14614,14 @@
<param name="culture"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.Extensions.DateTimeExtensions.EndOfYear(System.DateTime,System.Globalization.CultureInfo)">
<summary>
Returns the last day of the year.
</summary>
<param name="self"></param>
<param name="culture"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.Extensions.DateTimeExtensions.EndOfMonth(System.DateTime,System.Globalization.CultureInfo)">
<summary>
Returns the last day of the month.
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Components/DateTime/FluentCalendar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
Culture="@Culture"
DisabledSelectable="@DisabledSelectable"
AnimatePeriodChanges="@AnimatePeriodChanges"
DisabledCheckAllDaysOfMonthYear="@DisabledCheckAllDaysOfMonthYear"
DisabledDateFunc="@(e => DisabledDateFunc != null ? DisabledDateFunc(e) : false)" />
}

Expand All @@ -177,6 +178,7 @@
Culture="@Culture"
DisabledSelectable="@DisabledSelectable"
AnimatePeriodChanges="@AnimatePeriodChanges"
DisabledCheckAllDaysOfMonthYear="@DisabledCheckAllDaysOfMonthYear"
DisabledDateFunc="@(e => DisabledDateFunc != null ? DisabledDateFunc(e) : false)" />
}

Expand Down
24 changes: 24 additions & 0 deletions src/Core/Components/DateTime/FluentCalendar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,28 @@ private Task OnSelectDayMouseOverAsync(DateTime value, bool dayDisabled)

return Task.CompletedTask;
}

/// <summary>
/// Check if all days between two dates are disabled.
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
internal bool AllDaysAreDisabled(DateTime start, DateTime end)
{
if (DisabledDateFunc is null)
{
return false;
}

for (var day = start; day <= end; day = day.AddDays(1))
{
if (!DisabledDateFunc.Invoke(day))
{
return false;
}
}

return true;
}
}
7 changes: 7 additions & 0 deletions src/Core/Components/DateTime/FluentCalendarBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public abstract class FluentCalendarBase : FluentInputBase<DateTime?>
[Parameter]
public virtual Func<DateTime, bool>? DisabledDateFunc { get; set; }

/// <summary>
/// By default, the <see cref="DisabledDateFunc" /> check only the first day of the month and the first day of the year for the Month and Year views.
/// Set this property to `true` to check if all days of the month and year are disabled (more time consuming).
/// </summary>
[Parameter]
public virtual bool DisabledCheckAllDaysOfMonthYear { get; set; }

/// <summary>
/// Apply the disabled style to the <see cref="DisabledDateFunc"/> days.
/// If this is not the case, the days are displayed like the others, but cannot be selected.
Expand Down
9 changes: 8 additions & 1 deletion src/Core/Components/DateTime/FluentCalendarMonth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ internal FluentCalendarMonth(FluentCalendar calendar, DateTime month)
_calendar = calendar;
Month = month.GetDay(_calendar.Culture) == 1 ? month : month.StartOfMonth(_calendar.Culture);

_isInDisabledList = calendar.DisabledDateFunc?.Invoke(Month) ?? false;
if (calendar.DisabledCheckAllDaysOfMonthYear)
{
_isInDisabledList = calendar.AllDaysAreDisabled(month.StartOfMonth(_calendar.Culture), month.EndOfMonth(_calendar.Culture));
}
else
{
_isInDisabledList = calendar.DisabledDateFunc?.Invoke(Month) ?? false;
}
}

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/Core/Components/DateTime/FluentCalendarYear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ internal FluentCalendarYear(FluentCalendar calendar, DateTime year)
_calendar = calendar;
Year = year.GetDay(_calendar.Culture) == 1 && year.GetMonth(_calendar.Culture) == 1 ? year : year.StartOfYear(_calendar.Culture);

_isInDisabledList = calendar.DisabledDateFunc?.Invoke(Year) ?? false;
if (calendar.DisabledCheckAllDaysOfMonthYear)
{
_isInDisabledList = calendar.AllDaysAreDisabled(year.StartOfYear(_calendar.Culture), year.EndOfYear(_calendar.Culture));
}
else
{
_isInDisabledList = calendar.DisabledDateFunc?.Invoke(Year) ?? false;
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/DateTime/FluentDatePicker.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
View="@View"
DayFormat="@DayFormat"
DisabledDateFunc="@DisabledDateFunc"
DisabledCheckAllDaysOfMonthYear="@DisabledCheckAllDaysOfMonthYear"
DisabledSelectable="@DisabledSelectable"
Value="@Value"
ValueChanged="@OnSelectedDateAsync"
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public static DateTime StartOfYear(this DateTime self, CultureInfo culture)
return culture.Calendar.ToDateTime(year, 1, 1, 0, 0, 0, 0);
}

/// <summary>
/// Returns the last day of the year.
/// </summary>
/// <param name="self"></param>
/// <param name="culture"></param>
/// <returns></returns>
public static DateTime EndOfYear(this DateTime self, CultureInfo culture)
{
return self.StartOfYear(culture).AddYears(1, culture).AddDays(-1, culture);
}

/// <summary>
/// Returns the last day of the month.
/// </summary>
Expand Down