UNPKG

ngb-toast

Version:

This library was generated with [Angular CLI 9](https://github.com/angular/angular-cli).

154 lines (145 loc) 6.6 kB
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 = {})); var NgbToast = /** @class */ (function () { function NgbToast() { } return NgbToast; }()); var NgbToastService = /** @class */ (function () { function NgbToastService() { this.toastArray = []; this.toastSubject = new BehaviorSubject([]); } NgbToastService.prototype.getAllToasts = function () { return this.toastSubject.asObservable(); }; NgbToastService.prototype.show = function (toast) { this.toastArray.push(toast); this.toastSubject.next(this.toastArray); }; NgbToastService.prototype.remove = function (toast) { this.toastArray.splice(this.toastArray.findIndex(function (f) { return f == toast; }), 1); this.toastSubject.next(this.toastArray); }; NgbToastService = __decorate([ Injectable() ], NgbToastService); return NgbToastService; }()); var NgbToastContainer = /** @class */ (function () { function NgbToastContainer(ngbToastService) { this.ngbToastService = ngbToastService; this.toasts = []; } NgbToastContainer.prototype.ngOnInit = function () { var _this = this; this.ngbToastService.getAllToasts().subscribe(function (toasts) { _this.toasts = toasts.slice().reverse(); }); }; NgbToastContainer.ctorParameters = function () { return [ { 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); return NgbToastContainer; }()); var NgbToastComponent = /** @class */ (function () { function NgbToastComponent(ngbToastService) { this.ngbToastService = ngbToastService; this.isHidden = false; } NgbToastComponent.prototype.ngOnInit = function () { var _this = this; var time; if (this.toast.timeInSeconds) { time = this.toast.timeInSeconds * 1000; } else if (!this.toast.dismissible) { time = 3000; } if (time) { setTimeout(function () { _this.isHidden = true; if (_this.toast.onDismiss) _this.toast.onDismiss(); setTimeout(function () { _this.ngbToastService.remove(_this.toast); }, 500); }, time); } }; NgbToastComponent.prototype.dismiss = function () { var _this = this; this.isHidden = true; if (this.toast.onDismiss) this.toast.onDismiss(); setTimeout(function () { _this.ngbToastService.remove(_this.toast); }, 500); }; NgbToastComponent.ctorParameters = function () { return [ { 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); return NgbToastComponent; }()); var NgbToastModule = /** @class */ (function () { function NgbToastModule() { } NgbToastModule_1 = NgbToastModule; NgbToastModule.forRoot = function () { return { ngModule: NgbToastModule_1, providers: [NgbToastService] }; }; var NgbToastModule_1; NgbToastModule = NgbToastModule_1 = __decorate([ NgModule({ declarations: [ NgbToastContainer, NgbToastComponent ], imports: [ BrowserModule ], providers: [NgbToastService], exports: [ NgbToastContainer, ], }) ], NgbToastModule); return 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