Enterprise-level component library based on Bootstrap and Blazor

star nuget master download license repo commit

Modal 模态框

在保留当前页面状态的情况下,告知用户并承载相关操作

弹出一个对话框,适合需要定制性更大的场景

Demo

通过设置 Modal 组件的 IsKeyboard 参数,开启弹窗是否支持 ESC,请点击后面按钮设置后再点击 弹窗 按钮测试效果

点击弹窗以外区域默认关闭弹窗效果

Demo

通过 Size 设置弹框组件的大小

Demo

通过 IsCentered 设置弹框组件的垂直居中

Demo

通过 IsScrolling 针对超出内容设置弹框组件滚轮滑动功能

Demo

点击弹窗标题栏对弹窗进行拖拽

Demo

Attributes

Loading...
@page "/modals"

<h3>Modal 模态框</h3>

<h4>在保留当前页面状态的情况下,告知用户并承载相关操作</h4>

<Block Title="基本用法" Introduction="弹出一个对话框,适合需要定制性更大的场景">
    <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title">弹窗标题</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
            <p>弹窗正文</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary">保存</button>
        </div>
    </div>
    <div class="mt-3">
        <p>通过设置 <code>Modal</code> 组件的 <code>IsKeyboard</code> 参数,开启弹窗是否支持 <kbd>ESC</kbd>,请点击后面按钮设置后再点击 <b>弹窗</b> 按钮测试效果</p>
        <Button OnClick="async e => await Modal.Toggle()">弹窗</Button>
        <Button OnClick="OnClickKeyboard" Text="@($"Keyboard: {IsKeyboard}")" class="ms-3" />
    </div>
    <Modal @ref="Modal" IsKeyboard="@IsKeyboard">
        <ModalDialog Title="默认弹窗">
            <BodyTemplate>
                <div>我是弹窗内正文</div>
            </BodyTemplate>
        </ModalDialog>
    </Modal>
</Block>

<Block Title="IsBackdrop 背景关闭模式" Introduction="点击弹窗以外区域默认关闭弹窗效果">
    <Button OnClick="@(async e => await BackdropModal.Toggle())">弹窗</Button>
    <Modal @ref="BackdropModal" IsBackdrop="true">
        <ModalDialog Title="点击背景可关闭弹窗">
            <BodyTemplate>
                <div>我是弹窗内正文</div>
            </BodyTemplate>
        </ModalDialog>
    </Modal>
</Block>

<Block Title="弹框大小" Introduction="通过 <code>Size</code> 设置弹框组件的大小">
    <div class="row g-3">
        <div class="col-12 col-sm-4 col-lg-auto">
            <Button OnClick="@(async e => await SmailModal.Toggle())">小弹窗</Button>
            <Modal @ref="SmailModal">
                <ModalDialog Size="Size.Small" Title="小弹窗">
                    <BodyTemplate>
                        <div>我是弹窗内正文</div>
                    </BodyTemplate>
                </ModalDialog>
            </Modal>
        </div>
        <div class="col-12 col-sm-4 col-lg-auto">
            <Button OnClick="@(async e => await LargeModal.Toggle())">大弹窗</Button>
            <Modal @ref="LargeModal">
                <ModalDialog Size="Size.Large" Title="大弹窗">
                    <BodyTemplate>
                        <div>我是弹窗内正文</div>
                    </BodyTemplate>
                </ModalDialog>
            </Modal>
        </div>
        <div class="col-12 col-sm-4 col-lg-auto">
            <Button OnClick="@(async e => await ExtraLargeModal.Toggle())">超大弹窗</Button>
            <Modal @ref="ExtraLargeModal">
                <ModalDialog Size="Size.ExtraLarge" Title="超大弹窗">
                    <BodyTemplate>
                        <div>我是弹窗内正文</div>
                    </BodyTemplate>
                </ModalDialog>
            </Modal>
        </div>
    </div>
</Block>

<Block Title="垂直居中" Introduction="通过 <code>IsCentered</code> 设置弹框组件的垂直居中">
    <Button OnClick="@(async e => await CenterModal.Toggle())">垂直居中的弹窗</Button>
    <Modal @ref="CenterModal">
        <ModalDialog IsCentered="true" Title="垂直居中的弹窗">
            <BodyTemplate>
                <div>我是弹窗内正文</div>
            </BodyTemplate>
        </ModalDialog>
    </Modal>
</Block>

<Block Title="超长内容" Introduction="通过 <code>IsScrolling</code> 针对超出内容设置弹框组件滚轮滑动功能">
    <div class="row g-3">
        <div class="col-12 col-sm-4 col-lg-auto">
            <Button OnClick="@(async e => await LongContentModal.Toggle())">内容超长的弹窗</Button>
            <Modal @ref="LongContentModal">
                <ModalDialog IsCentered="true" Title="内容超长的弹窗">
                    <BodyTemplate>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                    </BodyTemplate>
                </ModalDialog>
            </Modal>
        </div>
        <div class="col-12 col-sm-4 col-lg-auto">
            <Button OnClick="@(async e => await ScrollModal.Toggle())">内置滚动条弹窗</Button>
            <Modal @ref="ScrollModal">
                <ModalDialog IsCentered="true" IsScrolling="true" Title="内置滚动条弹窗">
                    <BodyTemplate>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                        <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
                        <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
                        <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
                    </BodyTemplate>
                </ModalDialog>
            </Modal>
        </div>
    </div>
</Block>

<Block Title="可拖拽弹窗" Introduction="点击弹窗标题栏对弹窗进行拖拽">
    <Button OnClick="@(async e => await DragModal.Toggle())">弹窗</Button>
    <Modal @ref="DragModal">
        <ModalDialog Title="默认弹窗" IsDraggable="true">
            <BodyTemplate>
                <div>我是弹窗内正文</div>
            </BodyTemplate>
        </ModalDialog>
    </Modal>
</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 System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

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

        [NotNull]
        private Modal? BackdropModal { get; set; }

        [NotNull]
        private Modal? SmailModal { get; set; }

        [NotNull]
        private Modal? LargeModal { get; set; }

        [NotNull]
        private Modal? ExtraLargeModal { get; set; }

        [NotNull]
        private Modal? CenterModal { get; set; }

        [NotNull]
        private Modal? LongContentModal { get; set; }

        [NotNull]
        private Modal? ScrollModal { get; set; }

        [NotNull]
        private Modal? DragModal { get; set; }

        private bool IsKeyboard { get; set; }

        private void OnClickKeyboard()
        {
            IsKeyboard = !IsKeyboard;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private static IEnumerable<AttributeItem> GetAttributes()
        {
            return new AttributeItem[]
            {
                new AttributeItem() {
                    Name = "HeaderTemplate",
                    Description = "模态主体 ModalHeader 模板",
                    Type = "RenderFragment",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem() {
                    Name = "BodyTemplate",
                    Description = "模态主体 ModalBody 组件",
                    Type = "RenderFragment",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem() {
                    Name = "ChildContent",
                    Description = "内容",
                    Type = "RenderFragment",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem() {
                    Name = "FooterTemplate",
                    Description = "模态底部 ModalFooter 组件",
                    Type = "RenderFragment",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem() {
                    Name = "IsBackdrop",
                    Description = "是否后台关闭弹窗",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "IsKeyboard",
                    Description = "是否响应 ESC 键盘",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "true"
                },
                new AttributeItem() {
                    Name = "IsCentered",
                    Description = "是否垂直居中",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "true"
                },
                new AttributeItem() {
                    Name = "IsScrolling",
                    Description = "是否弹窗正文超长时滚动",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "IsFade",
                    Description = "是否开启淡入淡出动画效果",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "true"
                },
                new AttributeItem() {
                    Name = "IsDraggable",
                    Description = "是否开启可拖拽效果",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "ShowCloseButton",
                    Description = "是否显示关闭按钮",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "true"
                },
                new AttributeItem() {
                    Name = "ShowFooter",
                    Description = "是否显示 Footer",
                    Type = "boolean",
                    ValueList = " — ",
                    DefaultValue = "true"
                },
                new AttributeItem() {
                    Name = "Size",
                    Description = "尺寸",
                    Type = "Size",
                    ValueList = "None / ExtraSmall / Small / Medium / Large / ExtraLarge",
                    DefaultValue = "Large"
                },
                new AttributeItem() {
                    Name = "Title",
                    Description = "弹窗标题",
                    Type = "string",
                    ValueList = " — ",
                    DefaultValue = " 未设置 "
                },
            };
        }
    }
}

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