Browse Source

Refactor navigation components.

pull/25235/head
maliming 8 months ago
parent
commit
8b62569453
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 2
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme/MudBlazorBasicThemeToolbarContributor.cs
  2. 5
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/Branding.razor
  3. 2
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/MainLayout.razor
  4. 22
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/NavMenu.razor
  5. 20
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/NavMenuItem.razor
  6. 56
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor

2
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Server.MudBlazorBasicTheme/MudBlazorBasicThemeToolbarContributor.cs

@ -11,8 +11,8 @@ public class MudBlazorBasicThemeToolbarContributor : IToolbarContributor
{
if (context.Toolbar.Name == StandardToolbars.Main)
{
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginDisplay)));
context.Toolbar.Items.Add(new ToolbarItem(typeof(LanguageSwitch)));
context.Toolbar.Items.Add(new ToolbarItem(typeof(LoginDisplay)));
}
return Task.CompletedTask;

5
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/Branding.razor

@ -1,5 +0,0 @@
@using Volo.Abp.Ui.Branding
@using MudBlazor
@inject IBrandingProvider BrandingProvider
<MudText Typo="Typo.h6" Class="ma-0">@BrandingProvider.AppName</MudText>

2
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/MainLayout.razor

@ -15,14 +15,12 @@
Color="Color.Inherit"
Edge="Edge.Start"
OnClick="@ToggleDrawer" />
<Branding />
<MudSpacer />
<NavToolbar />
</MudAppBar>
<MudDrawer @bind-Open="@_drawerOpen"
Elevation="1"
Variant="@DrawerVariant.Mini"
Width="280px">
<NavMenu />
</MudDrawer>

22
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/NavMenu.razor

@ -1,10 +1,14 @@
@using Microsoft.AspNetCore.Components.Routing
@if (Menu != null)
{
<MudNavMenu>
@foreach (var menuItem in Menu.Items)
@using Volo.Abp.Ui.Branding
@inject IBrandingProvider BrandingProvider
<MudNavMenu>
<MudText Typo="Typo.h6" Class="px-4 pt-2">@BrandingProvider.AppName</MudText>
<MudDivider Class="my-1"/>
@if(Menu != null && !Menu.Items.IsNullOrEmpty())
{
foreach (var menuItem in Menu.Items)
{
@if (menuItem.Items.IsNullOrEmpty())
if (menuItem.Items.IsNullOrEmpty())
{
<MudNavLink Href="@menuItem.Url" Match="@(menuItem.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)">
<MudIcon Icon="@menuItem.Icon" Size="Size.Small" />
@ -13,8 +17,8 @@
}
else
{
<FirstLevelNavMenuItem MenuItem="menuItem" />
<NavMenuItem MenuItem="menuItem" />
}
}
</MudNavMenu>
}
}
</MudNavMenu>

20
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/FirstLevelNavMenuItem.razor → modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/NavMenuItem.razor

@ -13,7 +13,7 @@
}
else
{
<MudNavGroup>
<MudNavGroup Expanded="@MenuItem.Items.Any(IsExpanded)">
<TitleContent>
<MudIcon Icon="@MenuItem.Icon" Title="@MenuItem.DisplayName" Size="Size.Small" />
<MudText Class="ms-1" Inline="true">@MenuItem.DisplayName</MudText>
@ -23,7 +23,7 @@ else
{
@if (item.Items.Any())
{
<SecondLevelNavMenuItem MenuItem="item"/>
<NavMenuItem MenuItem="item"/>
}
else
{
@ -54,6 +54,22 @@ else
// Menu will close automatically on navigation
}
protected virtual bool IsExpanded(ApplicationMenuItem item)
{
if (!item.Url.IsNullOrEmpty())
{
var menuItemPath = item.Url.Replace("~/", string.Empty).Trim('/');
var currentPagePath = new Uri(NavigationManager.Uri.TrimEnd('/')).AbsolutePath.Trim('/');
if (menuItemPath.TrimEnd('/').Equals(currentPagePath, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return item.Items.Any(IsExpanded);
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;

56
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.MudBlazorBasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor

@ -1,56 +0,0 @@
@using Volo.Abp.UI.Navigation
@using MudBlazor
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Routing
@using System
@{
var customComponentType = MenuItem.GetComponentTypeOrDefault();
}
@if (customComponentType != null && typeof(ComponentBase).IsAssignableFrom(customComponentType))
{
<DynamicComponent Type="@customComponentType" />
}
else
{
<MudNavGroup>
<TitleContent>
<MudIcon Icon="@MenuItem.Icon" Title="@MenuItem.DisplayName" Size="Size.Small" />
<MudText Class="ms-2" Inline="true">@MenuItem.DisplayName</MudText>
</TitleContent>
<ChildContent>
@foreach (var item in MenuItem.Items)
{
<MudNavLink Href="@(item.Url?.TrimStart('/', '~') ?? "#")" Match="@(item.Url != null ? NavLinkMatch.All : NavLinkMatch.Prefix)">
<MudIcon Icon="@item.Icon" Size="Size.Small"/>
<MudText Class="ms-2" Inline="true">@item.DisplayName</MudText>
</MudNavLink>
}
</ChildContent>
</MudNavGroup>
}
@code {
[Parameter]
public ApplicationMenuItem MenuItem { get; set; } = default!;
[Inject]
private NavigationManager NavigationManager { get; set; } = default!;
protected override void OnInitialized()
{
NavigationManager.LocationChanged += OnLocationChanged;
}
protected virtual void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
// Menu will close automatically on navigation
}
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
}
@implements IDisposable
Loading…
Cancel
Save