ngx-admin/src/app/pages/modal-overlays/toastr/toastr.component.ts
Evgeny Lupanov fbbf94448b
feat: upgrade to Angular 9 and Nebular 5 (#5628)
BREAKING CHANGE:
Angular updated to version 9.
Nebular updated to version 5.
`@agm/core` replaced with `@angular/google-maps`.
`ng2-completer` replaced with `@akveo/ng2-completer`, read details [here](https://github.com/akveo/ng2-smart-table/pull/1140#issue-392285957).
2020-03-30 12:06:51 +03:00

86 lines
2.2 KiB
TypeScript

import { Component } from '@angular/core';
import {
NbComponentStatus,
NbGlobalLogicalPosition,
NbGlobalPhysicalPosition,
NbGlobalPosition,
NbToastrService,
NbToastrConfig,
} from '@nebular/theme';
@Component({
selector: 'ngx-toastr',
styleUrls: ['./toastr.component.scss'],
templateUrl: './toastr.component.html',
})
export class ToastrComponent {
constructor(private toastrService: NbToastrService) {}
config: NbToastrConfig;
index = 1;
destroyByClick = true;
duration = 2000;
hasIcon = true;
position: NbGlobalPosition = NbGlobalPhysicalPosition.TOP_RIGHT;
preventDuplicates = false;
status: NbComponentStatus = 'primary';
title = 'HI there!';
content = `I'm cool toaster!`;
types: NbComponentStatus[] = [
'primary',
'success',
'info',
'warning',
'danger',
];
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 = this.types[typeIndex];
const quote = this.quotes[quoteIndex];
this.showToast(type, quote.title, quote.body);
}
private showToast(type: NbComponentStatus, 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);
}
}