Sonner
An opinionated toast component for Angular.
import { Component } from '@angular/core';
import { toast } from 'ngx-sonner';
import { HlmToasterComponent } from '@spartan-ng/ui-sonner-helm';
import { HlmButtonDirective } from '@spartan-ng/ui-button-helm';
@Component({
selector: 'spartan-sonner-preview',
standalone: true,
imports: [HlmToasterComponent, HlmButtonDirective],
template: `
<hlm-toaster />
<button hlmBtn (click)="showToast()">Show Toast</button>
`,
})
export class SonnerPreviewComponent {
showToast() {
toast('Event has been created', {
description: 'Sunday, December 03, 2024 at 9:00 AM',
action: {
label: 'Undo',
onClick: () => console.log('Undo'),
}
})
}
}
Installation
npx nx g @spartan-ng/cli:ui sonner
ng g @spartan-ng/cli:ui sonner
Usage
import { toast } from 'ngx-sonner';
import { HlmToasterComponent } from '@spartan-ng/ui-sonner-helm';
<hlm-toaster />
<button (click)="toast('Hello world')">Show Toast</button>