From a1fa8b09410a3d49ba4a3e67e7c688954cee9404 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 27 Dec 2024 13:36:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Component=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Drawer/DrawerContainer.cs | 5 +++-- .../Components/Drawer/DrawerOption.cs | 5 +++++ .../Extensions/DrawerOptionExtensions.cs | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index fc08a80e21c..572d43e7f82 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -79,9 +79,10 @@ private Dictionary GetParameters(DrawerOption option) { parameters.Add(nameof(Drawer.Height), option.Height); } - if (option.ChildContent != null) + var content = option.GetContent(); + if (content != null) { - parameters.Add(nameof(Drawer.ChildContent), option.ChildContent); + parameters.Add(nameof(Drawer.ChildContent), content); } if (option.OnClickBackdrop != null) { diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs index 1d6e518a727..602447399d3 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -45,6 +45,11 @@ public class DrawerOption /// public RenderFragment? ChildContent { get; set; } + /// + /// 获得/设置 自定义组件 + /// + public BootstrapDynamicComponent? Component { get; set; } + /// /// 获得/设置 是否允许调整大小 默认 false /// diff --git a/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs b/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs new file mode 100644 index 00000000000..6fdc6a00171 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +namespace BootstrapBlazor.Components; + +/// +/// 扩展方法 +/// +public static class DrawerOptionExtensions +{ + /// + /// 获得 组件渲染块 + /// + /// + /// + public static RenderFragment? GetContent(this DrawerOption drawerOption) => drawerOption.ChildContent ?? drawerOption.Component?.Render(); +} From 92111c6308a0c37ac56eb8abf03cf973a66842bc Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 27 Dec 2024 13:42:40 +0800 Subject: [PATCH 2/3] =?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 Co-Authored-By: MadLongTom <36219016+MadLongTom@users.noreply.github.com> Co-Authored-By: Frost Autumn <78307204+XUEWUQIUSHUANG@users.noreply.github.com> Co-Authored-By: ice6 <889040+ice6@users.noreply.github.com> --- test/UnitTest/Services/DrawerServiceTest.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index 0391d0c0bb8..92369aa0c47 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -30,11 +30,18 @@ public async Task Show_Ok() var button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); + option.ChildContent = null; + option.Component = BootstrapDynamicComponent.CreateComponent(); + await service.Show(option); + 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)); + var type = typeof(DrawerDemo); + await service.Show(type); button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); } From f06108211db8896ff0de4a357f5cfb1262bd6b7a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 27 Dec 2024 13:43:46 +0800 Subject: [PATCH 3/3] =?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 Co-Authored-By: Alex chow --- test/UnitTest/Services/DrawerServiceTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index 92369aa0c47..2360d0e7bc8 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -36,6 +36,9 @@ public async Task Show_Ok() button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); + option.Component = null; + Assert.Null(option.GetContent()); + await service.Show(); button = cut.Find("button"); await cut.InvokeAsync(() => button.Click());