Enterprise-level component library based on Bootstrap and Blazor

star nuget master download license repo commit

Modal 模态框

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

基本用法

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

Demo

IsBackdrop 背景关闭模式

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

Demo

弹框大小

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

Demo

垂直居中

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

Demo

超长内容

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

Demo

多级弹窗

点击弹窗内部按钮继续弹出模态窗

Demo

可拖拽弹窗

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

Demo

Attributes

Loading...
@page "/modals"

<h3>Modal 模态框</h3>

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

<Block Title="基本用法" Introduction="弹出一个对话框,适合需要定制性更大的场景">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">弹窗标题</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p>弹窗正文</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary">保存</button>
                    </div>
                </div>
            </div>
            <div class="form-group col-12">
                <Button @onclick="@(e => Modal.Toggle())">弹窗</Button>
                <Modal @ref="Modal">
                    <ModalDialog Title="默认弹窗">
                        <BodyTemplate>
                            <div>我是弹窗内正文</div>
                        </BodyTemplate>
                    </ModalDialog>
                </Modal>
            </div>
        </div>
    </div>
</Block>

<Block Title="IsBackdrop 背景关闭模式" Introduction="点击弹窗以外区域默认关闭弹窗效果">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <Button @onclick="@(e => BackdropModal.Toggle())">弹窗</Button>
                <Modal @ref="BackdropModal" IsBackdrop="true">
                    <ModalDialog Title="点击背景可关闭弹窗">
                        <BodyTemplate>
                            <div>我是弹窗内正文</div>
                        </BodyTemplate>
                    </ModalDialog>
                </Modal>
            </div>
        </div>
    </div>
</Block>

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

<Block Title="垂直居中" Introduction="通过 <code>IsCentered</code> 设置弹框组件的垂直居中">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12 col-sm-4 col-lg-auto">
                <Button @onclick="@(e => CenterModal.Toggle())">垂直居中的弹窗</Button>
                <Modal @ref="CenterModal">
                    <ModalDialog IsCentered="true" Title="垂直居中的弹窗">
                        <BodyTemplate>
                            <div>我是弹窗内正文</div>
                        </BodyTemplate>
                    </ModalDialog>
                </Modal>
            </div>
        </div>
    </div>
</Block>

<Block Title="超长内容" Introduction="通过 <code>IsScrolling</code> 针对超出内容设置弹框组件滚轮滑动功能">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12 col-sm-4 col-lg-auto">
                <Button @onclick="@(e => 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="form-group col-12 col-sm-4 col-lg-auto">
                <Button @onclick="@(e => 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>
    </div>
</Block>

<Block Title="多级弹窗" Introduction="点击弹窗内部按钮继续弹出模态窗">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <button class="btn btn-primary" @onclick="@(e => CascadeModal.Toggle())">弹窗</button>
                <Modal @ref="CascadeModal">
                    <ModalDialog @ref="Dialog1" Title="内部按钮继续弹窗">
                        <BodyTemplate>
                            <div>我是第一个弹窗,点击下面按钮继续弹出第二个弹窗</div>
                        </BodyTemplate>
                        <FooterTemplate>
                            <Button @onclick="e => Dialog2?.Show()">继续弹第二个弹窗</Button>
                        </FooterTemplate>
                    </ModalDialog>
                    <ModalDialog @ref="Dialog2" Title="第二个弹窗">
                        <BodyTemplate>
                            <div>我是第二个弹窗,点击下面按钮继续弹出第三个弹窗</div>
                        </BodyTemplate>
                        <FooterTemplate>
                            <Button @onclick="e => Dialog1?.Show()">返回第一个弹窗</Button>
                            <Button Color="Color.Success" @onclick="e => Dialog3?.Show()">继续弹第三个弹窗</Button>
                        </FooterTemplate>
                    </ModalDialog>
                    <ModalDialog @ref="Dialog3" Title="第三个弹窗">
                        <BodyTemplate>
                            <div>我是弹窗内正文,点击下面关闭按钮关闭弹窗</div>
                            <p>弹窗背景一直是透明的哦,不会变黑乎乎的哦</p>
                        </BodyTemplate>
                        <FooterTemplate>
                            <Button Color="Color.Info" @onclick="e => Dialog2?.Show()">返回第二个弹窗</Button>
                        </FooterTemplate>
                    </ModalDialog>
                </Modal>
            </div>
        </div>
    </div>
</Block>

<Block Title="可拖拽弹窗" Introduction="点击弹窗标题栏对弹窗进行拖拽">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <Button @onclick="@(e => Modal.Toggle())">弹窗</Button>
                <Modal @ref="Modal">
                    <ModalDialog Title="默认弹窗" IsDraggable="true">
                        <BodyTemplate>
                            <div>我是弹窗内正文</div>
                        </BodyTemplate>
                    </ModalDialog>
                </Modal>
            </div>
        </div>
    </div>
</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
    {
        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? Modal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? BackdropModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? SmailModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? LargeModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? ExtraLargeModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? CenterModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? LongContentModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? ScrollModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [NotNull]
        private Modal? CascadeModal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private ModalDialog? Dialog1 { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private ModalDialog? Dialog2 { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private ModalDialog? Dialog3 { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private static IEnumerable<AttributeItem> GetAttributes()
        {
            return new AttributeItem[]
            {
                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 = "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群: BootstrapAdmin & Blazor(795206915)欢迎加群讨论
An error has occurred. This application may no longer respond until reloaded. Reload