Skip to content

Instantly share code, notes, and snippets.

@pawelel
Created March 30, 2022 22:04
Show Gist options
  • Save pawelel/0a448e8282f79b8442b5c6b8c80bb404 to your computer and use it in GitHub Desktop.
Save pawelel/0a448e8282f79b8442b5c6b8c80bb404 to your computer and use it in GitHub Desktop.
Mud nav menu - mini drawer and full text
//main
<MudPaper Class="mt-4" Height="400px" Style="overflow:hidden; position:relative;">
<MudDrawerContainer Class="mud-height-full">
<MudDrawer @bind-Open="@open" Fixed="true" DisableOverlay="true" Elevation="1" Variant="@DrawerVariant.Mini">
<NavMenu DrawerOpen="open" />
</MudDrawer>
<div class="d-flex justify-center align-center mud-height-full">
<MudButton OnClick="@ToggleDrawer" Color="Color.Primary">Toggle</MudButton>
</div>
</MudDrawerContainer>
</MudPaper>
@code {
bool open = false;
void ToggleDrawer()
{
open = !open;
}
}
//NavLinkTitle
<div class="@GetClass()">
<MudDivider Class="@(MinimizedDrawerOpen ? "flex-initial" : "flex-1")" Style="@(MinimizedDrawerOpen ? "width:6px;" : "")"/>
<div class="d-flex flex-initial align-center gap-2 mx-2">
<MudIcon Icon="@Icon" Color="Color.Primary" Size="Size.Small"/>
@if(MinimizedDrawerOpen)
{
<MudText Color="Color.Inherit" Class="corpfleet-navmenu-title">@Title</MudText>
}
</div>
<MudDivider Class="flex-1"/>
</div>
@code {
[Parameter] public bool FirstItem { get; set; }
[Parameter] public bool MinimizedDrawerOpen { get; set; }
[Parameter] public string Icon { get; set; }
[Parameter] public string Title { get; set; }
private string GetClass()
{
return $"d-flex align-center mud-width-full {(FirstItem ? "mt-3" : "mt-5")} mb-2";
}
}
/// NavMenu
<MudNavMenu Color="Color.Primary">
<NavLinkTitle FirstItem="true" Title="Section 1" Icon="@Icons.Material.Filled.Badge" MinimizedDrawerOpen="DrawerOpen"/>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Filled.Store">Store</MudNavLink>
<NavLinkTitle FirstItem="true" Title="Section 2" Icon="@Icons.Material.Filled.Badge" MinimizedDrawerOpen="DrawerOpen"/>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Filled.LibraryBooks">Library</MudNavLink>
<NavLinkTitle FirstItem="true" Title="Section 3" Icon="@Icons.Material.Filled.Badge" MinimizedDrawerOpen="DrawerOpen"/>
<MudNavLink Match="NavLinkMatch.All" Icon="@Icons.Filled.Group">Community</MudNavLink>
</MudNavMenu>
@code {
[Parameter] public bool DrawerOpen { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment