Skip to content

Commit

Permalink
Merge pull request #69 from danheron/feature/today-button
Browse files Browse the repository at this point in the history
Added Today button
  • Loading branch information
danheron authored Nov 4, 2023
2 parents b01fb4e + 0579fa0 commit b6f072e
Show file tree
Hide file tree
Showing 63 changed files with 199 additions and 553 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@namespace Heron.MudCalendar.Docs.Examples

<MudCalendar Outlined="_outlined" ShowPrevNextButtons="_prevNext" ShowDatePicker="_datePicker" Color="_color" ButtonVariant="_buttonVariant" Style="height: 400px;" />
<MudCalendar Outlined="_outlined" ShowPrevNextButtons="_prevNext" ShowDatePicker="_datePicker" ShowTodayButton="_todayButton" Color="_color" ButtonVariant="_buttonVariant" Style="height: 400px;" />

<MudToolBar Class="mt-4">
<MudSwitch @bind-checked="@_outlined" Color="Color.Primary" T="bool">Outlined</MudSwitch>
<MudSwitch @bind-checked="@_prevNext" Color="Color.Primary" T="bool">Prev/Next Buttons</MudSwitch>
<MudSwitch @bind-checked="@_datePicker" Color="Color.Primary" T="bool">Date Picker</MudSwitch>
<MudSwitch @bind-checked="@_todayButton" Color="Color.Primary" T="bool">Today Button</MudSwitch>
<MudSelect @bind-Value="_color" T="Color" Label="Color" Placeholder="Select Color" Class="ml-4">
<MudSelectItem Value="Color.Primary">Primary</MudSelectItem>
<MudSelectItem Value="Color.Secondary">Secondary</MudSelectItem>
Expand All @@ -22,6 +23,7 @@
private bool _outlined;
private bool _prevNext = true;
private bool _datePicker = true;
private bool _todayButton = false;
private Color _color = Color.Primary;
private Variant _buttonVariant = Variant.Filled;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<MudPopoverProvider></MudPopoverProvider>

<MudCalendar Items="_events" Height="500" />
<MudCalendar Items="_events" Height="500" ShowTodayButton="true" />

@code {
public static string __description__ = "Basic Calendar Tests";
Expand Down
4 changes: 2 additions & 2 deletions Heron.MudCalendar.UnitTests/Components/CalendarTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading;
using AngleSharp.Dom;
using FluentAssertions;
using Heron.MudCalendar.UnitTests.Viewer.TestComponents.Calendar;
using MudBlazor;
Expand Down Expand Up @@ -214,6 +212,8 @@ public void ViewNameLocalization()

comp.Find("div.mud-button-group-root button.mud-button-root span.mud-button-label").TextContent.Should()
.Be("Monat");

comp.FindAll("div.mud-cal-toolbar > div > button")[2].TextContent.Should().Be("Heute");
}

[Test]
Expand Down
10 changes: 7 additions & 3 deletions Heron.MudCalendar/Components/MudCalendar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@
<div>
@if (ShowPrevNextButtons)
{
<MudIconButton Variant="@ButtonVariant" Icon="@Icons.Material.Outlined.ChevronLeft" Color="@Color" OnClick="OnPreviousClicked" Class="mr-2"/>
<MudIconButton Variant="@ButtonVariant" Icon="@Icons.Material.Outlined.ChevronRight" Color="@Color" OnClick="OnNextClicked" Class="mr-2"/>
<MudIconButton Variant="@ButtonVariant" Icon="@Icons.Material.Outlined.ChevronLeft" Color="@Color" OnClick="OnPreviousClicked" Class="mx-1"/>
<MudIconButton Variant="@ButtonVariant" Icon="@Icons.Material.Outlined.ChevronRight" Color="@Color" OnClick="OnNextClicked" Class="mr-1"/>
}
@if (ShowDatePicker)
{
<CalendarDatePicker @ref="_datePicker" Date="PickerDate" DateChanged="DatePickerDateChanged" @bind-View="View" Variant="ButtonVariant" Color="Color" Class="ml-1" PickerOpened="OnDatePickerOpened"/>
<CalendarDatePicker @ref="_datePicker" Date="PickerDate" DateChanged="DatePickerDateChanged" @bind-View="View" Variant="ButtonVariant" Color="Color" Class="mx-1" PickerOpened="OnDatePickerOpened"/>
}
@if (ShowTodayButton)
{
<MudButton Variant="@ButtonVariant" Color="@Color" OnClick="OnTodayClicked" Class="mx-1">@DrawTodayText()</MudButton>
}
</div>
<div>
Expand Down
43 changes: 41 additions & 2 deletions Heron.MudCalendar/Components/MudCalendar.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Globalization;
using Heron.MudCalendar.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using MudBlazor.Utilities;
using MudBlazor;
using CategoryAttribute = Heron.MudCalendar.Attributes.CategoryAttribute;
Expand All @@ -9,8 +13,6 @@ namespace Heron.MudCalendar;

public partial class MudCalendar : MudComponentBase
{
private JsService? _jsService;

/// <summary>
/// The higher the number, the heavier the drop-shadow. 0 for no shadow.
/// </summary>
Expand Down Expand Up @@ -116,6 +118,13 @@ public partial class MudCalendar : MudComponentBase
[Category(CategoryTypes.Calendar.Behavior)]
public bool ShowDatePicker { get; set; } = true;

/// <summary>
/// If true the Today button is shown.
/// </summary>
[Parameter]
[Category(CategoryTypes.Calendar.Behavior)]
public bool ShowTodayButton { get; set; } = false;

/// <summary>
/// Set the day start time for week/day views.
/// </summary>
Expand Down Expand Up @@ -212,6 +221,11 @@ private DateTime? PickerDate
private CalendarDateRange? _currentDateRange;

private CalendarDatePicker? _datePicker;

private JsService? _jsService;

private static CultureInfo? _uiCulture;
private static string? _todayText;

/// <summary>
/// Classes added to main div of component.
Expand Down Expand Up @@ -317,6 +331,31 @@ protected virtual Task OnPreviousClicked()
return ChangeDateRange();
}

/// <summary>
/// Method invoked when the user clicks the today button.
/// </summary>
/// <returns></returns>
protected virtual Task OnTodayClicked()
{
CurrentDay = DateTime.Today;

return ChangeDateRange();
}

protected string DrawTodayText()
{
if (_todayText != null && Equals(_uiCulture, Thread.CurrentThread.CurrentUICulture)) return _todayText;

var options = Options.Create(new LocalizationOptions { ResourcesPath = "Resources" });
var factory = new ResourceManagerStringLocalizerFactory(options, NullLoggerFactory.Instance);
var localizer = new StringLocalizer<MudCalendar>(factory);

_uiCulture = Thread.CurrentThread.CurrentUICulture;
_todayText = localizer["Today"];

return _todayText;
}

private async Task SetLinks()
{
// Check if link is already set
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.bg.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Ден</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.cs.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Den</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.da.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Dag</value>
</data>
Expand Down
12 changes: 0 additions & 12 deletions Heron.MudCalendar/Resources/CalendarView.de.resx
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Tag</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.el.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Ημέρα</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.es.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Día</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.et.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Päev</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.fi.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Päivä</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.fr.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Jour</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.hu.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Nap</value>
</data>
Expand Down
19 changes: 0 additions & 19 deletions Heron.MudCalendar/Resources/CalendarView.id.resx
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Day" xml:space="preserve">
<value>Hari</value>
</data>
Expand Down
Loading

0 comments on commit b6f072e

Please sign in to comment.