namespace Lux.UI.Components.Layout { public partial class NavMenu : IDisposable { #region Public Properties [Parameter] public EventCallback EC_compressUpdated { get; set; } #endregion Public Properties #region Public Methods public void Dispose() { NavigationManager.LocationChanged -= OnLocationChanged; } #endregion Public Methods #region Protected Properties protected string hideText { get => showText ? "" : "invisible"; } [Inject] protected NavigationManager NavigationManager { get; set; } = null!; protected string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; protected string subArtCss { get => showText ? "ps-5" : ""; } protected string? TextCss => onlyIcon ? "d-none" : ""; #endregion Protected Properties #region Protected Methods protected override void OnInitialized() { currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri); NavigationManager.LocationChanged += OnLocationChanged; UpdateDict(); } protected void ToggleCompress() { showText = !showText; EC_compressUpdated.InvokeAsync(showText); } protected void ToggleNavMenu() { collapseNavMenu = !collapseNavMenu; } #endregion Protected Methods #region Private Fields private bool collapseNavMenu = true; private string? currentUrl; private Dictionary> IconDict = new Dictionary>(); private Dictionary> NameDict = new Dictionary>(); private bool onlyIcon = false; private Dictionary> PageDict = new Dictionary>(); #endregion Private Fields #region Private Properties private bool showText { get; set; } = true; #endregion Private Properties #region Private Methods private void OnLocationChanged(object? sender, LocationChangedEventArgs e) { currentUrl = NavigationManager.ToBaseRelativePath(e.Location); StateHasChanged(); } /// /// Aggiornamento dizionari per pagine raggruppate in sottomenu /// private void UpdateDict() { // Inserimento nomi segnaposto nav-item NameDict.Add("Articoli", new List() { "articoli", "artAcquisto", "artVendita" }); NameDict.Add("CicloProd", new List() { "cicloProd", "risorse", "cicli" }); NameDict.Add("Contatti", new List() { "contatti", "clienti", "venditori" }); // Inserimento icone IconDict.Add("Articoli", new List() { "fa-book-open", "fa-book", "fa-book-bookmark" }); IconDict.Add("CicloProd", new List() { "fa-industry", "fa-location-dot", "fa-route" }); IconDict.Add("Contatti", new List() { "fa-address-book", "fa-users", "fa-stamp" }); // Inserimento reindirizzamento elementi sotto menu PageDict.Add("Articoli", new List() { "Items", "SellItems" }); PageDict.Add("CicloProd", new List() { "Resources", "JobRoute" }); PageDict.Add("Contatti", new List() { "Customer", "Dealer" }); } #endregion Private Methods } }