mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 23:40:14 +01:00
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
|
|
import { Component } from '@angular/core';
|
||
|
|
import { ToasterConfig } from 'angular2-toaster';
|
||
|
|
|
||
|
|
import 'style-loader!angular2-toaster/toaster.css';
|
||
|
|
import { NbGlobalLogicalPosition, NbGlobalPhysicalPosition, NbGlobalPosition, NbToastrService } from '@nebular/theme';
|
||
|
|
import { NbToastStatus } from '@nebular/theme/components/toastr/model';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'ngx-toastr',
|
||
|
|
styleUrls: ['./toastr.component.scss'],
|
||
|
|
templateUrl: './toastr.component.html',
|
||
|
|
})
|
||
|
|
export class ToastrComponent {
|
||
|
|
constructor(private toastrService: NbToastrService) {}
|
||
|
|
|
||
|
|
config: ToasterConfig;
|
||
|
|
|
||
|
|
index = 1;
|
||
|
|
destroyByClick = true;
|
||
|
|
duration = 2000;
|
||
|
|
hasIcon = true;
|
||
|
|
position: NbGlobalPosition = NbGlobalPhysicalPosition.TOP_RIGHT;
|
||
|
|
preventDuplicates = false;
|
||
|
|
status: NbToastStatus = NbToastStatus.SUCCESS;
|
||
|
|
|
||
|
|
title = 'HI there!';
|
||
|
|
content = `I'm cool toaster!`;
|
||
|
|
|
||
|
|
types: NbToastStatus[] = [
|
||
|
|
NbToastStatus.DEFAULT,
|
||
|
|
NbToastStatus.DANGER,
|
||
|
|
NbToastStatus.INFO,
|
||
|
|
NbToastStatus.PRIMARY,
|
||
|
|
NbToastStatus.SUCCESS,
|
||
|
|
NbToastStatus.WARNING,
|
||
|
|
];
|
||
|
|
positions: string[] = [
|
||
|
|
NbGlobalPhysicalPosition.TOP_RIGHT,
|
||
|
|
NbGlobalPhysicalPosition.TOP_LEFT,
|
||
|
|
NbGlobalPhysicalPosition.BOTTOM_LEFT,
|
||
|
|
NbGlobalPhysicalPosition.BOTTOM_RIGHT,
|
||
|
|
NbGlobalLogicalPosition.TOP_END,
|
||
|
|
NbGlobalLogicalPosition.TOP_START,
|
||
|
|
NbGlobalLogicalPosition.BOTTOM_END,
|
||
|
|
NbGlobalLogicalPosition.BOTTOM_START,
|
||
|
|
];
|
||
|
|
|
||
|
|
quotes = [
|
||
|
|
{ title: null, body: 'We rock at Angular' },
|
||
|
|
{ title: null, body: 'Titles are not always needed' },
|
||
|
|
{ title: null, body: 'Toastr rock!' },
|
||
|
|
];
|
||
|
|
|
||
|
|
makeToast() {
|
||
|
|
this.showToast(this.status, this.title, this.content);
|
||
|
|
}
|
||
|
|
|
||
|
|
openRandomToast () {
|
||
|
|
const typeIndex = Math.floor(Math.random() * this.types.length);
|
||
|
|
const quoteIndex = Math.floor(Math.random() * this.quotes.length);
|
||
|
|
const type: NbToastStatus = this.types[typeIndex];
|
||
|
|
const quote = this.quotes[quoteIndex];
|
||
|
|
|
||
|
|
this.showToast(type, quote.title, quote.body);
|
||
|
|
}
|
||
|
|
|
||
|
|
private showToast(type: NbToastStatus, title: string, body: string) {
|
||
|
|
const config = {
|
||
|
|
status: type,
|
||
|
|
destroyByClick: this.destroyByClick,
|
||
|
|
duration: this.duration,
|
||
|
|
hasIcon: this.hasIcon,
|
||
|
|
position: this.position,
|
||
|
|
preventDuplicates: this.preventDuplicates,
|
||
|
|
};
|
||
|
|
const titleContent = title ? `. ${title}` : '';
|
||
|
|
|
||
|
|
this.index += 1;
|
||
|
|
this.toastrService.show(
|
||
|
|
body,
|
||
|
|
`Toast ${this.index}${titleContent}`,
|
||
|
|
config);
|
||
|
|
}
|
||
|
|
}
|