Lightweight, fast, and easy-to-use toast notifications for Blazor applications.
-
Install the
ToostNuGet package.dotnet add package Toost
-
In your
Program.cs, register the Toost service.builder.Services.AddToost();
-
Add the
<Toosts />component to your main layout file (e.g.,MainLayout.razororApp.razor).<Toosts @rendermode="InteractiveServer" />
-
Inject
ToostServiceinto the component or page where you want to show a toast.@inject ToostService ToostService
-
Call one of the methods on the
ToostServiceto show a toast.ToostService.Success("This is a success message!"); ToostService.Info("This is an info message."); ToostService.Warning("This is a warning message."); ToostService.Error("This is an error message.");
Each method accepts an optional duration parameter in milliseconds (default is 5000ms).
You can configure the titles for each toast type by providing an Action<ToostOptions> when you register the service.
builder.Services.AddToostServices(options =>
{
options.Titles[AlertType.Success] = "Great!";
options.Titles[AlertType.Error] = "Oops!";
});You can also configure the position of the toasts by setting the Position parameter on the Toosts component.
<Toosts @rendermode="InteractiveServer" Position="Position.TopLeft" />Available positions:
TopRightTopLeftBottomRight(default)BottomLeftTopCenterBottomCenter
You can also show the time the toast was created by setting the ShowTime parameter to true.
<Toosts ShowTime="true" />