UNPKG

angular2-flash-message

Version:
56 lines (55 loc) 3.95 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require('@angular/core'); var flash_message_service_1 = require('./flash-message.service'); var lodash_1 = require('lodash'); var FlashMessagesComponent = (function () { function FlashMessagesComponent(flashMsgService, el) { var _this = this; this.flashMsgService = flashMsgService; this.el = el; this.readonly = DEFAULT_TIMEOUT = 6000; this.flashMsg = []; this.flashMsgService._flashMessage.subscribe(function (flashMsg) { _this.show(flashMsg); }); } FlashMessagesComponent.prototype.show = function (flashMsg) { var _this = this; if (!flashMsg) { return; } this.flashMsg.unshift(flashMsg); setTimeout(function () { _this.destroy(flashMsg.uuid); }, flashMsg.timeoutInMS ? flashMsg.timeoutInMS : this.DEFAULT_TIMEOUT); }; FlashMessagesComponent.prototype.destroy = function (uuid) { var flashMessageToRemove = lodash_1.findIndex(this.flashMsg, ['uuid', uuid]); if (flashMessageToRemove !== -1) { this.flashMsg.splice(flashMessageToRemove, 1); } }; __decorate([ core_1.Input('messagePositioning'), __metadata('design:type', String) ], FlashMessagesComponent.prototype, "messagePositioning", void 0); FlashMessagesComponent = __decorate([ core_1.Component({ selector: 'flash-message', template: "\n <div class=\"flash-messages\" [ngClass]=\"messagePositioning\">\n <div *ngFor=\"let msg of flashMsg\">\n <div class=\"alert\" *ngIf=\"msg.message\" [ngClass]=\"msg.isSuccess ? 'alert-success' : msg.isError\n ? 'alert-danger' : msg.isWarning ? 'alert-warning' : 'alert-info'\" [id]=\"msg.uuid\">\n <i (click)=\"destroy(msg.uuid)\" class=\"fa fa-close\" aria-hidden=\"true\"></i>\n <div>\n <p>{{msg.message}}</p>\n </div>\n </div>\n </div>\n </div>\n ", styles: ["\n .top-right {\n position: fixed;\n top: 75px;\n right: 29px;\n z-index: 1030;\n }\n \n .alert {\n min-width: 300px;\n max-width: 350px;\n min-height: 70px;\n max-height: 100px;\n }\n \n .alert > div {\n padding: 7px;\n }\n \n .alert i.fa-close {\n position: absolute;\n right: 8px;\n top: auto;\n margin-top: 2px;\n }\n \n .alert i.fa-close:hover {\n cursor: pointer;\n }\n "], }), __metadata('design:paramtypes', [flash_message_service_1.FlashMessageService, core_1.ElementRef]) ], FlashMessagesComponent); return FlashMessagesComponent; }()); exports.FlashMessagesComponent = FlashMessagesComponent;