ngx-bootstrap-alert.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { __decorate, __metadata } from 'tslib';
  2. import { Injectable, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, EventEmitter, NgModule } from '@angular/core';
  3. import { OnChange } from 'ngx-bootstrap/utils';
  4. import { CommonModule } from '@angular/common';
  5. /**
  6. * @fileoverview added by tsickle
  7. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  8. */
  9. var AlertConfig = /** @class */ (function () {
  10. function AlertConfig() {
  11. /**
  12. * default alert type
  13. */
  14. this.type = 'warning';
  15. /**
  16. * is alerts are dismissible by default
  17. */
  18. this.dismissible = false;
  19. /**
  20. * default time before alert will dismiss
  21. */
  22. this.dismissOnTimeout = undefined;
  23. }
  24. AlertConfig.decorators = [
  25. { type: Injectable }
  26. ];
  27. return AlertConfig;
  28. }());
  29. /**
  30. * @fileoverview added by tsickle
  31. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  32. */
  33. var AlertComponent = /** @class */ (function () {
  34. function AlertComponent(_config, changeDetection) {
  35. var _this = this;
  36. this.changeDetection = changeDetection;
  37. /**
  38. * Alert type.
  39. * Provides one of four bootstrap supported contextual classes:
  40. * `success`, `info`, `warning` and `danger`
  41. */
  42. this.type = 'warning';
  43. /**
  44. * If set, displays an inline "Close" button
  45. */
  46. this.dismissible = false;
  47. /**
  48. * Is alert visible
  49. */
  50. this.isOpen = true;
  51. /**
  52. * This event fires immediately after close instance method is called,
  53. * $event is an instance of Alert component.
  54. */
  55. this.onClose = new EventEmitter();
  56. /**
  57. * This event fires when alert closed, $event is an instance of Alert component
  58. */
  59. this.onClosed = new EventEmitter();
  60. this.classes = '';
  61. this.dismissibleChange = new EventEmitter();
  62. Object.assign(this, _config);
  63. this.dismissibleChange.subscribe((/**
  64. * @param {?} dismissible
  65. * @return {?}
  66. */
  67. function (dismissible) {
  68. _this.classes = _this.dismissible ? 'alert-dismissible' : '';
  69. _this.changeDetection.markForCheck();
  70. }));
  71. }
  72. /**
  73. * @return {?}
  74. */
  75. AlertComponent.prototype.ngOnInit = /**
  76. * @return {?}
  77. */
  78. function () {
  79. var _this = this;
  80. if (this.dismissOnTimeout) {
  81. // if dismissOnTimeout used as attr without binding, it will be a string
  82. setTimeout((/**
  83. * @return {?}
  84. */
  85. function () { return _this.close(); }), parseInt((/** @type {?} */ (this.dismissOnTimeout)), 10));
  86. }
  87. };
  88. // todo: animation ` If the .fade and .in classes are present on the element,
  89. // the alert will fade out before it is removed`
  90. /**
  91. * Closes an alert by removing it from the DOM.
  92. */
  93. // todo: animation ` If the .fade and .in classes are present on the element,
  94. // the alert will fade out before it is removed`
  95. /**
  96. * Closes an alert by removing it from the DOM.
  97. * @return {?}
  98. */
  99. AlertComponent.prototype.close =
  100. // todo: animation ` If the .fade and .in classes are present on the element,
  101. // the alert will fade out before it is removed`
  102. /**
  103. * Closes an alert by removing it from the DOM.
  104. * @return {?}
  105. */
  106. function () {
  107. if (!this.isOpen) {
  108. return;
  109. }
  110. this.onClose.emit(this);
  111. this.isOpen = false;
  112. this.changeDetection.markForCheck();
  113. this.onClosed.emit(this);
  114. };
  115. AlertComponent.decorators = [
  116. { type: Component, args: [{
  117. selector: 'alert,bs-alert',
  118. template: "<ng-template [ngIf]=\"isOpen\">\n <div [class]=\"'alert alert-' + type\" role=\"alert\" [ngClass]=\"classes\">\n <ng-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 </ng-template>\n <ng-content></ng-content>\n </div>\n</ng-template>\n",
  119. changeDetection: ChangeDetectionStrategy.OnPush
  120. }] }
  121. ];
  122. /** @nocollapse */
  123. AlertComponent.ctorParameters = function () { return [
  124. { type: AlertConfig },
  125. { type: ChangeDetectorRef }
  126. ]; };
  127. AlertComponent.propDecorators = {
  128. type: [{ type: Input }],
  129. dismissible: [{ type: Input }],
  130. dismissOnTimeout: [{ type: Input }],
  131. isOpen: [{ type: Input }],
  132. onClose: [{ type: Output }],
  133. onClosed: [{ type: Output }]
  134. };
  135. __decorate([
  136. OnChange(),
  137. __metadata("design:type", Object)
  138. ], AlertComponent.prototype, "dismissible", void 0);
  139. return AlertComponent;
  140. }());
  141. /**
  142. * @fileoverview added by tsickle
  143. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  144. */
  145. var AlertModule = /** @class */ (function () {
  146. function AlertModule() {
  147. }
  148. /**
  149. * @return {?}
  150. */
  151. AlertModule.forRoot = /**
  152. * @return {?}
  153. */
  154. function () {
  155. return { ngModule: AlertModule, providers: [AlertConfig] };
  156. };
  157. AlertModule.decorators = [
  158. { type: NgModule, args: [{
  159. imports: [CommonModule],
  160. declarations: [AlertComponent],
  161. exports: [AlertComponent],
  162. entryComponents: [AlertComponent]
  163. },] }
  164. ];
  165. return AlertModule;
  166. }());
  167. export { AlertComponent, AlertConfig, AlertModule };
  168. //# sourceMappingURL=ngx-bootstrap-alert.js.map