Skip to content

Commit 39c42d4

Browse files
authored
feat(DialogOption): add IsFade parameter (#5518)
* doc: 文档注释更新为英语 * refactor: 增加 IsFade 参数 * refactor: 增加 IsFade 参数支持 * test: 更新单元测试 * test: 更新单元测试 * chore: bump version 9.4.4 * refactor: 重构代码
1 parent 28a9d85 commit 39c42d4

File tree

6 files changed

+91
-89
lines changed

6 files changed

+91
-89
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
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.4.3-beta04</Version>
4+
<Version>9.4.4</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Dialog/Dialog.razor

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@namespace BootstrapBlazor.Components
22
@inherits BootstrapComponentBase
33

4-
<Modal @ref="ModalContainer" IsBackdrop="IsBackdrop" IsKeyboard="@IsKeyboard" OnShownAsync="@OnShownAsync" OnCloseAsync="OnCloseAsync">
4+
<Modal @ref="_modal" IsBackdrop="_isBackdrop" IsKeyboard="@_isKeyboard" IsFade="@_isFade"
5+
OnShownAsync="@_onShownAsync" OnCloseAsync="@_onCloseAsync">
56
@for (var index = 0; index < DialogParameters.Keys.Count; index++)
67
{
78
@RenderDialog(index, DialogParameters.Keys.ElementAt(index))

src/BootstrapBlazor/Components/Dialog/Dialog.razor.cs

+36-46
Original file line numberDiff line numberDiff line change
@@ -6,103 +6,93 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// Dialog 对话框组件
9+
/// Dialog component
1010
/// </summary>
1111
public partial class Dialog : IDisposable
1212
{
13-
/// <summary>
14-
/// 获得/设置 Modal 容器组件实例
15-
/// </summary>
16-
[NotNull]
17-
private Modal? ModalContainer { get; set; }
18-
19-
/// <summary>
20-
/// 获得/设置 弹出对话框实例集合
21-
/// </summary>
22-
private Dictionary<Dictionary<string, object>, (bool IsKeyboard, bool IsBackdrop)> DialogParameters { get; } = [];
23-
24-
private bool IsKeyboard { get; set; }
25-
26-
private bool IsBackdrop { get; set; }
27-
28-
/// <summary>
29-
/// DialogServices 服务实例
30-
/// </summary>
3113
[Inject]
3214
[NotNull]
3315
private DialogService? DialogService { get; set; }
3416

3517
[NotNull]
36-
private Func<Task>? OnShownAsync { get; set; }
18+
private Modal? _modal = null;
19+
20+
[NotNull]
21+
private Func<Task>? _onShownAsync = null;
3722

3823
[NotNull]
39-
private Func<Task>? OnCloseAsync { get; set; }
24+
private Func<Task>? _onCloseAsync = null;
4025

41-
private Dictionary<string, object>? CurrentParameter { get; set; }
26+
private readonly Dictionary<Dictionary<string, object>, (bool IsKeyboard, bool IsBackdrop)> DialogParameters = [];
27+
private Dictionary<string, object>? _currentParameter;
28+
private bool _isKeyboard = false;
29+
private bool _isBackdrop = false;
30+
private bool _isFade = true;
4231

4332
/// <summary>
44-
/// OnInitialized 方法
33+
/// <inheritdoc/>
4534
/// </summary>
4635
protected override void OnInitialized()
4736
{
4837
base.OnInitialized();
4938

50-
// 注册 Dialog 弹窗事件
39+
// Register Dialog popup event
5140
DialogService.Register(this, Show);
5241
}
5342

5443
/// <summary>
55-
/// OnAfterRenderAsync 方法
44+
/// <inheritdoc/>
5645
/// </summary>
5746
/// <param name="firstRender"></param>
5847
/// <returns></returns>
5948
protected override async Task OnAfterRenderAsync(bool firstRender)
6049
{
6150
await base.OnAfterRenderAsync(firstRender);
6251

63-
if (CurrentParameter != null)
52+
if (_currentParameter != null)
6453
{
65-
await ModalContainer.Show();
54+
await _modal.Show();
6655
}
6756
}
6857

6958
private async Task Show(DialogOption option)
7059
{
71-
OnShownAsync = async () =>
60+
_onShownAsync = async () =>
7261
{
7362
if (option.OnShownAsync != null)
7463
{
7564
await option.OnShownAsync();
7665
}
7766
};
7867

79-
OnCloseAsync = async () =>
68+
_onCloseAsync = async () =>
8069
{
81-
// 回调 OnCloseAsync
70+
// Callback OnCloseAsync
8271
if (option.OnCloseAsync != null)
8372
{
8473
await option.OnCloseAsync();
8574
}
8675

87-
// 移除当前 DialogParameter
88-
if (CurrentParameter != null)
76+
// Remove current DialogParameter
77+
if (_currentParameter != null)
8978
{
90-
DialogParameters.Remove(CurrentParameter);
79+
DialogParameters.Remove(_currentParameter);
9180

92-
// 多弹窗支持
81+
// Support for multiple dialogs
9382
var p = DialogParameters.LastOrDefault();
94-
CurrentParameter = p.Key;
95-
IsKeyboard = p.Value.IsKeyboard;
96-
IsBackdrop = p.Value.IsBackdrop;
83+
_currentParameter = p.Key;
84+
_isKeyboard = p.Value.IsKeyboard;
85+
_isBackdrop = p.Value.IsBackdrop;
9786

9887
StateHasChanged();
9988
}
10089
};
10190

102-
IsKeyboard = option.IsKeyboard;
103-
IsBackdrop = option.IsBackdrop;
91+
_isKeyboard = option.IsKeyboard;
92+
_isBackdrop = option.IsBackdrop;
93+
_isFade = option.IsFade;
10494

105-
option.Modal = ModalContainer;
95+
option.Modal = _modal;
10696

10797
var parameters = option.ToAttributes();
10898
var content = option.BodyTemplate ?? option.Component?.Render();
@@ -163,11 +153,11 @@ private async Task Show(DialogOption option)
163153
}
164154
}
165155

166-
// 保存当前 Dialog 参数
167-
CurrentParameter = parameters;
156+
// Save current Dialog parameters
157+
_currentParameter = parameters;
168158

169-
// 添加 ModalDialog 到容器中
170-
DialogParameters.Add(parameters, (IsKeyboard, IsBackdrop));
159+
// Add ModalDialog to the container
160+
DialogParameters.Add(parameters, (_isKeyboard, _isBackdrop));
171161
await InvokeAsync(StateHasChanged);
172162
}
173163

@@ -180,7 +170,7 @@ private static RenderFragment RenderDialog(int index, Dictionary<string, object>
180170
};
181171

182172
/// <summary>
183-
/// Dispose 方法
173+
/// Dispose method
184174
/// </summary>
185175
/// <param name="disposing"></param>
186176
protected virtual void Dispose(bool disposing)
@@ -192,7 +182,7 @@ protected virtual void Dispose(bool disposing)
192182
}
193183

194184
/// <summary>
195-
/// Dispose 方法
185+
/// <inheritdoc/>
196186
/// </summary>
197187
public void Dispose()
198188
{

0 commit comments

Comments
 (0)