Skip to content

Commit 8addd2b

Browse files
feat(Dialog): add Show<TComponent> extension method (#5983)
* feat: 增加 Show 泛型扩展方法 * test: 增加单元测试 * chore: bump version 9.6.1-beta03 Co-Authored-By: WarriorBlue <15247822+warriorblue@users.noreply.github.com> * doc: 更新注释 * refactor: 更新文档 --------- Co-authored-by: WarriorBlue <15247822+warriorblue@users.noreply.github.com>
1 parent 384fd9d commit 8addd2b

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.6.1-beta02</Version>
4+
<Version>9.6.1-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,29 @@
88
namespace BootstrapBlazor.Components;
99

1010
/// <summary>
11-
/// DialogService 扩展方法
11+
/// DialogService extensions method
1212
/// </summary>
1313
public static class DialogServiceExtensions
1414
{
15+
/// <summary>
16+
/// Show dialog with generic type.
17+
/// </summary>
18+
/// <param name="service">DialogService 服务实例</param>
19+
/// <param name="title">对话框标题,优先级高于 <see cref="DialogOption.Title"/></param>
20+
/// <param name="parameters">TComponent 组件所需要的参数集合</param>
21+
/// <param name="dialog">指定弹窗组件 默认为 null 使用 <see cref="BootstrapBlazorRoot"/> 组件内置弹窗组件</param>
22+
public static Task Show<TComponent>(this DialogService service, string title, IDictionary<string, object?>? parameters = null, Dialog? dialog = null) where TComponent : IComponent
23+
{
24+
var option = new DialogOption();
25+
if (!string.IsNullOrEmpty(title))
26+
{
27+
option.Title = title;
28+
}
29+
option.ShowFooter = false;
30+
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
31+
return service.Show(option, dialog);
32+
}
33+
1534
/// <summary>
1635
/// 弹出搜索对话框
1736
/// </summary>

test/UnitTest/Components/DialogTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ await cut.InvokeAsync(() => dialog.ShowCloseDialog<MockValidateFormDialog>("Clos
573573
}));
574574
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
575575
#endregion
576+
577+
#region Show Extensions Method
578+
await cut.InvokeAsync(() => dialog.Show<MockValidateFormDialog>("Test Title"));
579+
await cut.InvokeAsync(() => modal.Instance.CloseCallback());
580+
#endregion
576581
}
577582

578583
private class MockValidateFormDialog : ComponentBase

0 commit comments

Comments
 (0)