Skip to content

Commit d971eae

Browse files
NathanJPhillipsNathan Phillipsgvreddy04
authored
Add RenderFragment content to ToastMessage (#965)
* Add RenderFragment content to ToastMessage * Toasts demo updated. --------- Co-authored-by: Nathan Phillips <[email protected]> Co-authored-by: Vikram Reddy <[email protected]>
1 parent 535023e commit d971eae

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

BlazorBootstrap.Demo.RCL/Components/Pages/Toasts/ToastsDocumentation.razor

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<Demo Type="typeof(Toasts_Demo_02_Toast_Without_Title)" />
2929
</Section>
3030

31+
<Section Size="HeadingSize.H2" Name="Toast with templated content" PageUrl="@pageUrl" Link="toast-with-content">
32+
<Demo Type="typeof(Toasts_Demo_07_Toast_With_Content)" />
33+
</Section>
34+
3135
<Section Size="HeadingSize.H2" Name="Auto hide" PageUrl="@pageUrl" Link="auto-hide">
3236
<div>Add <code>AutoHide="true"</code> parameter to hide the Blazor Toasts after the delay. The default delay is 5000 milliseconds, be sure to update the delay timeout so that users have enough time to read the toast.</div>
3337
<Demo Type="typeof(Toasts_Demo_03_A_Auto_Hide)" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Toasts class="p-3" Messages="messages" />
2+
3+
<Button Class="btn btn-primary" @onclick="ShowToast">Toast with Content</Button>
4+
5+
@code {
6+
List<ToastMessage> messages = [];
7+
8+
private void ShowToast() =>
9+
messages.Add(
10+
new ToastMessage
11+
{
12+
Type = ToastType.Info,
13+
Title = "Blazor Bootstrap",
14+
Content = @<div>Hello, world! This is a toast message. <button class="btn btn-sm btn-primary mt-2" @onclick="ShowToast">Show more toast</button></div>,
15+
});
16+
}

blazorbootstrap/Components/Toasts/SimpleToast.razor

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<div class="d-flex">
77
<div class="toast-body">
88
@ToastMessage?.Message
9+
@ToastMessage?.Content
910
</div>
1011
@if (!AutoHide || ShowCloseButton)
1112
{

blazorbootstrap/Components/Toasts/Toast.razor

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</div>
1414
<div class="toast-body">
1515
@ToastMessage.Message
16+
@ToastMessage.Content
1617
</div>
1718
<Progress Height="3">
1819
<ProgressBar @ref="toastProgressBar" Color="@progressColor" Width="toastProgressBarWidth"/>

blazorbootstrap/Models/ToastMessage.cs

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public ToastMessage(ToastType type, string customIconName, string title, string
102102

103103
public string? Message { get; set; }
104104

105+
public RenderFragment? Content { get; set; }
106+
105107
public string? Title { get; set; }
106108

107109
public ToastType Type { get; set; }

0 commit comments

Comments
 (0)