Getting Started
UI
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Utilities
Forms
Stack
Sonner
An opinionated toast component for Angular.
import { Component } from '@angular/core';
import { toast } from '@spartan-ng/brain/sonner';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmToasterImports } from '@spartan-ng/helm/sonner';
@Component({
selector: 'spartan-sonner-preview',
imports: [HlmToasterImports, HlmButtonImports],
template: `
<hlm-toaster />
<button hlmBtn variant="outline" (click)="showToast()">Show Toast</button>
`,
})
export class SonnerPreview {
showToast() {
toast('Event has been created', {
description: 'Sunday, December 03, 2023 at 9:00 AM',
action: {
label: 'Undo',
onClick: () => console.log('Undo'),
},
});
}
}Installation
ng g @spartan-ng/cli:ui sonnernx 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
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { toast } from '@spartan-ng/brain/sonner';
import { HlmButtonImports } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-sonner-types-example',
imports: [HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="flex flex-wrap justify-center gap-2">
<button hlmBtn variant="outline" (click)="showToast()">Default</button>
<button hlmBtn variant="outline" (click)="showSuccess()">Success</button>
<button hlmBtn variant="outline" (click)="showInfo()">Info</button>
<button hlmBtn variant="outline" (click)="showError()">Error</button>
<button hlmBtn variant="outline" (click)="showWarning()">Warning</button>
<button hlmBtn variant="outline" (click)="showPromise()">Promise</button>
</div>
`,
})
export class SonnerTypesExample {
showToast() {
toast('Event has been created');
}
showSuccess() {
toast.success('Event has been created');
}
showError() {
toast.error('Failed to create event');
}
showWarning() {
toast.warning('Event is missing a name');
}
showInfo() {
toast.info('Event will start in 10 minutes');
}
showPromise() {
toast.promise<{ name: string }>(
() => new Promise((resolve) => setTimeout(() => resolve({ name: 'Angular Connect' }), 2000)),
{
loading: 'Loading...',
success: (data) => `${data.name} has been created`,
error: 'Error',
},
);
}
}Description
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { toast } from '@spartan-ng/brain/sonner';
import { HlmButtonImports } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-sonner-description-example',
imports: [HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<button hlmBtn variant="outline" (click)="showToast()">Show Toast</button>
`,
})
export class SonnerDescriptionExample {
showToast() {
toast('Event has been created', {
description: 'Monday, January 3rd at 6:00pm',
});
}
}Position
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { toast } from '@spartan-ng/brain/sonner';
import { HlmButtonImports } from '@spartan-ng/helm/button';
@Component({
selector: 'spartan-sonner-position-example',
imports: [HlmButtonImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="flex flex-wrap justify-center gap-2">
<button hlmBtn variant="outline" (click)="showTopLeft()">Top Left</button>
<button hlmBtn variant="outline" (click)="showTopCenter()">Top Center</button>
<button hlmBtn variant="outline" (click)="showTopRight()">Top Right</button>
<button hlmBtn variant="outline" (click)="showBottomLeft()">Bottom Left</button>
<button hlmBtn variant="outline" (click)="showBottomCenter()">Bottom Center</button>
<button hlmBtn variant="outline" (click)="showBottomRight()">Bottom Right</button>
</div>
`,
})
export class SonnerPositionExample {
showTopLeft() {
toast('Event has been created', {
position: 'top-left',
});
}
showTopCenter() {
toast('Event has been created', {
position: 'top-center',
});
}
showTopRight() {
toast('Event has been created', {
position: 'top-right',
});
}
showBottomLeft() {
toast('Event has been created', {
position: 'bottom-left',
});
}
showBottomCenter() {
toast('Event has been created', {
position: 'bottom-center',
});
}
showBottomRight() {
toast('Event has been created', {
position: 'bottom-right',
});
}
}Brain API
BrnSonnerIcon
Selector: brn-sonner-icon
ExportAs: brnSonnerIcon
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| type | ToastTypes | 'default' | - |
BrnSonnerLoader
Selector: brn-sonner-loader
ExportAs: brnSonnerLoader
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| isVisible* (required) | boolean | - | - |
BrnSonnerToast
Selector: li[brnSonnerToast]
ExportAs: brnSonnerToast
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| 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> | {} | - |
| actionTemplate | BrnToastAction | - | - |
| cancelActionTemplate | BrnToastCancelAction | - | - |
BrnSonnerToaster
Selector: brn-sonner-toaster
ExportAs: brnSonnerToaster
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| 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> | {} | - |
BrnToastAction
Selector: [brnToastAction]
ExportAs: toastAction
BrnToastCancelAction
Selector: [brnToastCancelAction]
ExportAs: toastCancelAction
Helm API
HlmToaster
Selector: hlm-toaster
ExportAs: hlmToaster
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| 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)', } | - |
On This Page
Stop configuring. Start shipping.
Zerops powers spartan.ng and Angular teams worldwide.
One-command deployment. Zero infrastructure headaches.
Deploy with Zerops