Skip to content

Commit

Permalink
Add RenderFragment content to ToastMessage (#965)
Browse files Browse the repository at this point in the history
* Add RenderFragment content to ToastMessage

* Toasts demo updated.

---------

Co-authored-by: Nathan Phillips <[email protected]>
Co-authored-by: Vikram Reddy <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 535023e commit d971eae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<Demo Type="typeof(Toasts_Demo_02_Toast_Without_Title)" />
</Section>

<Section Size="HeadingSize.H2" Name="Toast with templated content" PageUrl="@pageUrl" Link="toast-with-content">
<Demo Type="typeof(Toasts_Demo_07_Toast_With_Content)" />
</Section>

<Section Size="HeadingSize.H2" Name="Auto hide" PageUrl="@pageUrl" Link="auto-hide">
<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>
<Demo Type="typeof(Toasts_Demo_03_A_Auto_Hide)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Toasts class="p-3" Messages="messages" />

<Button Class="btn btn-primary" @onclick="ShowToast">Toast with Content</Button>

@code {
List<ToastMessage> messages = [];

private void ShowToast() =>
messages.Add(
new ToastMessage
{
Type = ToastType.Info,
Title = "Blazor Bootstrap",
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>,
});
}
1 change: 1 addition & 0 deletions blazorbootstrap/Components/Toasts/SimpleToast.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="d-flex">
<div class="toast-body">
@ToastMessage?.Message
@ToastMessage?.Content
</div>
@if (!AutoHide || ShowCloseButton)
{
Expand Down
1 change: 1 addition & 0 deletions blazorbootstrap/Components/Toasts/Toast.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</div>
<div class="toast-body">
@ToastMessage.Message
@ToastMessage.Content
</div>
<Progress Height="3">
<ProgressBar @ref="toastProgressBar" Color="@progressColor" Width="toastProgressBarWidth"/>
Expand Down
2 changes: 2 additions & 0 deletions blazorbootstrap/Models/ToastMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public ToastMessage(ToastType type, string customIconName, string title, string

public string? Message { get; set; }

public RenderFragment? Content { get; set; }

public string? Title { get; set; }

public ToastType Type { get; set; }
Expand Down

0 comments on commit d971eae

Please sign in to comment.