Sonner
An opin./ionated toast component for Angular.
import { Component } from '@angular/core';
import { HlmButton } from '@spartan-ng/helm/button';
import { HlmToaster } from '@spartan-ng/helm/sonner';
import { toast } from 'ngx-sonner';
@Component({
selector: 'spartan-sonner-preview',
imports: [HlmToaster, HlmButton],
template: `
<hlm-toaster />
<button hlmBtn (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'),
},
});
}
}
About
Sonner is built on top of ngx-sonner by @tutkli .
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/helm/sonner';
<hlm-toaster />
<button hlmBtn (click)="showToast()">Show Toast</button>
Helm API
HlmToaster
Selector: hlm-toaster
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'] | { classes: { toast: group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg, description: group-[.toast]:text-muted-foreground, actionButton: group-[.toast]:bg-primary group-[.toast]:text-primary-foreground, cancelButton: group-[.toast]:bg-muted group-[.toast]:text-muted-foreground, }, } | - |
offset | ToasterProps['offset'] | null | - |
dir | ToasterProps['dir'] | auto | - |
class | ClassValue | - | - |
style | Record<string, string> | {} | - |