Files
2025-12-05 16:54:25 +01:00

52 lines
1.4 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
namespace Test.UI.Components.Layout
{
public partial class NavMenu
{
[Parameter]
public EventCallback<bool> EC_compressUpdated { get; set; }
public void Dispose()
{
NavigationManager.LocationChanged -= OnLocationChanged;
}
protected string hideText { get => showText ? "px-2" : "invisible"; }
protected string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
protected string? TextCss => onlyIcon ? "d-none" : "";
protected override void OnInitialized()
{
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
}
protected void ToggleCompress()
{
showText = !showText;
EC_compressUpdated.InvokeAsync(showText);
}
protected void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
private bool collapseNavMenu = false;
private string? currentUrl;
private bool onlyIcon = false;
private bool showText { get; set; } = true;
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
}
}
}