All files / src/lib/wvr-alert wvr-alert.component.ts

100% Statements 14/14
100% Branches 2/2
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                        1x     8x     8x     8x     8x   8x     8x               1x 1x         8x 8x 4x 4x            
import { ChangeDetectionStrategy, Component, Injector, Input, OnInit } from '@angular/core';
import { WvrBaseComponent } from '../shared/wvr-base.component';
 
/**
 * A message display with contextualized styling.
 */
@Component({
  selector: 'wvr-alert-component',
  templateUrl: './wvr-alert.component.html',
  styleUrls: ['./wvr-alert.component.scss'],
  changeDetection: ChangeDetectionStrategy.Default
})
export class WvrAlertComponent extends WvrBaseComponent implements OnInit {
 
  /** Used to define the type of alert. */
  @Input() alertType: 'basic' | 'self-closing' | 'custom' = 'basic';
 
  /** Used to self close the alert box. */
  alertClosed = false;
 
  /** Used to display the Close button. */
  @Input() closeable: 'true' | 'false' = 'true';
 
  /** Setting the delay timer for the self closing alert message */
  @Input() closeTimer = 5000;
 
  variantTypes = ['alert'];
 
  constructor(injector: Injector) {
    super(injector);
  }
 
  /**
   * An event handle method for the `document:click` event.
   * Closes the alert box once the `X` is clicked.
   */
  clickClose($event: MouseEvent): void {
      this.alertClosed = true;
      this.themeVariant = 'primary';
  }
 
  /** Initializes the closing timer for a self closing alert. */
  ngOnInit(): void {
    super.ngOnInit();
    if (this.alertType === 'self-closing') {
      setTimeout(() => {
        this.alertClosed = true;
      }, this.closeTimer);
    }
  }
 
}