Sonner

Modern toast notifications — new in v0.3.0.

Sonner is new in v0.3.0. It provides shadcn-style stacked toast notifications via a SonnerService injectable service.

Installation

bash
shellui add sonner

sonner-variants and sonner-service are auto-installed as dependencies.

Usage

Inject SonnerService in any component:

@inject SonnerService SonnerService

<div class="flex flex-wrap gap-2">
    <Button @onclick='() => SonnerService.Show("Saved successfully!")'>Default</Button>
    <Button @onclick='() => SonnerService.Show("All done", variant: "success")'>Success</Button>
    <Button @onclick='() => SonnerService.Show("Something went wrong", variant: "destructive")'>Error</Button>
    <Button @onclick='() => SonnerService.Show("Update available", description: "A new version is ready to install.")'>With description</Button>
</div>

@* Usually placed once in MainLayout.razor *@
<Sonner />

Dismiss all toasts

@inject ISonnerService Sonner

<div class="flex gap-2">
    <Button OnClick="@(() => Sonner.Info("Heads up", "This toast stays until dismissed."))">Show toast</Button>
    <Button Variant="ButtonVariant.Ghost" OnClick="DismissAll">Dismiss all</Button>
</div>


@code {
    private void DismissAll()
    {
        foreach (var toast in Sonner.Toasts.ToList())
            Sonner.Remove(toast.Id);
    }
}

Setup

1. Register the service

In Program.cs:

csharp
using ShellUI.Components.Services;

builder.Services.AddSonner();

2. Add <Sonner> to your layout

Place it once at the top level, e.g. MainLayout.razor:

razor
@using ShellUI.Components

<main>@Body</main>

<Sonner Position="SonnerPosition.TopCenter" />

Position options

@* Bottom right (common for apps) *@
<Sonner Position="SonnerPosition.BottomRight" />

@* Top center (common for docs/alerts) *@
<Sonner Position="SonnerPosition.TopCenter" />

API Reference

<Sonner>

Parameter Type Default Description
Position SonnerPosition TopCenter Where toasts appear on screen

SonnerPosition enum

Value Position
TopLeft Top-left corner
TopCenter Top-center
TopRight Top-right corner
BottomLeft Bottom-left corner
BottomCenter Bottom-center
BottomRight Bottom-right corner

SonnerService methods

Method Description
Show(message, description?, variant?, duration?) Display a toast. variant defaults to "default"
Success(message, description?, duration?) Success toast
Error(message, description?, duration?) Error toast
Info(message, description?, duration?) Info toast
Warning(message, description?, duration?) Warning toast
Remove(id) Dismiss a specific toast by ID
Toasts The toasts currently shown; remove each one to dismiss all

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.