Skip to content

Commit 9d8fddb

Browse files
ArgoZhangMadLongTomXUEWUQIUSHUANGice6densen2014
authored
feat(Drawer): add Component parameter on DrawerOption (#4964)
* feat: 增加 Component 参数 * test: 更新单元测试 Co-Authored-By: MadLongTom <[email protected]> Co-Authored-By: Frost Autumn <[email protected]> Co-Authored-By: ice6 <[email protected]> * test: 更新单元测试 Co-Authored-By: Alex chow <[email protected]> --------- Co-authored-by: MadLongTom <[email protected]> Co-authored-by: Frost Autumn <[email protected]> Co-authored-by: ice6 <[email protected]> Co-authored-by: Alex chow <[email protected]>
1 parent ee332f1 commit 9d8fddb

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ private Dictionary<string, object> GetParameters(DrawerOption option)
7979
{
8080
parameters.Add(nameof(Drawer.Height), option.Height);
8181
}
82-
if (option.ChildContent != null)
82+
var content = option.GetContent();
83+
if (content != null)
8384
{
84-
parameters.Add(nameof(Drawer.ChildContent), option.ChildContent);
85+
parameters.Add(nameof(Drawer.ChildContent), content);
8586
}
8687
if (option.OnClickBackdrop != null)
8788
{

src/BootstrapBlazor/Components/Drawer/DrawerOption.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class DrawerOption
4545
/// </summary>
4646
public RenderFragment? ChildContent { get; set; }
4747

48+
/// <summary>
49+
/// 获得/设置 自定义组件
50+
/// </summary>
51+
public BootstrapDynamicComponent? Component { get; set; }
52+
4853
/// <summary>
4954
/// 获得/设置 是否允许调整大小 默认 false
5055
/// </summary>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// <see cref="DrawerOption"/> 扩展方法
10+
/// </summary>
11+
public static class DrawerOptionExtensions
12+
{
13+
/// <summary>
14+
/// 获得 组件渲染块
15+
/// </summary>
16+
/// <param name="drawerOption"></param>
17+
/// <returns></returns>
18+
public static RenderFragment? GetContent(this DrawerOption drawerOption) => drawerOption.ChildContent ?? drawerOption.Component?.Render();
19+
}

test/UnitTest/Services/DrawerServiceTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ public async Task Show_Ok()
3030
var button = cut.Find("button");
3131
await cut.InvokeAsync(() => button.Click());
3232

33+
option.ChildContent = null;
34+
option.Component = BootstrapDynamicComponent.CreateComponent<DialogCloseButton>();
35+
await service.Show(option);
36+
button = cut.Find("button");
37+
await cut.InvokeAsync(() => button.Click());
38+
39+
option.Component = null;
40+
Assert.Null(option.GetContent());
41+
3342
await service.Show<DrawerDemo>();
3443
button = cut.Find("button");
3544
await cut.InvokeAsync(() => button.Click());
3645

37-
await service.Show(typeof(DrawerDemo));
46+
var type = typeof(DrawerDemo);
47+
await service.Show(type);
3848
button = cut.Find("button");
3949
await cut.InvokeAsync(() => button.Click());
4050
}

0 commit comments

Comments
 (0)