Skip to content

Commit

Permalink
#289 - Bottom menu with fixed items.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed May 25, 2021
1 parent dd40b7e commit b64a500
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 16 deletions.
27 changes: 27 additions & 0 deletions src/Money.Blazor.Host/Layouts/BottomMenu.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="row my-2 [email protected]">
@foreach (var item in Items)
{
<div class="col">
@if (item.Url != null)
{
<Match Url="@item.Url" PageType="@item.PageType" Context="IsActive">
<a href="@item.Url" class="btn btn-block @(IsActive ? "btn-primary" : "btn-light")">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</a>
</Match>
}
else
{
<button @onclick="@item.OnClick" class="btn btn-block btn-light">
<Icon Identifier="@item.Icon" />
<span class="text">
@item.Text
</span>
</button>
}
</div>
}
</div>
63 changes: 63 additions & 0 deletions src/Money.Blazor.Host/Layouts/BottomMenu.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.AspNetCore.Components;
using Money.Pages;
using Money.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Money.Layouts
{
public partial class BottomMenu
{
[Inject]
protected Navigator Navigator { get; set; }

protected List<MenuItemModel> Items { get; set; }

protected async override Task OnInitializedAsync()
{
await base.OnInitializedAsync();

Items = new List<MenuItemModel>()
{
new MenuItemModel()
{
Icon = "chart-pie",
Text = "Monthly",
Url = Navigator.UrlSummary(),
PageType = typeof(SummaryMonth)
},
new MenuItemModel()
{
Icon = "search",
Text = "Search",
Url = Navigator.UrlSearch()
},
new MenuItemModel()
{
Icon = "tag",
Text = "Categories",
Url = Navigator.UrlCategories()
},
new MenuItemModel()
{
Icon = "minus-circle",
Text = "New Expense",
OnClick = Navigator.OpenExpenseCreate
}
};
}
}

public class MenuItemModel
{
public string Icon { get; set; }
public string Text { get; set; }
public string Url { get; set; }
public Type PageType { get; set; }
public Action OnClick { get; set; }
}
}
10 changes: 7 additions & 3 deletions src/Money.Blazor.Host/Layouts/Layout.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using Neptuo.Exceptions.Handlers
@inherits LayoutComponentBase
@inherits LayoutComponentBase

<nav class="navbar fixed-top navbar-expand-lg navbar-dark">
<div class="container">
Expand All @@ -9,7 +8,12 @@
<div class="container body-content">
@Body
</div>
<footer>
<nav class="fixed-bottom d-block d-sm-none bottom-bar">
<div class="container">
<BottomMenu />
</div>
</nav>
<footer class="d-none d-sm-block">
<div class="container">
<hr />

Expand Down
27 changes: 22 additions & 5 deletions src/Money.Blazor.Host/Layouts/MainMenuLink.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<li class="nav-item">
<a href="@Href" class="nav-link @(IsActive() ? "active" : "")">
@ChildContent
</a>
</li>
<Match Url="@Href" Mode="@HrefMatch" PageType="@PageType" Context="IsActive">
<li class="nav-item">
<a href="@Href" class="nav-link @(IsActive ? "active" : "")">
@ChildContent
</a>
</li>
</Match>

@code
{
[Parameter]
public string Href { get; set; }

[Parameter]
public MatchMode HrefMatch { get; set; } = MatchMode.Exact;

[Parameter]
public Type PageType { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }
}
1 change: 1 addition & 0 deletions src/Money.Blazor.Host/Layouts/Match.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@ChildContent(IsActive())
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

namespace Money.Layouts
{
public partial class MainMenuLink : IDisposable
public partial class Match : IDisposable
{
[Inject]
protected NavigationManager NavigationManager { get; set; }

[Parameter]
public string Href { get; set; }
public string Url { get; set; }

[Parameter]
public MainMenuLinkMatch HrefMatch { get; set; } = MainMenuLinkMatch.Exact;
public MatchMode Mode { get; set; } = MatchMode.Exact;

[Parameter]
public Type PageType { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }
public RenderFragment<bool> ChildContent { get; set; }

[CascadingParameter]
public RouteData RouteData { get; set; }
Expand All @@ -49,7 +49,7 @@ protected bool IsActive()
return PageType == RouteData.PageType;

string currentUrl = "/" + NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
if ((HrefMatch == MainMenuLinkMatch.Exact && Href == currentUrl) || currentUrl.StartsWith(Href))
if ((Mode == MatchMode.Exact && Url == currentUrl) || currentUrl.StartsWith(Url))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Money.Layouts
{
public enum MainMenuLinkMatch
public enum MatchMode
{
Exact,
StartsWith
Expand Down
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Layouts/UserInfo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ChildContent>
@if (Profile != null)
{
<MainMenuLink Href="@Navigator.UrlUserManage()" HrefMatch="@MainMenuLinkMatch.StartsWith">
<MainMenuLink Href="@Navigator.UrlUserManage()" HrefMatch="@MatchMode.StartsWith">
<Icon Identifier="user" />
<span class="d-lg-none d-xl-inline">
@Profile.UserName
Expand Down
8 changes: 8 additions & 0 deletions src/Money.Blazor.Host/Money.Blazor.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@
<PropertyGroup>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>
<ItemGroup>
<Watch Remove="Layouts\Match.razor" />
</ItemGroup>
<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>
<ItemGroup>
<Compile Update="Layouts\Match.razor.cs">
<DependentUpon>Match.razor</DependentUpon>
</Compile>
</ItemGroup>

<!-- GitHubPages publish -->
<Target Name="PublishGitHubFiles" AfterTargets="ComputeFilesToPublish">
Expand Down
Loading

0 comments on commit b64a500

Please sign in to comment.