ngb-toast
Version:
This library was generated with [Angular CLI 9](https://github.com/angular/angular-cli).
141 lines (132 loc) • 5.67 kB
JavaScript
import { __decorate } from 'tslib';
import { Injectable, Component, Input, NgModule } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { BrowserModule } from '@angular/platform-browser';
var NgbToastType;
(function (NgbToastType) {
NgbToastType["Success"] = "tSuccess";
NgbToastType["Info"] = "tInfo";
NgbToastType["Warning"] = "tWarning";
NgbToastType["Danger"] = "tDanger";
NgbToastType["Primary"] = "tPrimary";
NgbToastType["Secondary"] = "tSecondary";
NgbToastType["Light"] = "tLight";
NgbToastType["Dark"] = "tDark";
})(NgbToastType || (NgbToastType = {}));
class NgbToast {
}
let NgbToastService = class NgbToastService {
constructor() {
this.toastArray = [];
this.toastSubject = new BehaviorSubject([]);
}
getAllToasts() {
return this.toastSubject.asObservable();
}
show(toast) {
this.toastArray.push(toast);
this.toastSubject.next(this.toastArray);
}
remove(toast) {
this.toastArray.splice(this.toastArray.findIndex((f) => f == toast), 1);
this.toastSubject.next(this.toastArray);
}
};
NgbToastService = __decorate([
Injectable()
], NgbToastService);
let NgbToastContainer = class NgbToastContainer {
constructor(ngbToastService) {
this.ngbToastService = ngbToastService;
this.toasts = [];
}
ngOnInit() {
this.ngbToastService.getAllToasts().subscribe((toasts) => {
this.toasts = toasts.slice().reverse();
});
}
};
NgbToastContainer.ctorParameters = () => [
{ type: NgbToastService }
];
NgbToastContainer = __decorate([
Component({
selector: 'ngb-toast-container',
template: "<ngb-toast-component *ngFor=\"let toast of toasts\" [toast]=\"toast\"></ngb-toast-component>",
styles: [":host{position:fixed;top:0;right:0;margin:.5em;z-index:1000}"]
})
], NgbToastContainer);
let NgbToastComponent = class NgbToastComponent {
constructor(ngbToastService) {
this.ngbToastService = ngbToastService;
this.isHidden = false;
}
ngOnInit() {
let time;
if (this.toast.timeInSeconds) {
time = this.toast.timeInSeconds * 1000;
}
else if (!this.toast.dismissible) {
time = 3000;
}
if (time) {
setTimeout(() => {
this.isHidden = true;
if (this.toast.onDismiss)
this.toast.onDismiss();
setTimeout(() => { this.ngbToastService.remove(this.toast); }, 500);
}, time);
}
}
dismiss() {
this.isHidden = true;
if (this.toast.onDismiss)
this.toast.onDismiss();
setTimeout(() => { this.ngbToastService.remove(this.toast); }, 500);
}
};
NgbToastComponent.ctorParameters = () => [
{ type: NgbToastService }
];
__decorate([
Input()
], NgbToastComponent.prototype, "toast", void 0);
NgbToastComponent = __decorate([
Component({
selector: 'ngb-toast-component',
template: "<div class=\"ngb-toast-container\" class=\"{{toast.toastType}}\" [ngClass]=\"{ 'dismissible' : toast.dismissible, 'hideToast': isHidden }\">\r\n {{toast.text}}\r\n <button type=\"button\" *ngIf=\"toast.dismissible\" (click)=\"dismiss()\" class=\"closebtn\" aria-label=\"Close\">\r\n <span aria-hidden=\"true\">x</span>\r\n </button>\r\n</div>",
styles: [".ngb-toast-container{position:relative;padding:.75rem 1.25rem;margin-bottom:1rem;border:1px solid transparent;border-radius:.25rem;width:40vw;visibility:visible;opacity:1;transition-delay:0s}.hideToast{visibility:hidden;opacity:0;transition:visibility linear .5s,opacity .5s linear}.tSuccess{color:#155724;background-color:#d4edda;border-color:#c3e6cb}.tInfo{color:#0c5460;background-color:#d1ecf1;border-color:#bee5eb}.tWarning{color:#856404;background-color:#fff3cd;border-color:#ffeeba}.tDanger{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb}.tPrimary{color:#004085;background-color:#cce5ff;border-color:#b8daff}.tSecondary{color:#383d41;background-color:#e2e3e5;border-color:#d6d8db}.tLight{color:#818182;background-color:#fefefe;border-color:#fdfdfe}.tDark{color:#1b1e21;background-color:#d6d8d9;border-color:#c6c8ca}.dismissible{padding-right:4rem}.closebtn{position:absolute;top:0;right:0;padding:.75rem 1.25rem;float:right;font-size:1.5em;line-height:1;color:#000;text-shadow:0 1px 0 #fff;opacity:.5}[type=button]:not(:disabled),button:not(:disabled){cursor:pointer;display:inline-block;text-align:center;align-items:flex-start}button.closebtn{background-color:transparent;border:0;-webkit-appearance:none}button:focus{border:none!important}"]
})
], NgbToastComponent);
var NgbToastModule_1;
let NgbToastModule = NgbToastModule_1 = class NgbToastModule {
static forRoot() {
return {
ngModule: NgbToastModule_1,
providers: [NgbToastService]
};
}
};
NgbToastModule = NgbToastModule_1 = __decorate([
NgModule({
declarations: [
NgbToastContainer,
NgbToastComponent
],
imports: [
BrowserModule
],
providers: [NgbToastService],
exports: [
NgbToastContainer,
],
})
], NgbToastModule);
/*
* Public API Surface of toast
*/
/**
* Generated bundle index. Do not edit.
*/
export { NgbToast, NgbToastContainer, NgbToastModule, NgbToastService, NgbToastType, NgbToastComponent as ɵa };
//# sourceMappingURL=ngb-toast.js.map