Skip to content

Commit 8178e81

Browse files
authored
feat(ModalSettings): add ModalSettings on BootstrapBlazorOptions (#5619)
* feat: 增加 ModalSetings 配置类 * doc: 更新文档注释 * feat: 增加 IsFade 取值逻辑 * refactor: 增加 IsFade 参数 * refactor: 更新 IsFade 逻辑 * chore: bump version 9.4.9-beta06
1 parent fd92ad9 commit 8178e81

File tree

8 files changed

+58
-24
lines changed

8 files changed

+58
-24
lines changed

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.4.9-beta05</Version>
4+
<Version>9.4.9-beta06</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class Dialog : IDisposable
2727
private Dictionary<string, object>? _currentParameter;
2828
private bool _isKeyboard = false;
2929
private bool _isBackdrop = false;
30-
private bool _isFade = true;
30+
private bool? _isFade = null;
3131

3232
/// <summary>
3333
/// <inheritdoc/>

src/BootstrapBlazor/Components/Dialog/DialogOption.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public class DialogOption
6868
public bool ShowHeaderCloseButton { get; set; } = true;
6969

7070
/// <summary>
71-
/// Gets or sets whether to enable fade animation, default is true
71+
/// Gets or sets whether to enable fade animation, default is null
7272
/// </summary>
73-
public bool IsFade { get; set; } = true;
73+
public bool? IsFade { get; set; }
7474

7575
/// <summary>
7676
/// Gets or sets whether to support closing the dialog with the ESC key, default is true

src/BootstrapBlazor/Components/Modal/Modal.razor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ namespace BootstrapBlazor.Components;
1212
/// </summary>
1313
public partial class Modal
1414
{
15+
[Inject]
16+
[NotNull]
17+
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
18+
1519
/// <summary>
1620
/// Gets the style string
1721
/// </summary>
1822
private string? ClassString => CssBuilder.Default("modal")
19-
.AddClass("fade", IsFade)
23+
.AddClass("fade", Options.CurrentValue.GetIsFadeValue(IsFade))
2024
.AddClassFromAttributes(AdditionalAttributes)
2125
.Build();
2226

@@ -40,10 +44,10 @@ public partial class Modal
4044
public bool IsKeyboard { get; set; } = true;
4145

4246
/// <summary>
43-
/// Gets or sets whether to enable fade in and out animation, default is true to enable animation
47+
/// Gets or sets whether to enable fade in and out animation, default is null
4448
/// </summary>
4549
[Parameter]
46-
public bool IsFade { get; set; } = true;
50+
public bool? IsFade { get; set; }
4751

4852
/// <summary>
4953
/// Gets or sets the child component

src/BootstrapBlazor/Components/SweetAlert/SweetAlert.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
@inherits BootstrapComponentBase
33
@inject SwalService Swal
44

5-
<Modal @ref="ModalContainer" IsKeyboard="false" OnCloseAsync="OnCloseAsync" class="swal">
5+
<Modal @ref="ModalContainer" IsKeyboard="false" OnCloseAsync="OnCloseAsync" IsFade="true" class="swal">
66
@RenderDialog()
77
</Modal>

src/BootstrapBlazor/Extensions/BootstrapBlazorOptionsExtensions.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,35 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
/// BootstrapBlazorOptions 配置类扩展方法
9+
/// BootstrapBlazorOptions configuration class extension methods
1010
/// </summary>
1111
public static class BootstrapBlazorOptionsExtensions
1212
{
1313
/// <summary>
14-
/// 获取步长泛型方法
14+
/// Get step size generic method
1515
/// </summary>
16-
/// <typeparam name="TType"></typeparam>
17-
/// <param name="options"></param>
18-
/// <returns></returns>
16+
/// <typeparam name="TType">The type parameter</typeparam>
17+
/// <param name="options">The BootstrapBlazorOptions instance</param>
18+
/// <returns>The step size as a string</returns>
1919
public static string? GetStep<TType>(this BootstrapBlazorOptions options) => options.GetStep(typeof(TType));
2020

2121
/// <summary>
22-
/// 获取步长方法
22+
/// Get step size method
2323
/// </summary>
24-
/// <param name="options">配置实体类实例</param>
25-
/// <param name="type">数据类型</param>
26-
/// <returns></returns>
24+
/// <param name="options">The BootstrapBlazorOptions instance</param>
25+
/// <param name="type">The data type</param>
26+
/// <returns>The step size as a string</returns>
2727
public static string? GetStep(this BootstrapBlazorOptions options, Type type)
2828
{
2929
var t = Nullable.GetUnderlyingType(type) ?? type;
3030
return options.StepSettings.GetStep(t);
3131
}
32+
33+
/// <summary>
34+
/// Get Modal IsFade value
35+
/// </summary>
36+
/// <param name="options">The BootstrapBlazorOptions instance</param>
37+
/// <param name="value">The default value</param>
38+
/// <returns>The IsFade value as a boolean</returns>
39+
public static bool GetIsFadeValue(this BootstrapBlazorOptions options, bool? value) => value ?? options.ModalSettings.IsFade ?? true;
3240
}

src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,42 +86,47 @@ public class BootstrapBlazorOptions : IOptions<BootstrapBlazorOptions>
8686
public string? JSModuleVersion { get; set; }
8787

8888
/// <summary>
89-
/// Gets or sets the table settings instance
89+
/// Gets or sets the <see cref="TableSettings"/> configuration instance
9090
/// </summary>
9191
public TableSettings TableSettings { get; set; } = new();
9292

93+
/// <summary>
94+
/// Gets or sets the <see cref="ModalSettings"/> configuration instance
95+
/// </summary>
96+
public ModalSettings ModalSettings { get; set; } = new();
97+
9398
/// <summary>
9499
/// Gets or sets the <see cref="StepSettings"/> configuration instance
95100
/// </summary>
96101
public StepSettings StepSettings { get; set; } = new();
97102

98103
/// <summary>
99-
/// Gets or sets the <see cref="ConnectionHubOptions"/> configuration, default is not null
104+
/// Gets or sets the <see cref="ConnectionHubOptions"/> configuration
100105
/// </summary>
101106
public ConnectionHubOptions ConnectionHubOptions { get; set; } = new();
102107

103108
/// <summary>
104-
/// Gets or sets the <see cref="WebClientOptions"/> configuration, default is not null
109+
/// Gets or sets the <see cref="WebClientOptions"/> configuration
105110
/// </summary>
106111
public WebClientOptions WebClientOptions { get; set; } = new();
107112

108113
/// <summary>
109-
/// Gets or sets the <see cref="IpLocatorOptions"/> configuration, default is not null
114+
/// Gets or sets the <see cref="IpLocatorOptions"/> configuration
110115
/// </summary>
111116
public IpLocatorOptions IpLocatorOptions { get; set; } = new();
112117

113118
/// <summary>
114-
/// Gets or sets the <see cref="ScrollOptions"/> configuration, default is not null
119+
/// Gets or sets the <see cref="ScrollOptions"/> configuration
115120
/// </summary>
116121
public ScrollOptions ScrollOptions { get; set; } = new();
117122

118123
/// <summary>
119-
/// Gets or sets the <see cref="ContextMenuOptions"/> configuration, default is not null
124+
/// Gets or sets the <see cref="ContextMenuOptions"/> configuration
120125
/// </summary>
121126
public ContextMenuOptions ContextMenuOptions { get; set; } = new();
122127

123128
/// <summary>
124-
/// Gets or sets the CacheManagerOptions configuration, default is not null
129+
/// Gets or sets the CacheManagerOptions configuration
125130
/// </summary>
126131
public CacheManagerOptions CacheManagerOptions { get; set; } = new();
127132

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
/// Modal component settings
10+
/// </summary>
11+
public class ModalSettings
12+
{
13+
/// <summary>
14+
/// Gets or sets whether to enable fade animation, default is null
15+
/// </summary>
16+
public bool? IsFade { get; set; }
17+
}

0 commit comments

Comments
 (0)