Skip to content

Commit

Permalink
Merge pull request #184 from danheron/feature/month-scrollbar
Browse files Browse the repository at this point in the history
Remove scroll bars when too many items shown in month view and replace with +n more message
  • Loading branch information
danheron authored Nov 11, 2024
2 parents 300d8f3 + 9fdfc6d commit aa064ce
Show file tree
Hide file tree
Showing 38 changed files with 216 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace Heron.MudCalendar.Docs.Examples

<MudCalendar Items="_events" Height="600" MonthCellMinHeight="@(_fixed ? 0 : 115)">
<MudCalendar Items="_events" Height="630" MonthCellMinHeight="@(_fixed ? 0 : 115)">
<MonthTemplate>
<div class="d-flex gap-1">
<MudIcon Icon="@Icons.Material.Filled.Circle" Color="Color.Secondary" Size="Size.Small"/>
Expand Down
4 changes: 3 additions & 1 deletion Heron.MudCalendar/Components/MonthView.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@namespace Heron.MudCalendar
@using Microsoft.JSInterop
@inherits CalendarViewBase
@inject IJSRuntime JsRuntime

@Render

Expand Down Expand Up @@ -89,7 +91,7 @@
/// </summary>
protected virtual RenderFragment RenderCellContainer(CalendarCell cell, int index) =>
@<div class="@CellClassname" style="@DayStyle(cell, index)" @onclick="() => OnCellLinkClicked(cell)">
<MudDropZone T="CalendarItem" Identifier="@cell.Date.Date.ToString("d")" Class="mud-cal-month-dropzone" Style="@CellStyle">
<MudDropZone T="CalendarItem" Identifier="@cell.Date.Date.ToString("d")" Class="mud-cal-month-dropzone">
@RenderCell(cell)
</MudDropZone>
</div>;
Expand Down
54 changes: 48 additions & 6 deletions Heron.MudCalendar/Components/MonthView.razor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
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;
using MudBlazor.Utilities;

namespace Heron.MudCalendar;

public partial class MonthView : CalendarViewBase
public partial class MonthView : CalendarViewBase, IDisposable
{
private MudDropContainer<CalendarItem>? _dropContainer;

private JsService? _jsService;

private static CultureInfo? _uiCulture;
private static string? _moreText;

protected virtual int Columns => 7;

/// <summary>
Expand All @@ -25,11 +35,6 @@ public partial class MonthView : CalendarViewBase
Calendar.MonthCellMinHeight == 0)
.Build();

protected virtual string CellStyle =>
new StyleBuilder()
.AddStyle("overflow-y", "scroll", Calendar.MonthCellMinHeight == 0)
.Build();

/// <summary>
/// Classes added to each month cell.
/// </summary>
Expand Down Expand Up @@ -88,6 +93,12 @@ protected override void OnParametersSet()
// Ensure that the order of items is correct
_dropContainer?.Refresh();
}

protected override Task OnAfterRenderAsync(bool firstRender)
{
// Truncate overflowing calendar items
return TruncateOverflows();
}

/// <summary>
/// Method invoked when the user clicks on the calendar item.
Expand Down Expand Up @@ -162,6 +173,37 @@ private async Task ItemDropped(MudItemDropInfo<CalendarItem> dropItem)

await Calendar.ItemChanged.InvokeAsync(item);
}

private async Task TruncateOverflows()
{
// Load localized text
var moreText = LoadText();

// Truncate overflowing calendar items
_jsService ??= new JsService(JsRuntime);
await _jsService.HideOverflows("mud-cal-month-dropzone", moreText);
}

private string LoadText()
{
if (_moreText != null && Equals(_uiCulture, Thread.CurrentThread.CurrentUICulture)) return _moreText;

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;
_moreText = localizer["More"];

return _moreText;
}

private RenderFragment<CalendarItem> CellTemplate => Calendar.MonthTemplate ?? Calendar.CellTemplate;

public void Dispose()
{
GC.SuppressFinalize(this);

_jsService?.Dispose();
}
}
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.bg.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Днес</value>
</data>
<data name="More" xml:space="preserve">
<value>Още</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.cs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Dnes</value>
</data>
<data name="More" xml:space="preserve">
<value>Více na</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.da.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>I dag</value>
</data>
<data name="More" xml:space="preserve">
<value>Mere om det</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Heute</value>
</data>
<data name="More" xml:space="preserve">
<value>Mehr</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.el.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Σήμερα</value>
</data>
<data name="More" xml:space="preserve">
<value>Περισσότερα</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Hoy</value>
</data>
<data name="More" xml:space="preserve">
<value>Más</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.et.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Täna</value>
</data>
<data name="More" xml:space="preserve">
<value>Rohkem</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.fi.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Tänään</value>
</data>
<data name="More" xml:space="preserve">
<value>Lisää</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Aujourd'hui</value>
</data>
<data name="More" xml:space="preserve">
<value>Plus d'informations</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.hr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Danas</value>
</data>
<data name="More" xml:space="preserve">
<value>Više</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.hu.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Ma</value>
</data>
<data name="More" xml:space="preserve">
<value>További</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.id.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Hari ini</value>
</data>
<data name="More" xml:space="preserve">
<value>Lebih lanjut</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Oggi</value>
</data>
<data name="More" xml:space="preserve">
<value>Di più</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>今日</value>
</data>
<data name="More" xml:space="preserve">
<value>もっと見る</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.ko.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>오늘</value>
</data>
<data name="More" xml:space="preserve">
<value>자세히 보기</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.lt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Šiandien</value>
</data>
<data name="More" xml:space="preserve">
<value>Daugiau</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.lv.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Šodien</value>
</data>
<data name="More" xml:space="preserve">
<value>Vairāk</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.nb.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>I dag</value>
</data>
<data name="More" xml:space="preserve">
<value>Mer</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.nl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Vandaag</value>
</data>
<data name="More" xml:space="preserve">
<value>Meer</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.pl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Dzisiaj</value>
</data>
<data name="More" xml:space="preserve">
<value>Więcej</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.pt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Hoje</value>
</data>
<data name="More" xml:space="preserve">
<value>Mais</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Today</value>
</data>
<data name="More" xml:space="preserve">
<value>More</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.ro.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Astăzi</value>
</data>
<data name="More" xml:space="preserve">
<value>Mai mult</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Сегодня</value>
</data>
<data name="More" xml:space="preserve">
<value>Подробнее</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.sk.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Dnes</value>
</data>
<data name="More" xml:space="preserve">
<value>Viac na</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.sl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Danes</value>
</data>
<data name="More" xml:space="preserve">
<value>Več</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.sv.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Idag</value>
</data>
<data name="More" xml:space="preserve">
<value>Mer om</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.tr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Bugün</value>
</data>
<data name="More" xml:space="preserve">
<value>Daha fazla</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.uk.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>Сьогодні</value>
</data>
<data name="More" xml:space="preserve">
<value>Більше</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Heron.MudCalendar/Resources/MudCalendar.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<data name="Today" xml:space="preserve">
<value>今天</value>
</data>
<data name="More" xml:space="preserve">
<value>更多信息</value>
</data>
</root>
Loading

0 comments on commit aa064ce

Please sign in to comment.