ngx-bootstrap-alert.js 4.8 KB

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