diff --git a/examples/FluentUI.Demo.Shared/Pages/CalendarPage.razor b/examples/FluentUI.Demo.Shared/Pages/CalendarPage.razor new file mode 100644 index 0000000000..6db0157c26 --- /dev/null +++ b/examples/FluentUI.Demo.Shared/Pages/CalendarPage.razor @@ -0,0 +1,49 @@ +@page "/CalendarPage" +

Calendar

+ +

Default

+

+ +

+ +

Show 6 weeks minimal

+

+ +

+ +

Disabled dates

+

+ +

+ +

Selected dates

+

+ +

+ +

Day Format = 2 digit

+

+ +

+ +@code { + static int currentYear = DateTime.Now.Year; + static int currentMonth = DateTime.Now.Month; + + static int daysInMonth = DateTime.DaysInMonth(currentYear, currentMonth) + 1; + static Random random = new(); + + List disabledDates = new(); + List selectedDates = new(); + + protected override void OnInitialized() + { + base.OnInitialized(); + + for (int i = 0; i < 3; i++) + { + disabledDates.Add(new DateOnly(currentYear, currentMonth, random.Next(1, daysInMonth))); + selectedDates.Add(new DateOnly(currentYear, currentMonth, random.Next(1, daysInMonth))); + }; + } +} \ No newline at end of file diff --git a/examples/FluentUI.Demo.Shared/Shared/MainLayout.razor.cs b/examples/FluentUI.Demo.Shared/Shared/MainLayout.razor.cs index 0da02c6832..0f96aa973a 100644 --- a/examples/FluentUI.Demo.Shared/Shared/MainLayout.razor.cs +++ b/examples/FluentUI.Demo.Shared/Shared/MainLayout.razor.cs @@ -29,7 +29,7 @@ public async Task SwitchDirection() public void SwitchTheme() { - baseLayerLuminance = baseLayerLuminance == 0.2f ? 1 : 0.2f; + baseLayerLuminance = baseLayerLuminance == 0.15f ? 0.98f : 0.15f; } protected override void OnParametersSet() diff --git a/examples/FluentUI.Demo.Shared/Shared/NavMenu.razor b/examples/FluentUI.Demo.Shared/Shared/NavMenu.razor index 41cba9c795..e6632d5c15 100644 --- a/examples/FluentUI.Demo.Shared/Shared/NavMenu.razor +++ b/examples/FluentUI.Demo.Shared/Shared/NavMenu.razor @@ -25,6 +25,9 @@
  • Button
  • +
  • + Calendar +
  • Card
  • diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor new file mode 100644 index 0000000000..786445ba99 --- /dev/null +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor @@ -0,0 +1,17 @@ +@inherits FluentComponentBase + +@ChildContent + diff --git a/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor.cs b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor.cs new file mode 100644 index 0000000000..166c4245e2 --- /dev/null +++ b/src/Microsoft.Fast.Components.FluentUI/Components/FluentCalendar.razor.cs @@ -0,0 +1,104 @@ +using Microsoft.AspNetCore.Components; + +namespace Microsoft.Fast.Components.FluentUI; +public partial class FluentCalendar : FluentComponentBase +{ + private string? disabledDates = null; + private string? selectedDates = null; + + /// + /// Gets or sets if the calendar is readonly + /// + [Parameter] + public bool? Readonly { get; set; } + + + /// + /// Gets or sets the month of the calendar to display + /// + [Parameter] + public int Month { get; set; } = DateTime.Now.Month; + + /// + /// Gets or sets the year of the calendar to display + /// + [Parameter] + public int Year { get; set; } = DateTime.Now.Year; + + /// + /// Locale information which can include market (language and country), calendar type and numbering type. + /// + [Parameter] + public string? Locale { get; set; } + + /// + /// Gets or sets formatting for the numbered days. + /// + [Parameter] + public DayFormat? DayFormat { get; set; } = FluentUI.DayFormat.Numeric; + + /// + /// Gets or sets formatting for the weekday titles. + /// + [Parameter] + public WeekdayFormat? WeekdayFormat { get; set; } = FluentUI.WeekdayFormat.Short; + + /// + /// Gets or sets formatting for the month name in the title. + /// + [Parameter] + public MonthFormat? MonthFormat { get; set; } = FluentUI.MonthFormat.Long; + + /// + /// Gets or sets formatting for the year in the title. + /// + [Parameter] + public YearFormat? YearFormat { get; set; } = FluentUI.YearFormat.Numeric; + + /// + /// Gets or sets the minimum number of weeks to show. This allows for normalizing of calendars so that they take up the same vertical space. + /// + [Parameter] + public int MinWeeks { get; set; } = 4; + + + /// + /// Gets or sets dates to be shown as disabled. + /// + [Parameter] + public IEnumerable? DisabledDates + { + get + { + return disabledDates!.Split(",").Select(x => + { + _ = DateOnly.TryParse(x, out DateOnly d); + return d; + }); + } + set + { + disabledDates = string.Join(",", value!.Select(x => x.ToString("M-d-yyyy"))); + } + } + + /// + /// Gets or sets dates to be shown as selected + /// + [Parameter] + public IEnumerable? SelectedDates + { + get + { + return selectedDates!.Split(",").Select(x => + { + _ = DateOnly.TryParse(x, out DateOnly d); + return d; + }); + } + set + { + selectedDates = string.Join(",", value!.Select(x => x.ToString("M-d-yyyy"))); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Fast.Components.FluentUI/Enums/CalendarFormats.cs b/src/Microsoft.Fast.Components.FluentUI/Enums/CalendarFormats.cs new file mode 100644 index 0000000000..ce14295e36 --- /dev/null +++ b/src/Microsoft.Fast.Components.FluentUI/Enums/CalendarFormats.cs @@ -0,0 +1,92 @@ +namespace Microsoft.Fast.Components.FluentUI; + +/// +/// Enum representing the different day formats +/// +public enum DayFormat +{ + TwoDigit, + Numeric +} + +/// +/// Enum representing the different weekday formats +/// +public enum WeekdayFormat +{ + Long, + Narrow, + Short +} + +/// +/// Enum representing the different month formats +/// +public enum MonthFormat +{ + TwoDigit, + Long, + Narrow, + Numeric, + Short +} + +/// +/// Enum representing the different year formats +/// +public enum YearFormat +{ + TwoDigit, + Numeric +} + +internal static class CalendarFormatExtensions +{ + // DayFormat extension + private static readonly Dictionary _dayFormatValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); + + public static string? ToAttributeValue(this DayFormat? value) + { + if (value is null) return null; + return value switch + { + DayFormat.TwoDigit => "2-digit", + _ => _dayFormatValues[value.Value], + }; + } + + // WeekdayFormat extension + private static readonly Dictionary _weekdayFormatValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); + + public static string? ToAttributeValue(this WeekdayFormat? value) => value == null ? null : _weekdayFormatValues[value.Value]; + + // MonthFormat extension + private static readonly Dictionary _monthFormatValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); + + public static string? ToAttributeValue(this MonthFormat? value) + { + if (value is null) return null; + return value switch + { + MonthFormat.TwoDigit => "2-digit", + _ => _monthFormatValues[value.Value], + }; + } + + // YearFormat extension + private static readonly Dictionary _yearFormatValues = + Enum.GetValues().ToDictionary(id => id, id => Enum.GetName(id)!.ToLowerInvariant()); + + public static string? ToAttributeValue(this YearFormat? value) + { + if (value is null) return null; + return value switch + { + YearFormat.TwoDigit => "2-digit", + _ => _yearFormatValues[value.Value], + }; + } +} \ No newline at end of file