UNPKG

3.83 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 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;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7var __metadata = (this && this.__metadata) || function (k, v) {
8 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9};
10import { Component, EventEmitter, Input, Output } from '@angular/core';
11import { AlertConfig } from './alert.config';
12import { OnChange } from '../utils/decorators';
13export var AlertComponent = (function () {
14 function AlertComponent(_config) {
15 var _this = this;
16 /** Alert type. Provides one of four bootstrap supported contextual classes: `success`, `info`, `warning` and `danger` */
17 this.type = 'warning';
18 /** If set, displays an inline "Close" button */
19 this.dismissible = false;
20 /** This event fires immediately after close instance method is called, $event is an instance of Alert component. */
21 this.onClose = new EventEmitter();
22 /** This event fires when alert closed, $event is an instance of Alert component */
23 this.onClosed = new EventEmitter();
24 this.isClosed = false;
25 this.classes = '';
26 this.dismissibleChange = new EventEmitter();
27 Object.assign(this, _config);
28 this.dismissibleChange.subscribe(function (dismissible) {
29 _this.classes = _this.dismissible ? 'alert-dismissible' : '';
30 });
31 }
32 AlertComponent.prototype.ngOnInit = function () {
33 var _this = this;
34 if (this.dismissOnTimeout) {
35 // if dismissOnTimeout used as attr without binding, it will be a string
36 setTimeout(function () { return _this.close(); }, parseInt(this.dismissOnTimeout, 10));
37 }
38 };
39 // todo: animation ` If the .fade and .in classes are present on the element,
40 // the alert will fade out before it is removed`
41 /**
42 * Closes an alert by removing it from the DOM.
43 */
44 AlertComponent.prototype.close = function () {
45 if (this.isClosed) {
46 return;
47 }
48 this.onClose.emit(this);
49 this.isClosed = true;
50 this.onClosed.emit(this);
51 };
52 AlertComponent.decorators = [
53 { type: Component, args: [{
54 selector: 'alert,ngx-alert',
55 template: "\n<template [ngIf]=\"!isClosed\">\n <div [class]=\"'alert alert-' + type\" role=\"alert\" [ngClass]=\"classes\">\n <template [ngIf]=\"dismissible\">\n <button type=\"button\" class=\"close\" aria-label=\"Close\" (click)=\"close()\">\n <span aria-hidden=\"true\">&times;</span>\n <span class=\"sr-only\">Close</span>\n </button>\n </template>\n <ng-content></ng-content>\n </div>\n</template>\n "
56 },] },
57 ];
58 /** @nocollapse */
59 AlertComponent.ctorParameters = function () { return [
60 { type: AlertConfig, },
61 ]; };
62 AlertComponent.propDecorators = {
63 'type': [{ type: Input },],
64 'dismissible': [{ type: Input },],
65 'dismissOnTimeout': [{ type: Input },],
66 'onClose': [{ type: Output },],
67 'onClosed': [{ type: Output },],
68 };
69 __decorate([
70 OnChange(),
71 __metadata('design:type', Boolean)
72 ], AlertComponent.prototype, "dismissible", void 0);
73 return AlertComponent;
74}());
75//# sourceMappingURL=alert.component.js.map
\No newline at end of file