ManuHub.Blazor.Toast is a Blazor component for displaying Bootstrap-based toast notifications with customizable types and positions.
- Fully integrated with Bootstrap toasts
- Supports different toast types (Success, Error, Info, Warning, Default)
- Customizable toast positions (Top-Right, Top-Left, Bottom-Right, Bottom-Left, Center, etc.)
- JavaScript interop for seamless toast display
- Compatible with Blazor Server, WebAssembly (WASM), and Hybrid apps
Install the NuGet package:
dotnet add package ManuHub.Blazor.Toast
In Program.cs
, add the toast service:
using ManuHub.Blazor.Toast;
builder.Services.AddBlazorToast();
In wwwroot/index.html
(Blazor WASM) or Pages/_Host.cshtml
(Blazor Server),
or App.razor
(Blazor Server), add:
<script src="lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
In _Imports.razor
, add:
@using ManuHub.Blazor.Toast
@inject IToastService ToastService
In MainLayout.razor
, include the <Toast/>
component:
<ToastBS />
In Home.razor
, use the ToastService
to trigger notifications:
@page "/"
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
<button class="btn btn-primary" @onclick="ShowToast">Show Toast</button>
<button class="btn btn-danger" @onclick="ShowSecondToast">Show Error Toast</button>
@code{
public async Task ShowToast()
{
await ToastService.Show(title: "Hello", message: "Sample Notification.", timestamp: "now");
}
public async Task ShowSecondToast()
{
await ToastService.Show(title: "Error", message: "Something went wrong!", timestamp: "now",
type: ToastType.Error, position: ToastPosition.TopCenter);
}
}
ToastType.Default // Light Toast
ToastType.Success // Green Success Toast
ToastType.Error // Red Error Toast
ToastType.Warning // Yellow Warning Toast
ToastType.Info // Blue Info Toast
ToastPosition.BottomLeft // Bottom Left
ToastPosition.BottomRight // Bottom Right
ToastPosition.BottomCenter // Bottom Center
ToastPosition.Center // Center of Screen
ToastPosition.TopLeft // Top Left
ToastPosition.TopRight // Top Right
ToastPosition.TopCenter // Top Center
Feel free to submit issues or pull requests to improve the package!