Skip to content

Commit ddca0bf

Browse files
doc(Toast): update sample code show the delay time (#5338)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c86c885 commit ddca0bf

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/BootstrapBlazor.Server/Components/Samples/Toasts.razor.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using Microsoft.Extensions.Options;
7+
68
namespace BootstrapBlazor.Server.Components.Samples;
79

810
/// <summary>
@@ -32,17 +34,22 @@ public sealed partial class Toasts
3234
[NotNull]
3335
private ConsoleLogger? Logger { get; set; }
3436

37+
[Inject, NotNull]
38+
private IOptions<BootstrapBlazorOptions>? Options { get; set; }
39+
40+
private int _delayTs => Options.Value.ToastDelay / 1000;
41+
3542
/// <summary>
3643
/// OnInitialized
3744
/// </summary>
3845
protected override void OnInitialized()
3946
{
4047
base.OnInitialized();
4148

42-
Options1 = new ToastOption { Title = "Save data", IsAutoHide = false, Content = "Save data successfully, automatically close after 4 seconds" };
43-
Options2 = new ToastOption { Category = ToastCategory.Error, Title = "Save data", IsAutoHide = false, Content = "Save data successfully, automatically close after 4 seconds" };
44-
Options3 = new ToastOption { Category = ToastCategory.Information, Title = "Prompt information", IsAutoHide = false, Content = "Information prompt pop-up window, automatically closes after 4 seconds" };
45-
Options4 = new ToastOption { Category = ToastCategory.Warning, Title = "Warning message", IsAutoHide = false, Content = "Information prompt pop-up window, automatically closes after 4 seconds" };
49+
Options1 = new ToastOption { Title = "Save data", IsAutoHide = false, Content = $"Save data successfully, automatically close after {_delayTs} seconds" };
50+
Options2 = new ToastOption { Category = ToastCategory.Error, Title = "Save data", IsAutoHide = false, Content = $"Save data successfully, automatically close after {_delayTs} seconds" };
51+
Options3 = new ToastOption { Category = ToastCategory.Information, Title = "Prompt information", IsAutoHide = false, Content = $"Information prompt pop-up window, automatically closes after {_delayTs} seconds" };
52+
Options4 = new ToastOption { Category = ToastCategory.Warning, Title = "Warning message", IsAutoHide = false, Content = $"Information prompt pop-up window, automatically closes after {_delayTs} seconds" };
4653

4754
ToastContainer = Root.ToastContainer;
4855
}
@@ -55,7 +62,7 @@ await ToastService.Show(new ToastOption()
5562
PreventDuplicates = true,
5663
Category = ToastCategory.Success,
5764
Title = "Successfully saved",
58-
Content = "Save data successfully, automatically close after 4 seconds"
65+
Content = $"Save data successfully, automatically close after {_delayTs} seconds"
5966
});
6067
}
6168

@@ -66,7 +73,7 @@ await ToastService.Show(new ToastOption()
6673
{
6774
Category = ToastCategory.Success,
6875
Title = "Successfully saved",
69-
Content = "Save data successfully, automatically close after 4 seconds"
76+
Content = $"Save data successfully, automatically close after {_delayTs} seconds"
7077
});
7178
}
7279

@@ -77,7 +84,7 @@ await ToastService.Show(new ToastOption()
7784
{
7885
Category = ToastCategory.Error,
7986
Title = "Failed to save",
80-
Content = "Failed to save data, automatically closes after 4 seconds"
87+
Content = $"Failed to save data, automatically closes after {_delayTs} seconds"
8188
});
8289
}
8390

@@ -88,7 +95,7 @@ await ToastService.Show(new ToastOption()
8895
{
8996
Category = ToastCategory.Information,
9097
Title = "Notification",
91-
Content = "The system adds new components, it will automatically shut down after 4 seconds"
98+
Content = $"The system adds new components, it will automatically shut down after {_delayTs} seconds"
9299
});
93100
}
94101

@@ -99,7 +106,7 @@ await ToastService.Show(new ToastOption()
99106
{
100107
Category = ToastCategory.Warning,
101108
Title = "Warning",
102-
Content = "If the system finds abnormality, please deal with it in time, and it will automatically shut down after 4 seconds"
109+
Content = $"If the system finds abnormality, please deal with it in time, and it will automatically shut down after {_delayTs} seconds"
103110
});
104111
}
105112

@@ -128,7 +135,7 @@ await ToastService.Show(new ToastOption()
128135
{
129136
Category = ToastCategory.Warning,
130137
ShowHeader = false,
131-
Content = "The system adds new components, it will automatically shut down after 4 seconds"
138+
Content = $"The system adds new components, it will automatically shut down after {_delayTs} seconds"
132139
});
133140
}
134141

@@ -139,7 +146,7 @@ await ToastService.Show(new ToastOption()
139146
{
140147
Category = ToastCategory.Information,
141148
HeaderTemplate = RenderHeader,
142-
Content = "The system adds new components, it will automatically shut down after 4 seconds"
149+
Content = $"The system adds new components, it will automatically shut down after {_delayTs} seconds"
143150
});
144151
}
145152

@@ -150,7 +157,7 @@ await ToastService.Show(new ToastOption()
150157
{
151158
Category = ToastCategory.Information,
152159
Title = "Notification",
153-
Content = "<b>Toast</b> The component has changed position, it will automatically shut down after 4 seconds"
160+
Content = $"<b>Toast</b> The component has changed position, it will automatically shut down after {_delayTs} seconds"
154161
});
155162
}
156163

0 commit comments

Comments
 (0)