Enterprise-level component library based on Bootstrap and Blazor
gitee
version
license
download
repo
commit
build
coverage

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

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 settingsnode 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 theMenuItem

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 IOptionsMonitor<WebsiteOptions> WebsiteOption

<h3>Menu</h3>

<h4>A list of menus that provide navigation for pages and features.</h4>

<Tips class="mt-3">
    <p><code>Menu</code> component is generally used for menu navigation, i.e. redirect navigation by clicking on the address bar after the menu, but sometimes you don't need navigation in real life, by setting <code>OnClick</code> callback delegate, custom processing logic, at this point by setting Property <code>The</code> of TheableNavigation, in this case all <code>Menu</code> are set to <code>true</code> disable navigation because they are analog menu clicks and do not actually navigate the address bar</p>
</Tips>

<DemoBlock Title="Top bar" Introduction="A wide range of basic usages are applicable." Name="TopBar">
    <Menu Items="@Items" DisableNavigation="true" OnClick="@OnClickMenu" />
    <BlockLogger @ref="Trace" class="mt-3" />
</DemoBlock>

<DemoBlock Title="Bottom bar" Introduction="Set the parameter <code>IsBottom</code> value is <b>true</b> menu bar at the bottom of the container, for the mover" Name="BottomBar">
    <Tips>
        <div>Because the <b>bottom bar menu</b> is relatively positioned relative to the parent container, you need to set the parent node style <code>position-</code>, or customize the style <code>theposition-fixed</code></div>
    </Tips>
    <div style="height: 120px; position: relative;">
        <div>@ClickedMenuItemText</div>
        <Menu Items="@BottomItems" DisableNavigation="true" OnClick="@OnClickBottomMenu" IsBottom="true" />
    </div>
</DemoBlock>

<DemoBlock Title="Top bar menu with icon" Introduction="For simple website apps, set the menu icon by setting the menu item <code>the <code>Icon</code> property of the MenuItem</code>" Name="IconTop">
    <Menu Items="@IconItems" DisableNavigation="true" />
</DemoBlock>

<DemoBlock Title="Sidebar" Introduction="For sites with left and right structure layouts, change the navigation menu to sidebar by setting <code></code>" Name="LeftRightLayout">
    <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" />
</DemoBlock>

<DemoBlock Title="Sidebar menu with icon" Introduction="Set the menu icon by setting the menu item <code>the <code>Icon</code> property of the MenuItem</code>" Name="IconLeft">
    <div style="width:220px;">
        <Menu Items="@IconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</DemoBlock>

<DemoBlock Title="Sidebar for accordion effects" Introduction="Set the accordion effect sidebar menu by setting the <code>IsAccordion</code> property" Name="Accordion">
    <div style="width:220px;">
        <Menu Items="@IconSideMenuItems" DisableNavigation="true" IsVertical="true" IsAccordion="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</DemoBlock>

<DemoBlock Title="Sidebar effect with shrink" Introduction="Set the sidebar menu to the put-away state by setting the <code>IsCollapsed</code> property" Name="ClickShrink">
    <Tips>
        <p>@(new MarkupString(Localizer["AlertText"].Value))</p>
    </Tips>
    <p>In this example, the layout component <code>Layout</code> is used to build a web page, set the <code>SideWith'0'</code> turn off the sidebar width setting, and use the internal menu width from fit</p>
    <Layout SideWidth="0" IsFullSide="true" ShowFooter="true" ShowCollapseBar="true" class="layout-menu-demo"
            Menus="IconSideMenuItems">
        <Header>
            <div class="menu-demo-header">
                I am the title of the website
            </div>
        </Header>
        <Side>
            <div class="layout-banner">
                <img class="layout-logo" src="_content/BootstrapBlazor.Shared/images/logo.png" />
                <div class="layout-title">
                    <span>后台管理</span>
                </div>
            </div>
        </Side>
        <Main>
            <div style="padding: 10rem 1rem;">Main</div>
        </Main>
        <Footer>
            <a href="@WebsiteOption.CurrentValue.BootstrapAdminLink" target="_blank">Bootstrap Admin</a>
        </Footer>
    </Layout>
</DemoBlock>

<DemoBlock Title="Menu with pendant" Introduction="Set the custom component into the menu by setting the <code>Component</code> property of the MenuItem</code> <code>" Name="Wiget">
    <div style="width:220px;">
        <Menu Items="@WidgetIconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</DemoBlock>

<DemoBlock Title="Custom node shrinkage" Introduction="Set whether the node is receding by setting the <code>IsCollapsed</code> property of the <code>MenuItem</code>" Name="CustomNode">
    <p>In this example, the <b>permission settings</b>node is expanded and the remaining nodes are in the recess state</p>
    <div style="width:220px;">
        <Menu Items="@CollapsedIconSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
</DemoBlock>

<DemoBlock Title="Dynamically change the menu" Introduction="Change the menu item by dynamically setting <code>Theitems</code> property values" Name="Dynamic">
    <div class="mt-3" style="width:220px;">
        <Menu Items="@DynamicSideMenuItems" DisableNavigation="true" IsVertical="true" style="border-right: 1px solid #e6e6e6;" />
    </div>
    <Button Text="Update the menu" OnClick="UpdateMenu" />
    <Button Text="Reset the menu" OnClick="ResetMenu" />
</DemoBlock>

<DemoBlock Title="Some menus disable functionality" Introduction="Set whether the node is disabled by setting the <code>IsDisabled</code> property of the</code>MenuItem<code>" Name="PartDisable">
    <p>In this example <b>navigation two</b> node is disabled and the menu and its submenu are not clickable</p>
    <Menu Items="@DisabledMenuItems" DisableNavigation="true" OnClick="@OnClick2" />
    <p class="mt-3"><b>Example of a disablement of the sidebar</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" />
</DemoBlock>

<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.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;

namespace BootstrapBlazor.Shared.Samples;

/// <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;
    }

    /// <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 = " — "
        }
    };
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
Themes
Bootstrap
Motronic
Ant Design (完善中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload
Seems like the connection with the server has been lost. It can be due to poor or broken network. Please hang on while we're trying to reconnect...
Oh snap! Failed to reconnect with the server. This is typically caused by a longer network outage, or if the server has been taken down. You can try to reconnect, but if that does not work, you need to reload the page.
Oh man! The server rejected the attempt to reconnect. The only option now is to reload the page, but be prepared that it won't work, since this is typically caused by a failure on the server.
Bootstrap Blazor 组件库 更新到 6.6.0

首先感谢您对本套组件的关注,本目前本套组件已经拥有超过 120 个组件,本组件是基于 Bootstrap 风格的 Blazor 企业级组件库,提供如布局、导航、表单、数据、通知、图标、语音等几大类通用组件,每一个组件都经过静心设计,具有模块化、响应式和优秀的性能。从更多实际场景出发,满足多种场景的需求,极大的减少开发者时间成本,大大缩短开发周期,大幅提高开发效率,并提供了一套 通用权限管理系统 示例工程。Bootstrap Blazor 产品是由一支专业的全职技术团队进行维护,高效的响应速度,多元化的解决方案,长期提供支持,并提供企业级支持。目前已在多家知名国企内部使用,项目最高在线 1200 人稳定运行。右侧为国内人数最多的中文 Blazor QQ 社区二维码,欢迎扫描加群。

组件更新到 6.6.0 更新日志 [传送门] 如果组件给您带来了方便,请您帮忙给项目点亮 Star github gitee

QQGroup
QQ 795206915