UNPKG

ng2-alert-center

Version:

Alert center provides an alert service and an alert component, you can include in your Angular 2 project.

1 lines 5.16 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs/Subject"),require("@angular/animations"),require("@angular/common")):"function"==typeof define&&define.amd?define(["exports","@angular/core","rxjs/Subject","@angular/animations","@angular/common"],e):e((t.ng=t.ng||{},t.ng.alert=t.ng.alert||{},t.ng.alert.center={}),t.ng.core,t.Rx,t.ng.animations,t.ng.common)}(this,function(t,e,n,i,r){"use strict";var s=function(){function t(){this._alerts=new n.Subject}return Object.defineProperty(t.prototype,"alerts",{get:function(){return this._alerts},enumerable:!0,configurable:!0}),t.prototype.alert=function(t){console.log("sending alert: "+JSON.stringify(t)),this._alerts.next(t)},t}();s.decorators=[{type:e.Injectable}],s.ctorParameters=function(){return[]};var a=function(){function t(t){this.alertCenterService=t,this.animation="none",this.htmlTextEnabled=!1,this.alerts=[]}return t.prototype.ngOnInit=function(){var t=this;this.alertSubscription=this.alertCenterService.alerts.subscribe(function(e){t.alerts.unshift(e)})},t.prototype.ngOnDestroy=function(){this.alertSubscription.unsubscribe()},t.prototype.getAlerts=function(){return this.alerts},t.prototype.remove=function(t){this.alerts.indexOf(t)>=0&&this.alerts.splice(this.alerts.indexOf(t),1)},t.prototype.getAnimation=function(){return this.animation},t}();a.decorators=[{type:e.Component,args:[{selector:"nac-alert-center",template:'\n <div class="alert-list">\n <div *ngFor="let alert of getAlerts()" [@animation]="getAnimation()" >\n <nac-alert [alert]="alert" [htmlTextEnabled]="htmlTextEnabled" (dismissed)="remove(alert)"></nac-alert>\n </div>\n </div>\n ',animations:[i.trigger("animation",[i.state("none",i.style({})),i.state("decent",i.style([{opacity:1},{maxHeight:300}])),i.state("fancy",i.style([{transform:"translateX(0)"},{transform:"translateY(0)"},{opacity:1},{maxHeight:300}])),i.transition("void => fancy",[i.style({opacity:0,maxHeight:0,transform:"translateY(-100%)"}),i.animate("300ms ease-in-out")]),i.transition("fancy => void",[i.animate("300ms ease-in-out",i.style({transform:"translateX(100%)",height:0,opacity:0}))]),i.transition("void => decent",[i.style({opacity:0,maxHeight:0}),i.animate("300ms ease-in-out")]),i.transition("decent => void",[i.animate("300ms ease-in-out",i.style({height:0,opacity:0}))])])]}]}],a.ctorParameters=function(){return[{type:s}]},a.propDecorators={animation:[{type:e.Input}],htmlTextEnabled:[{type:e.Input}]};var o=function(){function t(t,e,n,i,r){void 0===n&&(n=""),void 0===i&&(i=0),void 0===r&&(r=!0),this.alertType=t,this.text=e,this.textStrong=n,this.autoDismissTime=i,this.dismissable=r}return t.create=function(e,n,i,r){return void 0===i&&(i=0),void 0===r&&(r=!0),new t(e,n,"",i,r)},t.prototype.isDismissable=function(){return 0===this.autoDismissTime||this.dismissable},t.prototype.isAutoDismissing=function(){return this.autoDismissTime>0},t}();!function(t){t[t.SUCCESS=0]="SUCCESS",t[t.INFO=1]="INFO",t[t.WARNING=2]="WARNING",t[t.DANGER=3]="DANGER"}(t.AlertType||(t.AlertType={}));var l=function(){function n(){this.alert=new o(t.AlertType.INFO,"",""),this.htmlTextEnabled=!1,this.dismissed=new e.EventEmitter}return n.prototype.ngOnInit=function(){this.initTimerIfNeeded()},n.prototype.isSuccess=function(){return this.alert.alertType===t.AlertType.SUCCESS},n.prototype.isInfo=function(){return this.alert.alertType===t.AlertType.INFO},n.prototype.isWarning=function(){return this.alert.alertType===t.AlertType.WARNING},n.prototype.isDanger=function(){return this.alert.alertType===t.AlertType.DANGER},n.prototype.dismiss=function(){this.dismissed.emit()},n.prototype.isDismissEnabled=function(){return this.alert.isDismissable()},n.prototype.isTextStrongDefined=function(){return this.alert.textStrong&&this.alert.textStrong.length>0},n.prototype.initTimerIfNeeded=function(){var t=this;this.alert.isAutoDismissing()&&setTimeout(function(){return t.dismiss()},this.alert.autoDismissTime)},n}();l.decorators=[{type:e.Component,args:[{selector:"nac-alert",template:'\n <div class="alert"\n [class.alert-success]="isSuccess()"\n [class.alert-info]="isInfo()"\n [class.alert-warning]="isWarning()"\n [class.alert-danger]="isDanger()">\n <button *ngIf="isDismissEnabled()" type="button" class="close" data-dismiss="alert" aria-label="Close" (click)="dismiss()">\n <span aria-hidden="true">&times;</span>\n </button>\n <strong *ngIf="isTextStrongDefined()">{{alert.textStrong}}</strong><span *ngIf="!htmlTextEnabled">{{alert.text}}</span>\n <span *ngIf="htmlTextEnabled" [innerHtml]="alert.text"></span>\n </div>\n '}]}],l.ctorParameters=function(){return[]},l.propDecorators={alert:[{type:e.Input}],htmlTextEnabled:[{type:e.Input}],dismissed:[{type:e.Output}]};var u=function(){return function(){}}();u.decorators=[{type:e.NgModule,args:[{declarations:[a,l],providers:[s],imports:[r.CommonModule],exports:[a]}]}],u.ctorParameters=function(){return[]},t.AlertCenterModule=u,t.Alert=o,t.AlertCenterService=s,t.AlertCenterComponent=a,Object.defineProperty(t,"__esModule",{value:!0})});