Sonner

An opinionated toast component for Angular.

Installation

ng g @spartan-ng/cli:ui sonner

Add the HlmToaster component to your root component.

src/app/app.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';

import { HlmToasterImports } from '@spartan-ng/helm/sonner';

@Component({
  selector: 'app-root',
  imports: [RouterOutlet, HlmToasterImports],
  template: `
    <router-outlet />

    <hlm-toaster />
  `,
})
export class App {}

Angular 21 Compatibility

If you are using Angular 21+, the CDK overlay now defaults to using the popover attribute, which causes overlay-based components (sheets, dialogs, etc.) to always render above <hlm-toaster> . To fix this, add provideSpartanHlm() to your application config:

src/app/app.config.ts
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideSpartanHlm } from '@spartan-ng/helm/utils';

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideSpartanHlm(),
    // ... other providers
  ],
};

Usage

import { toast } from '@spartan-ng/brain/sonner';
toast('Event has been created.');

Examples

Types

Description

Position

Brain API

BrnSonnerIcon

Selector: brn-sonner-icon

Inputs

PropTypeDefaultDescription
type ToastTypes default -

BrnSonnerLoader

Selector: brn-sonner-loader

Inputs

PropTypeDefaultDescription
isVisible* (required) boolean --

BrnSonnerToast

Selector: brn-sonner-toast

Inputs

PropTypeDefaultDescription
toast* (required) ToastProps['toast'] --
index* (required) ToastProps['index'] --
expanded* (required) ToastProps['expanded'] --
invert* (required) ToastProps['invert'] --
position* (required) ToastProps['position'] --
visibleToasts* (required) ToastProps['visibleToasts'] --
expandByDefault* (required) ToastProps['expandByDefault'] --
closeButton* (required) ToastProps['closeButton'] --
interacting* (required) ToastProps['interacting'] --
cancelButtonStyle ToastProps['cancelButtonStyle'] --
actionButtonStyle ToastProps['actionButtonStyle'] --
duration ToastProps['duration'] this._config.toastLifetime -
descriptionClass ToastProps['descriptionClass'] --
classes ToastProps['classes'] {} -
unstyled ToastProps['unstyled'] false -
class unknown --
style Record<string, string> {} -

BrnSonnerToaster

Selector: brn-sonner-toaster

Inputs

PropTypeDefaultDescription
invert ToasterProps['invert'] false -
theme ToasterProps['theme'] light -
position ToasterProps['position'] bottom-right -
hotKey ToasterProps['hotkey'] [altKey, KeyT] -
richColors ToasterProps['richColors'] false -
expand ToasterProps['expand'] false -
duration ToasterProps['duration'] this._config.toastLifetime -
visibleToasts ToasterProps['visibleToasts'] this._config.visibleToastsAmount -
closeButton ToasterProps['closeButton'] false -
toastOptions ToasterProps['toastOptions'] {} -
offset ToasterProps['offset'] null -
class unknown --
style Record<string, string> {} -

Helm API

HlmToaster

Selector: hlm-toaster

Inputs

PropTypeDefaultDescription
invert ToasterProps['invert'] false -
theme ToasterProps['theme'] light -
position ToasterProps['position'] bottom-right -
hotKey ToasterProps['hotkey'] [altKey, KeyT] -
richColors ToasterProps['richColors'] false -
expand ToasterProps['expand'] false -
duration ToasterProps['duration'] 4000 -
visibleToasts ToasterProps['visibleToasts'] 3 -
closeButton ToasterProps['closeButton'] false -
toastOptions ToasterProps['toastOptions'] {} -
offset ToasterProps['offset'] null -
class ClassValue --
style Record<string, string> { --normal-bg: var(--popover), --normal-text: var(--popover-foreground), --normal-border: var(--border), --border-radius: var(--radius), } -
Spinner Slider