Enterprise-level component library based on Bootstrap and Blazor

star nuget master download license repo commit

Menu

A list of menus that provide navigation for pages and features.

A wide range of basic usages are applicable.

Demo

Set the parameter IsBottom value is true menu bar at the bottom of the container, for the mover

Demo

For simple website apps, set the menu icon by setting the menu item the Icon property of the MenuItem

Demo

For sites with left and right structure layouts, change the navigation menu to sidebar by setting

Demo

Set the menu icon by setting the menu item the Icon property of the MenuItem

Demo

Set the accordion effect sidebar menu by setting the IsAccordion property

Demo

Set the sidebar menu to the put-away state by setting the IsCollapsed property

Demo

In this example, the layout component Layout is used to build a web page, set the SideWith'0' turn off the sidebar width setting, and use the internal menu width from fit

I am the title of the website
Main

Set the custom component into the menu by setting the Component property of the MenuItem

Demo

Set whether the node is receding by setting the IsCollapsed property of the MenuItem

Demo

In this example, the permission settings node is expanded and the remaining nodes are in the recess state

Change the menu item by dynamically setting Theitems property values

Demo

Set whether the node is disabled by setting the IsDisabled property of the MenuItem

Demo

In this example navigation two node is disabled and the menu and its submenu are not clickable

Example of a disablement of the sidebar

Attributes

Loading...
@page "/menus"
@inject IOptions<WebsiteOptions> WebsiteOption

<h3>@Localizer["Title"]</h3>

<h4>@Localizer["H1"]</h4>

<Tips class="mt-3">
    <p>@((MarkupString)Localizer["Tips1"].Value)</p>
</Tips>

<Block Title="@Localizer["Block1Title"]" Introduction="@Localizer["Block1Intro"]">
    <Menu Items="@Items" DisableNavigation="true" OnClick="@OnClickMenu" />
    <BlockLogger @ref="Trace" class="mt-3" />
</Block>

<Block Title="@Localizer["Block2Title"]" Introduction="@Localizer["Block2Intro"]">
    <Tips>
        <div>@((MarkupString)Localizer["Tips2"].Value)</div>
    </Tips>
    <div style="height: 120px">
        <div>@ClickedMenuItemText</div>
        <Menu Items="@BottomItems" DisableNavigation="true" OnClick="@OnClickBottomMenu" IsBottom="true" />
    </div>
</Block>

<Block Title="@Localizer["Block3Title"]" Introduction="@Localizer["Block3Intro"]">
    <Menu Items="@IconItems" DisableNavigation="true" />
</Block>

<Block Title="@Localizer["Block4Title"]" Introduction="@Localizer["Block4Intro"]">
    <div style="width:220px; border-right: 1px solid #e6e6e6; padding-right: 4px;">
        <Menu Items="@SideMenuItems" DisableNavigation="true" IsVertical="true" OnClick="@OnClickSideMenu" />
    </div>
    <BlockLogger @ref="TraceSideMenu" class="mt-3" />
</Block>

<Block Title="@Localizer["Block5Title"]" Introduction="@Localizer["Block5Intro"]">
    <div style="width:220px;">
        <Menu Items="@IconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</Block>

<Block Title="@Localizer["Block6Title"]" Introduction="@Localizer["Block6Intro"]">
    <div style="width:220px;">
        <Menu Items="@IconSideMenuItems" DisableNavigation="true" IsVertical="true" IsAccordion="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</Block>

<Block Title="@Localizer["Block7Title"]" Introduction="@Localizer["Block7Intro"]">
    <Alert ShowBar="true">@Localizer["AlertText"]</Alert>
    <p>@((MarkupString)Localizer["P1"].Value)</p>
    <Layout SideWidth="0" IsFullSide="true" ShowFooter="true">
        <Header>
            <div class="d-flex align-items-center ps-3" style="background-color: #17a2b8; height: 50px; color: #fff;">
                <a style="padding: 4px 12px; color: #fff; background-color: #1ab394; border-color: #1ab394; border-radius: 4px;" class="@ClassString" title="@Localizer["Block7aTitle"]" @onclick="@CollapseMenu">
                    <i class="fa fa-bars"></i>
                </a>
                <span class="ms-3">@Localizer["Block7Span"]</span>
            </div>
        </Header>
        <Side>
            <div class="menu-demo" style="background-color: #2f4050; color: #dcdfe6; height: 100%; padding: 6px 0;">
                <Menu Items="@IconSideMenuItems" DisableNavigation="true" IsVertical="true" IsCollapsed="@IsCollapsed" />
            </div>
        </Side>
        <Main>
            <div style="padding: 10rem 1rem;">Main</div>
        </Main>
        <Footer>
            <div class="d-flex justify-content-center align-items-center" style="height: 30px; color: #fff; background-color: #5b6e84;"><a href="@WebsiteOption.Value.BootstrapAdminLink" target="_blank" style="color: #fff;">Bootstrap Admin</a></div>
        </Footer>
    </Layout>
</Block>

<Block Title="@Localizer["Block8Title"]" Introduction="@Localizer["Block8Intro"]">
    <div style="width:220px;">
        <Menu Items="@WidgetIconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</Block>

<Block Title="@Localizer["Block9Title"]" Introduction="@Localizer["Block9Intro"]">
    <p>@((MarkupString)Localizer["P2"].Value)</p>
    <div style="width:220px;">
        <Menu Items="@CollapsedIconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</Block>

<Block Title="@Localizer["Block10Title"]" Introduction="@Localizer["Block10Intro"]">
    <div class="mt-3" style="width:220px;">
        <Menu Items="@DynamicSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
    <Button Text="@Localizer["Block10Button1"]" OnClick="UpdateMenu" />
    <Button Text="@Localizer["Block10Button2"]" OnClick="ResetMenu" />
</Block>

<Block Title="@Localizer["Block11Title"]" Introduction="@Localizer["Block11Intro"]">
    <p>@((MarkupString)Localizer["P3"].Value)</p>
    <Menu Items="@DisabledMenuItems" DisableNavigation="true" OnClick="@OnClick2" />
    <p class="mt-3"><b>@Localizer["b1"]</b></p>
    <div style="width:220px; border-right: 1px solid #e6e6e6;">
        <Menu Items="@DisabledMenuItems" DisableNavigation="true" IsVertical="true" OnClick="@OnClick2" />
    </div>
    <BlockLogger @ref="Trace2" class="mt-3" />
</Block>

<AttributeTable Items="@GetAttributes()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using BootstrapBlazor.Components;
using BootstrapBlazor.Shared.Common;
using BootstrapBlazor.Shared.Pages.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace BootstrapBlazor.Shared.Pages
{
    /// <summary>
    /// 
    /// </summary>
    public sealed partial class Menus
    {
        [NotNull]
        private BlockLogger? Trace { get; set; }

        [NotNull]
        private BlockLogger? Trace2 { get; set; }

        [NotNull]
        private BlockLogger? TraceSideMenu { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? Items { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? BottomItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? IconItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? SideMenuItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? IconSideMenuItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? WidgetIconSideMenuItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? CollapsedIconSideMenuItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? DisabledMenuItems { get; set; }

        [NotNull]
        private IEnumerable<MenuItem>? DynamicSideMenuItems { get; set; }

        [Inject]
        [NotNull]
        private IStringLocalizer<Menus>? Localizer { get; set; }

        private Task OnClickMenu(MenuItem item)
        {
            Trace.Log($"菜单点击项: {item.Text}");
            return Task.CompletedTask;
        }

        private string? ClickedMenuItemText { get; set; }

        private Task OnClickBottomMenu(MenuItem item)
        {
            ClickedMenuItemText = item.Text;
            StateHasChanged();
            return Task.CompletedTask;
        }

        private Task OnClick2(MenuItem item)
        {
            Trace2.Log($"菜单点击项: {item.Text}");
            return Task.CompletedTask;
        }

        private Task OnClickSideMenu(MenuItem item)
        {
            TraceSideMenu?.Log($"菜单点击项: {item.Text}");
            return Task.CompletedTask;
        }

        private bool IsCollapsed { get; set; }

        private string? ClassString => CssBuilder.Default("menu-demo-bar")
            .AddClass("is-collapsed", IsCollapsed)
            .Build();

        private Task CollapseMenu()
        {
            IsCollapsed = !IsCollapsed;
            return Task.CompletedTask;
        }

        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();
            Items = await MenusDataGerator.GetTopItemsAsync(Localizer);
            IconItems = await MenusDataGerator.GetTopIconItemsAsync(Localizer);
            SideMenuItems = await MenusDataGerator.GetSideMenuItemsAsync(Localizer);
            IconSideMenuItems = await MenusDataGerator.GetIconSideMenuItemsAsync(Localizer);
            WidgetIconSideMenuItems = await MenusDataGerator.GetWidgetIconSideMenuItemsAsync(Localizer);
            CollapsedIconSideMenuItems = await MenusDataGerator.GetCollapsedIconSideMenuItemsAsync(Localizer);
            DisabledMenuItems = await MenusDataGerator.GetDisabledMenuItemsAsync(Localizer);
            DynamicSideMenuItems = await MenusDataGerator.GetSideMenuItemsAsync(Localizer);
            BottomItems = await MenusDataGerator.GetBottomMenuItemsAsync(Localizer);
        }

        private async Task UpdateMenu()
        {
            DynamicSideMenuItems = await MenusDataGerator.GetIconSideMenuItemsAsync(Localizer);
        }

        private async Task ResetMenu()
        {
            DynamicSideMenuItems = await MenusDataGerator.GetSideMenuItemsAsync(Localizer);
        }

        private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
        {
            new AttributeItem()
            {
                Name = "Items",
                Description = Localizer["Desc1"]!,
                Type = "IEnumerable<MenuItem>",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem()
            {
                Name = "IsVertical",
                Description = Localizer["Desc2"]!,
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "false"
            },
            new AttributeItem()
            {
                Name = "IsBottom",
                Description = Localizer["Desc3"]!,
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "false"
            },
            new AttributeItem() {
                Name = "IsAccordion",
                Description = Localizer["Desc4"]!,
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "false"
            },
            new AttributeItem() {
                Name = "DisableNavigation",
                Description = Localizer["Desc5"]!,
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "false"
            },
            new AttributeItem() {
                Name = "OnClick",
                Description = Localizer["Desc6"]!,
                Type = "Func<MenuItem, Task>",
                ValueList = " — ",
                DefaultValue = " — "
            }
        };

        internal static class MenusDataGerator
        {
            public static async Task<IEnumerable<MenuItem>> GetTopItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);

                return new List<MenuItem>
                {
                    new(localizer["Menu1"].Value),
                    new(localizer["Menu2"].Value)
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu1"].Value)
                            {
                                Items = new List<MenuItem>
                                {
                                    new(localizer["SubMenu11"].Value),
                                    new(localizer["SubMenu12"].Value)
                                }
                            },
                            new(localizer["SubMenu2"].Value)
                            {
                                Items = new List<MenuItem>
                                {
                                    new(localizer["SubMenu21"].Value),
                                    new(localizer["SubMenu22"].Value)
                                    {
                                        Items = new List<MenuItem>
                                        {
                                            new(localizer["SubMenu31"].Value),
                                            new(localizer["SubMenu32"].Value)
                                            {
                                                Items = new List<MenuItem>
                                                {
                                                    new(localizer["SubMenu41"].Value),
                                                    new(localizer["SubMenu42"].Value)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            new(localizer["SubMenu3"].Value)
                        }
                    },
                    new(localizer["Menu3"].Value)
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetBottomMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);

                return new List<MenuItem>
                {
                    new(localizer["Menu1"].Value),
                    new(localizer["Menu2"].Value)
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu1"].Value),
                            new(localizer["SubMenu2"].Value),
                            new(localizer["SubMenu3"].Value)
                        }
                    },
                    new(localizer["Menu3"].Value)
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetTopIconItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);
                return new List<MenuItem>
                {
                    new(localizer["Menu1"].Value, icon:"fa fa-life-bouy"),
                    new(localizer["Menu2"].Value, icon:"fa fa-fa")
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu1"].Value, icon:"fa fa-fa"),
                            new(localizer["SubMenu2"].Value, icon:"fa fa-fa"),
                            new(localizer["SubMenu3"].Value, icon:"fa fa-fa"),
                        }
                    },
                    new(localizer["Menu3"].Value, icon:"fa fa-rebel fa-fw")
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetSideMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);

                return new List<MenuItem>
                {
                    new(localizer["Menu1"].Value, icon: "fa fa-fa"),
                    new(localizer["Menu2"].Value)
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu1"].Value)
                            {
                                Items = new List<MenuItem>
                                {
                                    new(localizer["SubMenu11"].Value),
                                    new(localizer["SubMenu12"].Value)
                                }
                            },
                            new(localizer["SubMenu2"].Value)
                            {
                                Items = new List<MenuItem>
                                {
                                    new(localizer["SubMenu21"].Value),
                                    new(localizer["SubMenu22"].Value)
                                    {
                                        Items = new List<MenuItem>
                                        {
                                            new(localizer["SubMenu31"].Value),
                                            new(localizer["SubMenu32"].Value)
                                            {
                                                Items = new List<MenuItem>
                                                {
                                                    new(localizer["SubMenu41"].Value),
                                                    new(localizer["SubMenu42"].Value)
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            new(localizer["SubMenu3"].Value)
                        }
                    },
                    new(localizer["Menu3"].Value)
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetDisabledMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);
                return new List<MenuItem>
                {
                    new(localizer["Menu1"].Value)
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu1"].Value)
                        }
                    },
                    new(localizer["Menu2"].Value)
                    {
                        IsDisabled = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu2"].Value)
                        }
                    },
                    new(localizer["Menu3"].Value)
                    {
                        Items = new List<MenuItem>
                        {
                            new(localizer["SubMenu3"].Value)
                        }
                    }
                };
            }

            private static BootstrapDynamicComponent BuildDynamicComponent() => BootstrapDynamicComponent.CreateComponent<Badge>(new KeyValuePair<string, object>[]
            {
                new(nameof(Badge.Color), Color.Danger),
                new(nameof(Badge.IsPill), true),
                new(nameof(Badge.ChildContent), new RenderFragment(builder =>
                {
                    var index = 0;
                    builder.AddContent(index++, "10");
                }))
            });

            public static async Task<IEnumerable<MenuItem>> GetIconSideMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);
                return new List<MenuItem>
                {
                    new(localizer["System"].Value, icon: "fa fa-gears")
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["Website"].Value, icon: "fa fa-fa"),
                            new(localizer["Task"].Value, icon: "fa fa-tasks")
                        }
                    },
                    new(localizer["Authorize"].Value, icon: "fa fa-users")
                    {
                        Items = new List<MenuItem>
                        {
                            new(localizer["User"].Value, icon: "fa fa-user"),
                            new(localizer["Menu"].Value, icon: "fa fa-dashboard"),
                            new(localizer["Role"].Value, icon: "fa fa-sitemap")
                        }
                    },
                    new(localizer["Log"].Value, icon: "fa fa-database")
                    {
                        Items = new List<MenuItem>
                        {
                            new(localizer["Access"].Value, icon: "fa fa-bars"),
                            new(localizer["Login"].Value, icon: "fa fa-user-circle-o"),
                            new(localizer["Operation"].Value, icon: "fa fa-edit")
                        }
                    }
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetWidgetIconSideMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);
                return new List<MenuItem>
                {
                    new(localizer["System"].Value, icon: "fa fa-gears")
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["Website"].Value, icon: "fa fa-fa"),
                            new(localizer["Task"].Value, icon: "fa fa-tasks")
                        }
                    },
                    new(localizer["Authorize"].Value, icon: "fa fa-users")
                    {
                        Items = new List<MenuItem>
                        {
                            new(localizer["User"].Value, icon: "fa fa-user"),
                            new(localizer["Menu"].Value, icon: "fa fa-dashboard"),
                            new(localizer["Role"].Value, icon: "fa fa-sitemap")
                        }
                    },
                    new(localizer["Log"].Value, icon: "fa fa-database")
                    {
                        Component = BuildDynamicComponent(),
                        Items = new List<MenuItem>
                        {
                            new(localizer["Access"].Value, icon: "fa fa-bars"),
                            new(localizer["Login"].Value, icon: "fa fa-user-circle-o"),
                            new(localizer["Operation"].Value, icon: "fa fa-edit")
                            {
                                Component = BuildDynamicComponent()
                            }
                        }
                    }
                };
            }

            public static async Task<IEnumerable<MenuItem>> GetCollapsedIconSideMenuItemsAsync(IStringLocalizer localizer)
            {
                await Task.Delay(1);
                return new List<MenuItem>
                {
                    new(localizer["System"].Value, icon: "fa fa-gears")
                    {
                        IsActive = true,
                        Items = new List<MenuItem>
                        {
                            new(localizer["Website"].Value, icon: "fa fa-fa"),
                            new(localizer["Task"].Value, icon: "fa fa-tasks")
                        }
                    },
                    new(localizer["Authorize"].Value, icon: "fa fa-users")
                    {
                        IsCollapsed = false,
                        Items = new List<MenuItem>
                        {
                            new(localizer["User"].Value, icon: "fa fa-user"),
                            new(localizer["Menu"].Value, icon: "fa fa-dashboard"),
                            new(localizer["Role"].Value, icon: "fa fa-sitemap")
                        }
                    },
                    new(localizer["Log"].Value, icon: "fa fa-database")
                    {
                        Items = new List<MenuItem>
                        {
                            new(localizer["Access"].Value, icon: "fa fa-bars"),
                            new(localizer["Login"].Value, icon: "fa fa-user-circle-o"),
                            new(localizer["Operation"].Value, icon: "fa fa-edit")
                        }
                    }
                };
            }
        }
    }
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915( Full) 675147445 Welcome to join the group discussion
Themes
Bootstrap
Ant Design (完善中)
Bluma (完善中)
LayUI (完善中)
Motronic (已集成)
An error has occurred. This application may no longer respond until reloaded. Reload