Skip to content
Overlay Toast

Toast

Brief notifications, raised from .NET through IToastService.

On this page

Examples

Toasts

Razor
@inject IToastService Toasts

<div class="flex flex-wrap gap-2">
    <KlyButton Label="Show toast" OnClick="Saved" data-testid="toast-trigger" />
    <KlyButton Label="Show error" Color="KlyColor.Error" Variant="ButtonVariant.Soft" OnClick="Failed" />
</div>

@code {
    private async Task Saved() => await Toasts.Add(new KlyToast
    {
        Title = "Changes saved",
        Description = "Your profile is up to date.",
        Color = KlyColor.Success,
    });

    private async Task Failed() => await Toasts.Add(new KlyToast
    {
        Title = "Upload failed",
        Description = "The file is larger than 10 MB.",
        Color = KlyColor.Error,
        Duration = TimeSpan.FromSeconds(8),
    });
}

API

KlyToaster

Container that shows the toasts added through IToastService . KlyApp renders one for you.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Duration TimeSpan 00:00:05 How long a toast stays on screen when it does not set its own duration. Defaults to 5 seconds.
Ui ToastUi Per-instance class overrides of the slots of the toaster, see ToastUi . They are merged after the theme and the Class parameter wins on the root slot.

Ui slots

Ui takes a ToastUi with one class string per slot, merged after the theme.

Slot Styles
Viewport Classes merged into the viewport slot of KlyToaster , after the theme and the app configuration.
Root Classes merged into the root slot of KlyToaster , after the theme and the app configuration.
Wrapper Classes merged into the wrapper slot of KlyToaster , after the theme and the app configuration.
Title Classes merged into the title slot of KlyToaster , after the theme and the app configuration.
Description Classes merged into the description slot of KlyToaster , after the theme and the app configuration.
Close Classes merged into the close slot of KlyToaster , after the theme and the app configuration.