From 948b3504da43aace9600f34e726e75c3c82811f3 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 10:01:18 +0800 Subject: [PATCH 01/25] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=B3=A8=E9=87=8A=E4=B8=8E=E5=8F=82=E6=95=B0=E8=A7=84?= =?UTF-8?q?=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Toast/ToastService.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/Components/Toast/ToastService.cs b/src/BootstrapBlazor/Components/Toast/ToastService.cs index 8d8218630d2..976e864af57 100644 --- a/src/BootstrapBlazor/Components/Toast/ToastService.cs +++ b/src/BootstrapBlazor/Components/Toast/ToastService.cs @@ -7,9 +7,6 @@ namespace BootstrapBlazor.Components; /// /// Toast 弹出窗服务类 /// -/// -/// 构造方法 -/// /// public class ToastService(IOptionsMonitor options) : BootstrapServiceBase { @@ -17,13 +14,13 @@ public class ToastService(IOptionsMonitor options) : Boo /// Show 方法 /// /// - /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 - public async Task Show(ToastOption option, ToastContainer? ToastContainer = null) + /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 + public async Task Show(ToastOption option, ToastContainer? toastContainer = null) { if (!option.ForceDelay && options.CurrentValue.ToastDelay != 0) { option.Delay = options.CurrentValue.ToastDelay; } - await Invoke(option, ToastContainer); + await Invoke(option, toastContainer); } } From 1d1955fd798fd320117e7b3c8bdf7cde13e72a44 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 10:54:48 +0800 Subject: [PATCH 02/25] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs b/src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs index b0fbfa95d0c..2d9ca11cf72 100644 --- a/src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs +++ b/src/BootstrapBlazor/Components/Toast/ToastContainer.razor.cs @@ -76,7 +76,6 @@ private async Task Show(ToastOption option) } Toasts.Add(option); await InvokeAsync(StateHasChanged); - return; } /// From 1c60db7666608129ab051b28af4c1fae346d3c0a Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 10:55:07 +0800 Subject: [PATCH 03/25] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/Drawer.razor | 21 +---- .../Components/Drawer/Drawer.razor.cs | 34 ++++----- .../Components/Drawer/DrawerBody.razor | 18 +++++ .../Components/Drawer/DrawerBody.razor.cs | 50 ++++++++++++ .../Components/Drawer/DrawerContainer.razor | 11 +++ .../Drawer/DrawerContainer.razor.cs | 76 +++++++++++++++++++ .../Components/Drawer/DrawerOption.cs | 56 ++++++++++++++ .../Components/Drawer/DrawerService.cs | 18 +++++ 8 files changed, 246 insertions(+), 38 deletions(-) create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerBody.razor create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerOption.cs create mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerService.cs diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor b/src/BootstrapBlazor/Components/Drawer/Drawer.razor index 3c0a2c4a967..a62c67d8eba 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor @@ -3,22 +3,7 @@ @attribute [BootstrapModuleAutoLoader]
- @if (ShowBackdrop) - { -
-
- } -
-
- - @ChildContent - -
- @if (AllowResize) - { -
-
-
- } -
+ + +
diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index 65ee0fdf469..187a960f43b 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -17,24 +17,6 @@ public partial class Drawer .AddClassFromAttributes(AdditionalAttributes) .Build(); - /// - /// 获得 抽屉 Style 字符串 - /// - private string? DrawerStyleString => CssBuilder.Default() - .AddClass($"--bb-drawer-width: {Width};", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) - .AddClass($"--bb-drawer-height: {Height};", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) - .Build(); - - /// - /// 获得 抽屉样式 - /// - private string? DrawerClassString => CssBuilder.Default("drawer-body") - .AddClass("left", Placement != Placement.Right && Placement != Placement.Top && Placement != Placement.Bottom) - .AddClass("top", Placement == Placement.Top) - .AddClass("right", Placement == Placement.Right) - .AddClass("bottom", Placement == Placement.Bottom) - .Build(); - /// /// 获得/设置 抽屉宽度 左右布局时生效 /// @@ -110,6 +92,18 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } } + private DrawerOption GetOption() => new() + { + Height = Height, + Width = Width, + IsBackdrop = IsBackdrop, + ShowBackdrop = ShowBackdrop, + Placement = Placement, + AllowResize = AllowResize, + OnClickBackdrop = OnClickBackdrop, + ChildContent = ChildContent + }; + /// /// 点击背景遮罩方法 /// @@ -117,7 +111,7 @@ public async Task OnContainerClick() { if (IsBackdrop) { - await Close(); + await Close(GetOption()); if (OnClickBackdrop != null) await OnClickBackdrop.Invoke(); } } @@ -126,7 +120,7 @@ public async Task OnContainerClick() /// 关闭抽屉方法 ///
/// - public async Task Close() + public async Task Close(DrawerOption option) { IsOpen = false; if (IsOpenChanged.HasDelegate) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor new file mode 100644 index 00000000000..5d03d8bc21e --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor @@ -0,0 +1,18 @@ +@namespace BootstrapBlazor.Components +@inherits BootstrapComponentBase + +@if (Option.ShowBackdrop) +{ +
+} +
+
+ @Option.ChildContent +
+ @if (Option.AllowResize) + { +
+
+
+ } +
diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs new file mode 100644 index 00000000000..066ca6b463a --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs @@ -0,0 +1,50 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// DrawerBody 组件 +/// +public partial class DrawerBody +{ + /// + /// 获得/设置 实例 + /// + [Parameter, NotNull] + public DrawerOption? Option { get; set; } + + [CascadingParameter] + private Func? OnCloseAsync { get; set; } + + /// + /// 获得 抽屉 Style 字符串 + /// + private string? DrawerStyleString => CssBuilder.Default() + .AddClass($"--bb-drawer-width: {Option.Width};", !string.IsNullOrEmpty(Option.Width) && Option.Placement != Placement.Top && Option.Placement != Placement.Bottom) + .AddClass($"--bb-drawer-height: {Option.Height};", !string.IsNullOrEmpty(Option.Height) && (Option.Placement == Placement.Top || Option.Placement == Placement.Bottom)) + .Build(); + + /// + /// 获得 抽屉样式 + /// + private string? DrawerClassString => CssBuilder.Default("drawer-body") + .AddClass("left", Option.Placement != Placement.Right && Option.Placement != Placement.Top && Option.Placement != Placement.Bottom) + .AddClass("top", Option.Placement == Placement.Top) + .AddClass("right", Option.Placement == Placement.Right) + .AddClass("bottom", Option.Placement == Placement.Bottom) + .Build(); + + /// + /// 关闭抽屉方法 + /// + /// + public async Task Close() + { + if (OnCloseAsync != null) + { + await OnCloseAsync(Option); + } + } +} diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor new file mode 100644 index 00000000000..81ccfc71716 --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor @@ -0,0 +1,11 @@ +@namespace BootstrapBlazor.Components +@inherits BootstrapComponentBase + +
+ + @foreach (var option in _options) + { + + } + +
diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs new file mode 100644 index 00000000000..102df574287 --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs @@ -0,0 +1,76 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// Drawer 抽屉容器组件 +/// +public partial class DrawerContainer : IDisposable +{ + /// + /// 获得 弹出窗集合 + /// + private readonly List _options = []; + + [Inject] + [NotNull] + private DrawerService? DrawerService { get; set; } + + [Inject] + [NotNull] + private IOptionsMonitor? Options { get; set; } + + /// + /// OnInitialized 方法 + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + // 注册 Drawer 弹窗事件 + DrawerService.Register(this, Show); + } + + private async Task Show(DrawerOption option) + { + _options.Add(option); + await InvokeAsync(StateHasChanged); + } + + /// + /// 关闭弹窗 + /// + /// + public async Task Close(DrawerOption option) + { + if (option.OnCloseAsync != null) + { + await option.OnCloseAsync(); + } + _options.Remove(option); + StateHasChanged(); + } + + /// + /// Dispose 方法 + /// + /// + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + DrawerService.UnRegister(this); + } + } + + /// + /// Dispose 方法 + /// + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } +} diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs new file mode 100644 index 00000000000..d9338bb854d --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -0,0 +1,56 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// Toast 弹出窗参数配置类 +/// +public class DrawerOption : PopupOptionBase +{ + /// + /// 获得/设置 抽屉宽度 左右布局时生效 + /// + public string Width { get; set; } = "360px"; + + /// + /// 获得/设置 抽屉高度 上下布局时生效 + /// + public string Height { get; set; } = "290px"; + + /// + /// 获得/设置 点击遮罩是否关闭抽屉 默认为 false + /// + public bool IsBackdrop { get; set; } + + /// + /// 获得/设置 是否显示遮罩 默认为 true 显示遮罩 + /// + public bool ShowBackdrop { get; set; } = true; + + /// + /// 获得/设置 组件出现位置 默认显示在 Left 位置 + /// + public Placement Placement { get; set; } = Placement.Left; + + /// + /// 获得/设置 子组件 + /// + public RenderFragment? ChildContent { get; set; } + + /// + /// 获得/设置 是否允许调整大小 默认 false + /// + public bool AllowResize { get; set; } + + /// + /// 获得/设置 点击背景遮罩时回调委托方法 默认为 null + /// + public Func? OnClickBackdrop { get; set; } + + /// + /// 获得/设置 关闭当前 Drawer 回调委托 默认 null + /// + public Func? OnCloseAsync { get; set; } +} diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerService.cs b/src/BootstrapBlazor/Components/Drawer/DrawerService.cs new file mode 100644 index 00000000000..1d0a994ec91 --- /dev/null +++ b/src/BootstrapBlazor/Components/Drawer/DrawerService.cs @@ -0,0 +1,18 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// Toast 弹出窗服务类 +/// +public class DrawerService : BootstrapServiceBase +{ + /// + /// Show 方法 + /// + /// DrawerOption 实例 + /// 指定抽屉容器组件 默认为 null 使用 组件内置弹窗组件 + public Task Show(DrawerOption option, DrawerContainer? drawerContainer = null) => Invoke(option, drawerContainer); +} From 5b9e6806c33d1842dd2dd538df5e754d1cec5dc7 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 10:55:15 +0800 Subject: [PATCH 04/25] =?UTF-8?q?chore:=20=E5=86=85=E7=BD=AE=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/BootstrapBlazorServiceCollectionExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index 5ffc71db1e9..61bca7a58d6 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -74,6 +74,7 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); From 526ede1658f5c14cf8615f492111e5df9ad3cbb2 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 10:55:31 +0800 Subject: [PATCH 05/25] =?UTF-8?q?feat:=20=E6=A0=B9=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=8A=BD=E5=B1=89=E5=AE=B9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/BaseComponents/BootstrapBlazorRoot.razor | 1 + .../Components/BaseComponents/BootstrapBlazorRoot.razor.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor index 5508a1ff4ed..2ef7d868cc4 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor @@ -10,6 +10,7 @@ + diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor.cs b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor.cs index 60e001ee0c4..90f919f8f57 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor.cs +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapBlazorRoot.razor.cs @@ -32,7 +32,7 @@ public partial class BootstrapBlazorRoot public Message? MessageContainer { get; private set; } /// - /// 获得 Toast 组件实例 + /// 获得 ToastContainer 组件实例 /// [NotNull] public ToastContainer? ToastContainer { get; private set; } From 472033faadeef7afa4dd850442257a318d603a6d Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:03:55 +0800 Subject: [PATCH 06/25] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/DrawerBody.razor | 18 ------- .../Components/Drawer/DrawerBody.razor.cs | 50 ------------------- ...rContainer.razor.cs => DrawerContainer.cs} | 38 ++++++-------- .../Components/Drawer/DrawerContainer.razor | 11 ---- .../Components/Drawer/DrawerOption.cs | 4 +- 5 files changed, 17 insertions(+), 104 deletions(-) delete mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerBody.razor delete mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs rename src/BootstrapBlazor/Components/Drawer/{DrawerContainer.razor.cs => DrawerContainer.cs} (68%) delete mode 100644 src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor deleted file mode 100644 index 5d03d8bc21e..00000000000 --- a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor +++ /dev/null @@ -1,18 +0,0 @@ -@namespace BootstrapBlazor.Components -@inherits BootstrapComponentBase - -@if (Option.ShowBackdrop) -{ -
-} -
-
- @Option.ChildContent -
- @if (Option.AllowResize) - { -
-
-
- } -
diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs b/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs deleted file mode 100644 index 066ca6b463a..00000000000 --- a/src/BootstrapBlazor/Components/Drawer/DrawerBody.razor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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/ - -namespace BootstrapBlazor.Components; - -/// -/// DrawerBody 组件 -/// -public partial class DrawerBody -{ - /// - /// 获得/设置 实例 - /// - [Parameter, NotNull] - public DrawerOption? Option { get; set; } - - [CascadingParameter] - private Func? OnCloseAsync { get; set; } - - /// - /// 获得 抽屉 Style 字符串 - /// - private string? DrawerStyleString => CssBuilder.Default() - .AddClass($"--bb-drawer-width: {Option.Width};", !string.IsNullOrEmpty(Option.Width) && Option.Placement != Placement.Top && Option.Placement != Placement.Bottom) - .AddClass($"--bb-drawer-height: {Option.Height};", !string.IsNullOrEmpty(Option.Height) && (Option.Placement == Placement.Top || Option.Placement == Placement.Bottom)) - .Build(); - - /// - /// 获得 抽屉样式 - /// - private string? DrawerClassString => CssBuilder.Default("drawer-body") - .AddClass("left", Option.Placement != Placement.Right && Option.Placement != Placement.Top && Option.Placement != Placement.Bottom) - .AddClass("top", Option.Placement == Placement.Top) - .AddClass("right", Option.Placement == Placement.Right) - .AddClass("bottom", Option.Placement == Placement.Bottom) - .Build(); - - /// - /// 关闭抽屉方法 - /// - /// - public async Task Close() - { - if (OnCloseAsync != null) - { - await OnCloseAsync(Option); - } - } -} diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs similarity index 68% rename from src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs rename to src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index 102df574287..b36a00516eb 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -2,25 +2,20 @@ // 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 Microsoft.AspNetCore.Components.Rendering; + namespace BootstrapBlazor.Components; /// /// Drawer 抽屉容器组件 /// -public partial class DrawerContainer : IDisposable +public class DrawerContainer : ComponentBase, IDisposable { - /// - /// 获得 弹出窗集合 - /// - private readonly List _options = []; - [Inject] [NotNull] private DrawerService? DrawerService { get; set; } - [Inject] - [NotNull] - private IOptionsMonitor? Options { get; set; } + private DrawerOption? _option; /// /// OnInitialized 方法 @@ -33,24 +28,21 @@ protected override void OnInitialized() DrawerService.Register(this, Show); } - private async Task Show(DrawerOption option) + /// + /// + /// + /// + protected override void BuildRenderTree(RenderTreeBuilder builder) { - _options.Add(option); - await InvokeAsync(StateHasChanged); + builder.OpenComponent(0); + + builder.CloseComponent(); } - /// - /// 关闭弹窗 - /// - /// - public async Task Close(DrawerOption option) + private async Task Show(DrawerOption option) { - if (option.OnCloseAsync != null) - { - await option.OnCloseAsync(); - } - _options.Remove(option); - StateHasChanged(); + _option = option; + await InvokeAsync(StateHasChanged); } /// diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor deleted file mode 100644 index 81ccfc71716..00000000000 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.razor +++ /dev/null @@ -1,11 +0,0 @@ -@namespace BootstrapBlazor.Components -@inherits BootstrapComponentBase - -
- - @foreach (var option in _options) - { - - } - -
diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs index d9338bb854d..70909e36ff7 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -5,9 +5,9 @@ namespace BootstrapBlazor.Components; /// -/// Toast 弹出窗参数配置类 +/// Drawer 弹出窗参数配置类 /// -public class DrawerOption : PopupOptionBase +public class DrawerOption { /// /// 获得/设置 抽屉宽度 左右布局时生效 From 5869cc7a82ff8d8305fab3cc207a5a161daa7ae0 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:04:05 +0800 Subject: [PATCH 07/25] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DrawerServiceExtensions.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs diff --git a/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs new file mode 100644 index 00000000000..3c3ae26d217 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs @@ -0,0 +1,40 @@ +// 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/ + +namespace BootstrapBlazor.Components; + +/// +/// 抽屉服务扩展方法 +/// +public static class DrawerServiceExtensions +{ + /// + /// 弹出搜索对话框 + /// + /// DrawerService 服务实例 + /// + /// DrawerOption 配置类实例 + /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 + public static async Task Show(this DrawerService service, IDictionary? parameters = null, DrawerOption? option = null, DrawerContainer? drawerContainer = null) where TComponent : IComponent + { + option ??= new DrawerOption(); + option.ChildContent = BootstrapDynamicComponent.CreateComponent(parameters).Render(); + await service.Show(option, drawerContainer); + } + + /// + /// 弹出搜索对话框 + /// + /// DrawerService 服务实例 + /// + /// + /// DrawerOption 配置类实例 + /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 + public static async Task Show(this DrawerService service, Type type, IDictionary? parameters = null, DrawerOption? option = null, DrawerContainer? drawerContainer = null) + { + option ??= new DrawerOption(); + option.ChildContent = BootstrapDynamicComponent.CreateComponent(type, parameters).Render(); + await service.Show(option, drawerContainer); + } +} From 03c5cd6a2de04bf84be1eee43ac002e3e8f0da47 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:04:13 +0800 Subject: [PATCH 08/25] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/Drawer.razor.js | 83 ++++++++++++------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js index 7984b9c623c..31d2738a438 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js @@ -1,31 +1,25 @@ import Data from "../../modules/data.js" import Drag from "../../modules/drag.js" +import EventHandler from "../../modules/event-handler.js" -export function init(id) { - const el = document.getElementById(id) - const dw = { - element: el, - body: document.querySelector('body'), - drawerBody: el.querySelector('.drawer-body'), - bar: el.querySelector('.drawer-bar') - } - Data.set(id, dw) - +const initDrag = el => { let originX = 0 let originY = 0; let width = 0 let height = 0; let isVertical = false; - Drag.drag(dw.bar, + const drawerBody = el.querySelector('.drawer-body'); + const bar = el.querySelector('.drawer-bar'); + Drag.drag(bar, e => { - isVertical = dw.drawerBody.classList.contains("top") || dw.drawerBody.classList.contains("bottom") - dw.bar.classList.add('drag') + isVertical = drawerBody.classList.contains("top") || drawerBody.classList.contains("bottom") + bar.classList.add('drag') if (isVertical) { - height = parseInt(getComputedStyle(dw.drawerBody).getPropertyValue('--bb-drawer-height')) + height = parseInt(getComputedStyle(drawerBody).getPropertyValue('--bb-drawer-height')) originY = e.clientY || e.touches[0].clientY } else { - width = parseInt(getComputedStyle(dw.drawerBody).getPropertyValue('--bb-drawer-width')) + width = parseInt(getComputedStyle(drawerBody).getPropertyValue('--bb-drawer-width')) originX = e.clientX || e.touches[0].clientX } }, @@ -34,7 +28,7 @@ export function init(id) { const eventY = e.clientY || (e.touches.length || e.touches.length > 0 && e.touches[0].clientY) const moveY = eventY - originY let newHeight = 0; - if (dw.drawerBody.classList.contains("bottom")) { + if (drawerBody.classList.contains("bottom")) { newHeight = height - moveY } else { @@ -42,14 +36,14 @@ export function init(id) { } const maxHeight = window.innerHeight; if (newHeight > 100 && newHeight < maxHeight) { - dw.drawerBody.style.setProperty('--bb-drawer-height', `${newHeight}px`) + drawerBody.style.setProperty('--bb-drawer-height', `${newHeight}px`) } } else { const eventX = e.clientX || (e.touches.length || e.touches.length > 0 && e.touches[0].clientX) const moveX = eventX - originX let newWidth = 0; - if (dw.drawerBody.classList.contains("right")) { + if (drawerBody.classList.contains("right")) { newWidth = width - moveX } else { @@ -57,36 +51,55 @@ export function init(id) { } const maxWidth = window.innerWidth; if (newWidth > 100 && newWidth < maxWidth) { - dw.drawerBody.style.setProperty('--bb-drawer-width', `${newWidth}px`) + drawerBody.style.setProperty('--bb-drawer-width', `${newWidth}px`) } } }, e => { - dw.bar.classList.remove('drag') + bar.classList.remove('drag') } ) } +export function init(id, options) { + const el = document.getElementById(id) + const dw = { + el, + body: document.querySelector('body') + } + Data.set(id, dw) + + EventHandler.on(el, 'click', '.drawer-backdrop', e => { + const element = e.delegateTarget; + if (element.getAttribute('data-bb-backdrop') === 'true') { + options.invoke.invokeMethodAsync(options.callback); + } + }); + initDrag(el); +} + export function execute(id, open) { const dw = Data.get(id) - const el = dw.element + const { el, body } = dw + const drawerBody = el.querySelector('.drawer-body') + if (open) { el.classList.add('show') - dw.body.classList.add('overflow-hidden') + body.classList.add('overflow-hidden') let handler = window.setTimeout(() => { - dw.drawerBody.classList.add('show') + drawerBody.classList.add('show') window.clearTimeout(handler) handler = null }, 20); } else { if (el.classList.contains('show')) { - dw.drawerBody.classList.remove('show') + drawerBody.classList.remove('show') let handler = window.setTimeout(() => { window.clearTimeout(handler) handler = null el.classList.remove('show') - dw.body.classList.remove('overflow-hidden') + body.classList.remove('overflow-hidden') }, 320) } } @@ -94,15 +107,23 @@ export function execute(id, open) { export function dispose(id) { const dw = Data.get(id) - const el = dw.element + Data.remove(id); + + const { el, body } = dw if (el.classList.contains('show')) { el.classList.remove('show') - dw.drawerBody.classList.remove('show') - dw.body.classList.remove('overflow-hidden') + + const drawerBody = el.querySelector('.drawer-body') + if (drawerBody) { + drawerBody.classList.remove('show') + } + body.classList.remove('overflow-hidden') } - Data.remove(id) - if (dw.bar) { - Drag.dispose(dw.bar) + EventHandler.off(el, 'click', '.drawer-backdrop'); + + const bar = el.querySelector('.drawer-bar'); + if (bar) { + Drag.dispose(bar) } } From 13256605e8979fbdaa74131f21aa7353b7764526 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:04:25 +0800 Subject: [PATCH 09/25] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Drawers.razor | 4 ++++ .../Components/Samples/Drawers.razor.cs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor index 91b9918658c..aab21c579a8 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor @@ -38,4 +38,8 @@ + + + + diff --git a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs index 0ab609bf783..c971fd97831 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs @@ -9,6 +9,9 @@ namespace BootstrapBlazor.Server.Components.Samples; /// public sealed partial class Drawers { + [Inject, NotNull] + private DrawerService? DrawerService { get; set; } + private bool IsOpen { get; set; } private Placement DrawerAlign { get; set; } @@ -49,6 +52,15 @@ private void OpenDrawer() private void OpenNoBackdropDrawer() => IsShowBackdropOpen = true; + private async Task DrawerServiceShow() => await DrawerService.Show(new DrawerOption() + { + Placement = Placement.Right, + ChildContent = builder => builder.AddContent(0, "Test"), + ShowBackdrop = true, + AllowResize = true, + IsBackdrop = true + }); + /// /// Get property method /// From 5b8f43440c01cc3476eb73a02d7fa42680bf4f9b Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:05:32 +0800 Subject: [PATCH 10/25] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E6=8A=BD?= =?UTF-8?q?=E5=B1=89=E7=BB=84=E4=BB=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/Drawer.razor | 21 ++++++++++-- .../Components/Drawer/Drawer.razor.cs | 34 +++++++++++-------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor b/src/BootstrapBlazor/Components/Drawer/Drawer.razor index a62c67d8eba..3c0a2c4a967 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor @@ -3,7 +3,22 @@ @attribute [BootstrapModuleAutoLoader]
- - - + @if (ShowBackdrop) + { +
+
+ } +
+
+ + @ChildContent + +
+ @if (AllowResize) + { +
+
+
+ } +
diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index 187a960f43b..65ee0fdf469 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -17,6 +17,24 @@ public partial class Drawer .AddClassFromAttributes(AdditionalAttributes) .Build(); + /// + /// 获得 抽屉 Style 字符串 + /// + private string? DrawerStyleString => CssBuilder.Default() + .AddClass($"--bb-drawer-width: {Width};", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) + .AddClass($"--bb-drawer-height: {Height};", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) + .Build(); + + /// + /// 获得 抽屉样式 + /// + private string? DrawerClassString => CssBuilder.Default("drawer-body") + .AddClass("left", Placement != Placement.Right && Placement != Placement.Top && Placement != Placement.Bottom) + .AddClass("top", Placement == Placement.Top) + .AddClass("right", Placement == Placement.Right) + .AddClass("bottom", Placement == Placement.Bottom) + .Build(); + /// /// 获得/设置 抽屉宽度 左右布局时生效 /// @@ -92,18 +110,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender) } } - private DrawerOption GetOption() => new() - { - Height = Height, - Width = Width, - IsBackdrop = IsBackdrop, - ShowBackdrop = ShowBackdrop, - Placement = Placement, - AllowResize = AllowResize, - OnClickBackdrop = OnClickBackdrop, - ChildContent = ChildContent - }; - /// /// 点击背景遮罩方法 /// @@ -111,7 +117,7 @@ public async Task OnContainerClick() { if (IsBackdrop) { - await Close(GetOption()); + await Close(); if (OnClickBackdrop != null) await OnClickBackdrop.Invoke(); } } @@ -120,7 +126,7 @@ public async Task OnContainerClick() /// 关闭抽屉方法 ///
/// - public async Task Close(DrawerOption option) + public async Task Close() { IsOpen = false; if (IsOpenChanged.HasDelegate) From aceaef68af5e7f13386bf8b25658f4d60010bf63 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:19:18 +0800 Subject: [PATCH 11/25] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=B8=B2=E6=9F=93=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/DrawerContainer.cs | 29 +++++++++++++++++-- .../Components/Drawer/DrawerOption.cs | 4 +-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index b36a00516eb..a327edfd6e1 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -34,9 +34,32 @@ protected override void OnInitialized() /// protected override void BuildRenderTree(RenderTreeBuilder builder) { - builder.OpenComponent(0); - - builder.CloseComponent(); + if (_option != null) + { + var parameters = new Dictionary() + { + [nameof(Drawer.IsOpen)] = true, + [nameof(Drawer.IsBackdrop)] = _option.IsBackdrop, + [nameof(Drawer.ShowBackdrop)] = _option.ShowBackdrop, + [nameof(Drawer.Placement)] = _option.Placement, + [nameof(Drawer.AllowResize)] = _option.AllowResize + }; + if (!string.IsNullOrEmpty(_option.Width)) + { + parameters.Add(nameof(Drawer.Width), _option.Width); + } + if (!string.IsNullOrEmpty(_option.Height)) + { + parameters.Add(nameof(Drawer.Height), _option.Height); + } + if (_option.ChildContent != null) + { + parameters.Add(nameof(Drawer.ChildContent), _option.ChildContent); + } + builder.OpenComponent(0); + builder.AddMultipleAttributes(1, parameters); + builder.CloseComponent(); + } } private async Task Show(DrawerOption option) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs index 70909e36ff7..fd4bdd3445c 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -12,12 +12,12 @@ public class DrawerOption /// /// 获得/设置 抽屉宽度 左右布局时生效 /// - public string Width { get; set; } = "360px"; + public string? Width { get; set; } /// /// 获得/设置 抽屉高度 上下布局时生效 /// - public string Height { get; set; } = "290px"; + public string? Height { get; set; } /// /// 获得/设置 点击遮罩是否关闭抽屉 默认为 false From ea0f6e35a86afe6629df18319f10cc666d52f5ad Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:31:00 +0800 Subject: [PATCH 12/25] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=89=93=E5=BC=80=E6=8A=BD=E5=B1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs | 7 +++++-- src/BootstrapBlazor/Components/Drawer/Drawer.razor.js | 9 --------- src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs | 4 ++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index 65ee0fdf469..57c37670407 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -104,7 +104,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); - if (!firstRender) + if (!firstRender || IsOpen) { await InvokeVoidAsync("execute", Id, IsOpen); } @@ -118,7 +118,10 @@ public async Task OnContainerClick() if (IsBackdrop) { await Close(); - if (OnClickBackdrop != null) await OnClickBackdrop.Invoke(); + if (OnClickBackdrop != null) + { + await OnClickBackdrop(); + } } } diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js index 31d2738a438..ef6df6def0d 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js @@ -1,6 +1,5 @@ import Data from "../../modules/data.js" import Drag from "../../modules/drag.js" -import EventHandler from "../../modules/event-handler.js" const initDrag = el => { let originX = 0 @@ -69,12 +68,6 @@ export function init(id, options) { } Data.set(id, dw) - EventHandler.on(el, 'click', '.drawer-backdrop', e => { - const element = e.delegateTarget; - if (element.getAttribute('data-bb-backdrop') === 'true') { - options.invoke.invokeMethodAsync(options.callback); - } - }); initDrag(el); } @@ -120,8 +113,6 @@ export function dispose(id) { body.classList.remove('overflow-hidden') } - EventHandler.off(el, 'click', '.drawer-backdrop'); - const bar = el.querySelector('.drawer-bar'); if (bar) { Drag.dispose(bar) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index a327edfd6e1..946b1bec85d 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -56,6 +56,10 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) { parameters.Add(nameof(Drawer.ChildContent), _option.ChildContent); } + parameters.Add(nameof(Drawer.IsOpenChanged), EventCallback.Factory.Create(this, v => + { + _option = null; + })); builder.OpenComponent(0); builder.AddMultipleAttributes(1, parameters); builder.CloseComponent(); From 8fc8e30298937202b9ea0a0116486853a94c94a8 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 13:48:12 +0800 Subject: [PATCH 13/25] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/Drawer.razor.js | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js index ef6df6def0d..6d5083f02c8 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.js @@ -60,7 +60,7 @@ const initDrag = el => { ) } -export function init(id, options) { +export function init(id) { const el = document.getElementById(id) const dw = { el, @@ -76,24 +76,43 @@ export function execute(id, open) { const { el, body } = dw const drawerBody = el.querySelector('.drawer-body') + let start = void 0 + const show = ts => { + if (start === void 0) { + start = ts + } + const elapsed = ts - start; + if (elapsed < 20) { + requestAnimationFrame(show); + } + else { + drawerBody.classList.add('show') + } + } + + const hide = ts => { + if (start === void 0) { + start = ts + } + const elapsed = ts - start; + if (elapsed < 320) { + requestAnimationFrame(hide); + } + else { + el.classList.remove('show') + body.classList.remove('overflow-hidden') + } + } + if (open) { el.classList.add('show') body.classList.add('overflow-hidden') - let handler = window.setTimeout(() => { - drawerBody.classList.add('show') - window.clearTimeout(handler) - handler = null - }, 20); + requestAnimationFrame(show) } else { if (el.classList.contains('show')) { drawerBody.classList.remove('show') - let handler = window.setTimeout(() => { - window.clearTimeout(handler) - handler = null - el.classList.remove('show') - body.classList.remove('overflow-hidden') - }, 320) + requestAnimationFrame(hide) } } } From de2845393a4e1beb5df38a0565daf2710bba014c Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:00:43 +0800 Subject: [PATCH 14/25] =?UTF-8?q?feat:=20Drawer=20=E5=A2=9E=E5=8A=A0=20OnC?= =?UTF-8?q?loseAsync=20=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/Drawer.razor.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index 57c37670407..13a7b590cb9 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -95,6 +95,12 @@ public partial class Drawer [Parameter] public bool AllowResize { get; set; } + /// + /// 获得/设置 关闭抽屉回调委托 默认 null + /// + [Parameter] + public Func? OnCloseAsync { get; set; } + /// /// /// @@ -117,11 +123,11 @@ public async Task OnContainerClick() { if (IsBackdrop) { - await Close(); if (OnClickBackdrop != null) { await OnClickBackdrop(); } + await Close(); } } @@ -132,6 +138,10 @@ public async Task OnContainerClick() public async Task Close() { IsOpen = false; + if (OnCloseAsync != null) + { + await OnCloseAsync(); + } if (IsOpenChanged.HasDelegate) { await IsOpenChanged.InvokeAsync(IsOpen); From 6b51c62c247f6ce3e04fcc182cbc8fc57eed730d Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:36:45 +0800 Subject: [PATCH 15/25] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/DrawerContainer.cs | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index 946b1bec85d..55db931ea8a 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -36,33 +36,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) { if (_option != null) { - var parameters = new Dictionary() - { - [nameof(Drawer.IsOpen)] = true, - [nameof(Drawer.IsBackdrop)] = _option.IsBackdrop, - [nameof(Drawer.ShowBackdrop)] = _option.ShowBackdrop, - [nameof(Drawer.Placement)] = _option.Placement, - [nameof(Drawer.AllowResize)] = _option.AllowResize - }; - if (!string.IsNullOrEmpty(_option.Width)) - { - parameters.Add(nameof(Drawer.Width), _option.Width); - } - if (!string.IsNullOrEmpty(_option.Height)) - { - parameters.Add(nameof(Drawer.Height), _option.Height); - } - if (_option.ChildContent != null) - { - parameters.Add(nameof(Drawer.ChildContent), _option.ChildContent); - } - parameters.Add(nameof(Drawer.IsOpenChanged), EventCallback.Factory.Create(this, v => - { - _option = null; - })); - builder.OpenComponent(0); - builder.AddMultipleAttributes(1, parameters); - builder.CloseComponent(); + RenderDrawer(builder, _option); } } @@ -72,6 +46,52 @@ private async Task Show(DrawerOption option) await InvokeAsync(StateHasChanged); } + private void RenderDrawer(RenderTreeBuilder builder, DrawerOption option) + { + builder.OpenComponent(0); + builder.SetKey(option); + builder.AddMultipleAttributes(1, GetParameters(option)); + builder.CloseComponent(); + } + + private Dictionary GetParameters(DrawerOption option) + { + var parameters = new Dictionary() + { + [nameof(Drawer.IsOpen)] = true, + [nameof(Drawer.IsBackdrop)] = option.IsBackdrop, + [nameof(Drawer.ShowBackdrop)] = option.ShowBackdrop, + [nameof(Drawer.Placement)] = option.Placement, + [nameof(Drawer.AllowResize)] = option.AllowResize, + [nameof(Drawer.OnCloseAsync)] = new Func(() => OnCloseAsync(option)) + }; + if (!string.IsNullOrEmpty(option.Width)) + { + parameters.Add(nameof(Drawer.Width), option.Width); + } + if (!string.IsNullOrEmpty(option.Height)) + { + parameters.Add(nameof(Drawer.Height), option.Height); + } + if (option.ChildContent != null) + { + parameters.Add(nameof(Drawer.ChildContent), option.ChildContent); + } + if (option.OnClickBackdrop != null) + { + parameters.Add(nameof(Drawer.OnClickBackdrop), option.OnClickBackdrop); + } + return parameters; + } + + private async Task OnCloseAsync(DrawerOption option) + { + if (option.OnCloseAsync != null) + { + await option.OnCloseAsync(); + } + } + /// /// Dispose 方法 /// From 1e51d72f249078cf2ecbc462af1f24eae5a649d3 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:42:18 +0800 Subject: [PATCH 16/25] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Locales/en-US.json | 2 ++ src/BootstrapBlazor.Server/Locales/zh-CN.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index 439a3dbd9d0..33401539e32 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -923,6 +923,8 @@ "PlacementIntro": "By setting the IsBackdrop property to true, the drawer is automatically closed when the mask part is clicked", "NoBackdropTitle": "No backdrop", "NoBackdropIntro": "By setting the ShowBackdrop=\"false\" do not show the backdrop", + "DrawerServiceTitle": "Drawer Service", + "DrawerServiceIntro": "Open the drawer pop-up window by calling the DrawerService service", "Open": "click me to open", "Content": "The layout, components, etc. in the drawer are fully customizable", "Close": "close the drawer", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index f52b74b4018..1792b034bff 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -923,6 +923,8 @@ "PlacementIntro": "通过设置 IsBackdrop 属性为 true,点击遮罩部分时自动关闭抽屉", "NoBackdropTitle": "无遮罩效果", "NoBackdropIntro": "通过设置 ShowBackdrop=\"false\" 不显示遮罩,这种模式下可以与抽屉下面网页元素进行交互操作", + "DrawerServiceTitle": "调用服务打开抽屉", + "DrawerServiceIntro": "通过调用 DrawerService 服务打开抽屉弹窗", "Open": "点我打开", "Content": "抽屉内布局、组件等完全可以自定义", "Close": "关闭抽屉", From e36302843df30b7759840c99a9cc4efeb507a4fc Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:42:29 +0800 Subject: [PATCH 17/25] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20Show=20?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Drawer/DrawerService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerService.cs b/src/BootstrapBlazor/Components/Drawer/DrawerService.cs index 1d0a994ec91..5d08d6f4c6a 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerService.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerService.cs @@ -13,6 +13,5 @@ public class DrawerService : BootstrapServiceBase /// Show 方法 /// /// DrawerOption 实例 - /// 指定抽屉容器组件 默认为 null 使用 组件内置弹窗组件 - public Task Show(DrawerOption option, DrawerContainer? drawerContainer = null) => Invoke(option, drawerContainer); + public Task Show(DrawerOption option) => Invoke(option); } From 1c795e414c3a9a3b515d2158fcd5ed651de96db6 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:43:21 +0800 Subject: [PATCH 18/25] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/DrawerServiceExtensions.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs index 3c3ae26d217..66f0a666d1e 100644 --- a/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs +++ b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs @@ -15,12 +15,11 @@ public static class DrawerServiceExtensions /// DrawerService 服务实例 /// /// DrawerOption 配置类实例 - /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 - public static async Task Show(this DrawerService service, IDictionary? parameters = null, DrawerOption? option = null, DrawerContainer? drawerContainer = null) where TComponent : IComponent + public static async Task Show(this DrawerService service, IDictionary? parameters = null, DrawerOption? option = null) where TComponent : IComponent { option ??= new DrawerOption(); option.ChildContent = BootstrapDynamicComponent.CreateComponent(parameters).Render(); - await service.Show(option, drawerContainer); + await service.Show(option); } /// @@ -30,11 +29,10 @@ public static async Task Show(this DrawerService service, IDictionar /// /// /// DrawerOption 配置类实例 - /// 指定弹窗组件 默认为 null 使用 组件内置弹窗组件 - public static async Task Show(this DrawerService service, Type type, IDictionary? parameters = null, DrawerOption? option = null, DrawerContainer? drawerContainer = null) + public static async Task Show(this DrawerService service, Type type, IDictionary? parameters = null, DrawerOption? option = null) { option ??= new DrawerOption(); option.ChildContent = BootstrapDynamicComponent.CreateComponent(type, parameters).Render(); - await service.Show(option, drawerContainer); + await service.Show(option); } } From 51da15e41f5516831b4aff538a6f0a6d8adbdaa2 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:47:18 +0800 Subject: [PATCH 19/25] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/Drawers.razor.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs index c971fd97831..90c67d3c6a3 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs @@ -130,6 +130,14 @@ private static AttributeItem[] GetAttributes() => Type = "RenderFragment", ValueList = " — ", DefaultValue = " — " + }, + new() + { + Name = nameof(Drawer.OnCloseAsync), + Description = "The callback when close drawer", + Type = "Func", + ValueList = " — ", + DefaultValue = " — " } ]; } From 8a20a940d254ade5bb2ca6036235ea65e53571cc Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 14:47:29 +0800 Subject: [PATCH 20/25] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs index 66f0a666d1e..3fbcb557116 100644 --- a/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs +++ b/src/BootstrapBlazor/Extensions/DrawerServiceExtensions.cs @@ -15,7 +15,7 @@ public static class DrawerServiceExtensions /// DrawerService 服务实例 /// /// DrawerOption 配置类实例 - public static async Task Show(this DrawerService service, IDictionary? parameters = null, DrawerOption? option = null) where TComponent : IComponent + public static async Task Show(this DrawerService service, DrawerOption? option = null, IDictionary? parameters = null) where TComponent : IComponent { option ??= new DrawerOption(); option.ChildContent = BootstrapDynamicComponent.CreateComponent(parameters).Render(); @@ -29,7 +29,7 @@ public static async Task Show(this DrawerService service, IDictionar /// /// /// DrawerOption 配置类实例 - public static async Task Show(this DrawerService service, Type type, IDictionary? parameters = null, DrawerOption? option = null) + public static async Task Show(this DrawerService service, Type type, DrawerOption? option = null, IDictionary? parameters = null) { option ??= new DrawerOption(); option.ChildContent = BootstrapDynamicComponent.CreateComponent(type, parameters).Render(); From 57ffe8c063974f6e4fdfb8628e0ed3879ca7ffbb Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 15:06:15 +0800 Subject: [PATCH 21/25] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DrawerTest.cs | 12 ++-- test/UnitTest/Core/DialogTestBase.cs | 16 +++--- test/UnitTest/Core/DrawerTestBase.cs | 63 +++++++++++++++++++++ test/UnitTest/Services/DrawerServiceTest.cs | 40 +++++++++++++ 4 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 test/UnitTest/Core/DrawerTestBase.cs create mode 100644 test/UnitTest/Services/DrawerServiceTest.cs diff --git a/test/UnitTest/Components/DrawerTest.cs b/test/UnitTest/Components/DrawerTest.cs index ca33fc2e096..52c602ef70e 100644 --- a/test/UnitTest/Components/DrawerTest.cs +++ b/test/UnitTest/Components/DrawerTest.cs @@ -59,34 +59,34 @@ public void AllowResize_Ok() [Fact] public void IsOpenChanged_Ok() { - var isopen = true; + var isOpen = true; var cut = Context.RenderComponent(builder => { builder.Add(a => a.IsBackdrop, true); builder.Add(a => a.IsOpen, true); builder.Add(a => a.IsOpenChanged, EventCallback.Factory.Create(this, e => { - isopen = e; + isOpen = e; })); }); cut.Find(".drawer-backdrop").Click(); - Assert.False(isopen); + Assert.False(isOpen); } [Fact] public void OnClickBackdrop_Ok() { - var isopen = true; + var isOpen = true; var cut = Context.RenderComponent(builder => { builder.Add(a => a.IsBackdrop, true); builder.Add(a => a.IsOpen, true); - builder.Add(a => a.OnClickBackdrop, () => { isopen = false; return Task.CompletedTask; }); + builder.Add(a => a.OnClickBackdrop, () => { isOpen = false; return Task.CompletedTask; }); }); cut.Find(".drawer-backdrop").Click(); - Assert.False(isopen); + Assert.False(isOpen); } [Fact] diff --git a/test/UnitTest/Core/DialogTestBase.cs b/test/UnitTest/Core/DialogTestBase.cs index fcfae658888..3e0942a53eb 100644 --- a/test/UnitTest/Core/DialogTestBase.cs +++ b/test/UnitTest/Core/DialogTestBase.cs @@ -7,29 +7,29 @@ namespace UnitTest.Core; -[Collection("DialogTestContext")] -public class DialogTestBase +[Collection("DrawerTestContext")] +public class DrawerTestBase { protected TestContext Context { get; } - public DialogTestBase() + public DrawerTestBase() { - Context = DialogTestHost.Instance; + Context = DrawerTestHost.Instance; } } -[CollectionDefinition("DialogTestContext")] -public class DialogTestCollection : ICollectionFixture +[CollectionDefinition("DrawerTestContext")] +public class DrawerTestCollection : ICollectionFixture { } -public class DialogTestHost : IDisposable +public class DrawerTestHost : IDisposable { [NotNull] internal static TestContext? Instance { get; private set; } - public DialogTestHost() + public DrawerTestHost() { Instance = new TestContext(); diff --git a/test/UnitTest/Core/DrawerTestBase.cs b/test/UnitTest/Core/DrawerTestBase.cs new file mode 100644 index 00000000000..fcfae658888 --- /dev/null +++ b/test/UnitTest/Core/DrawerTestBase.cs @@ -0,0 +1,63 @@ +// 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 Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace UnitTest.Core; + +[Collection("DialogTestContext")] +public class DialogTestBase +{ + protected TestContext Context { get; } + + public DialogTestBase() + { + Context = DialogTestHost.Instance; + } +} + +[CollectionDefinition("DialogTestContext")] +public class DialogTestCollection : ICollectionFixture +{ + +} + +public class DialogTestHost : IDisposable +{ + [NotNull] + internal static TestContext? Instance { get; private set; } + + public DialogTestHost() + { + Instance = new TestContext(); + + // Mock 脚本 + Instance.JSInterop.Mode = JSRuntimeMode.Loose; + + ConfigureServices(Instance.Services); + + ConfigureConfiguration(Instance.Services); + + // 渲染 SwalRoot 组件 激活 ICacheManager 接口 + Instance.Services.GetRequiredService(); + } + + protected virtual void ConfigureServices(IServiceCollection services) + { + services.AddBootstrapBlazor(); + } + + protected virtual void ConfigureConfiguration(IServiceCollection services) + { + // 增加单元测试 appsettings.json 配置文件 + services.AddConfiguration(); + } + + public void Dispose() + { + Instance.Dispose(); + GC.SuppressFinalize(this); + } +} diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs new file mode 100644 index 00000000000..67140270643 --- /dev/null +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -0,0 +1,40 @@ +// 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 Microsoft.Extensions.DependencyInjection; + +namespace UnitTest.Services; + +public class DrawerServiceTest : DrawerTestBase +{ + [Fact] + public async Task Show_Ok() + { + var option = new DrawerOption() + { + AllowResize = true, + ChildContent = RenderContent(), + Height = "100px", + Width = "100px", + IsBackdrop = true, + OnClickBackdrop = () => Task.CompletedTask, + OnCloseAsync = () => Task.CompletedTask, + Placement = Placement.Bottom, + ShowBackdrop = true + }; + var service = Context.Services.GetRequiredService(); + var cut = Context.RenderComponent(); + await service.Show(option); + + var button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); + } + + private RenderFragment RenderContent() => builder => + { + builder.AddContent(0, "drawer-content"); + builder.OpenComponent(0); + builder.CloseComponent(); + }; +} From cb88795c863719218ba5396ea1842c5ca3aac95f Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 15:10:19 +0800 Subject: [PATCH 22/25] =?UTF-8?q?test:=20=E6=8F=90=E9=AB=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/DrawerServiceTest.cs | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index 67140270643..d493eda8f8f 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -8,6 +8,28 @@ namespace UnitTest.Services; public class DrawerServiceTest : DrawerTestBase { + [Fact] + public async Task ShowComponent_Ok() + { + var service = Context.Services.GetRequiredService(); + var cut = Context.RenderComponent(); + await service.Show(); + + var button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); + } + + [Fact] + public async Task ShowType_Ok() + { + var service = Context.Services.GetRequiredService(); + var cut = Context.RenderComponent(); + await service.Show(typeof(DrawerDemo)); + + var button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); + } + [Fact] public async Task Show_Ok() { @@ -31,10 +53,15 @@ public async Task Show_Ok() await cut.InvokeAsync(() => button.Click()); } - private RenderFragment RenderContent() => builder => + private static RenderFragment RenderContent() => builder => { builder.AddContent(0, "drawer-content"); builder.OpenComponent(0); builder.CloseComponent(); }; + + class DrawerDemo : ComponentBase + { + + } } From 39acdd3290c1ab522227a79c0fc4a3351b2bf386 Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 15:12:18 +0800 Subject: [PATCH 23/25] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/DrawerServiceTest.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index d493eda8f8f..b1c5560f940 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -2,6 +2,7 @@ // 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 Microsoft.AspNetCore.Components.Rendering; using Microsoft.Extensions.DependencyInjection; namespace UnitTest.Services; @@ -62,6 +63,9 @@ private static RenderFragment RenderContent() => builder => class DrawerDemo : ComponentBase { - + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.AddContent(0, RenderContent()); + } } } From 47f293a604241be4ab8d641dfc83abc49d8a916c Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 15:15:25 +0800 Subject: [PATCH 24/25] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/DrawerServiceTest.cs | 31 ++++++--------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index b1c5560f940..9bfeb1b2f9f 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -9,28 +9,6 @@ namespace UnitTest.Services; public class DrawerServiceTest : DrawerTestBase { - [Fact] - public async Task ShowComponent_Ok() - { - var service = Context.Services.GetRequiredService(); - var cut = Context.RenderComponent(); - await service.Show(); - - var button = cut.Find("button"); - await cut.InvokeAsync(() => button.Click()); - } - - [Fact] - public async Task ShowType_Ok() - { - var service = Context.Services.GetRequiredService(); - var cut = Context.RenderComponent(); - await service.Show(typeof(DrawerDemo)); - - var button = cut.Find("button"); - await cut.InvokeAsync(() => button.Click()); - } - [Fact] public async Task Show_Ok() { @@ -49,9 +27,16 @@ public async Task Show_Ok() var service = Context.Services.GetRequiredService(); var cut = Context.RenderComponent(); await service.Show(option); - var button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); + + await service.Show(); + button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); + + await service.Show(typeof(DrawerDemo)); + button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); } private static RenderFragment RenderContent() => builder => From 33a002b047215eee61fef0093ecb5421786b1d9a Mon Sep 17 00:00:00 2001 From: Argo-Supper Date: Mon, 27 May 2024 15:15:47 +0800 Subject: [PATCH 25/25] chore: bump version 8.5.11 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index ba84a847b31..d83b48aa89b 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 8.5.10 + 8.5.11