A Generic Toast Implementation for Blazor. You can choose a toast implementation as your wish.
See live demo
Package | Implementation | NuGet |
---|---|---|
Blazorius.Toast | Abstractions | |
Blazorius.Toast.Toastr | CodeSeven/toastr | |
Blazorius.Toast.NativeToast | egoist/native-toast | |
Blazorius.Toast.SiiimpleToast | gomonk3037/siiimple-toast |
- Add Nuget Package to your project.
Choose one of implementation like below: _
Install-Package Blazorius.Toast.Toastr -Version 1.0.1
Install-Package Blazorius.Toast.SiiimpleToast -Version 1.0.1
- Go your Startup.cs and add your Toast implementation:
Add one of implementation of toast like below: _
services.AddToastr(); // Add Toastr
services.AddSiiimpleToast(); // or SiiimpleToast
- You can customize default values:
public void ConfigureServices(IServiceCollection services)
{
services.AddToastr(builder =>
{
builder.Position = ToastPosition.BottomCenter;
builder.Type = ToastType.Success;
});
}
-
Go your view and add following using:
-
Inject
IToastManager
-
And use methods over IToastManager
@page "/"
@using Blazorius.Toast.Abstractions
@inject IToastManager Toast;
<button @onclick="ShowToast">Click me!</button>
@code {
async Task ShowToast()
{
await Toast.ShowAsync("Hello World!");
}
}