All files / lib/toggle-button-group toggle-button.component.ts

100% Statements 163/163
100% Branches 15/15
100% Functions 9/9
100% Lines 163/163

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 1641x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 132x 1x 1x 1x 132x 132x 44x 44x 44x 132x 132x 1x 1x 1x 1x 1x 23x 23x 23x 1x 1x 1x 1x 1x 15x 15x 15x 1x 1x 1x 1x 1x 14x 14x 14x 1x 1x 1x 1x 1x 10x 10x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  AfterViewInit,
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
} from '@angular/core';
 
import { WidgetKeySet } from '../utils/util.types';
import { createWidgetKeySet } from '../utils/utilities';
 
import { TooltipComponent } from '../internal/tooltip/tooltip.component';
 
/**
 * A Toggle Button component that allows the user to mark a value as selected.
 */
@Component({
  selector: 'gc-toggle-button',
  templateUrl: './toggle-button.component.html',
  styleUrls: [
    './../utils/styles/reset-button.css',
    './toggle-button.component.css',
  ],
})
export class ToggleButtonComponent implements AfterViewInit {
  /**
   * Label of the toggle button component.
   */
  @Input()
  public label = '';
 
  /**
   * Name of the toggle button group.
   */
  @Input()
  public groupName = '';
 
  /**
   * Decides if the toggle button is active/selected.
   */
  @Input()
  public value = false;
 
  /**
   * Key of the toggle button. Used for selecting the toggle button.
   */
  @Input()
  public key!: string;
 
  /**
   * Inform about the change of the selection state
   */
  @Output()
  public readonly valueChange: EventEmitter<boolean> =
    new EventEmitter<boolean>();
 
  /**
   * @ignore
   */
  @ViewChild('button')
  public _buttonElement!: ElementRef<HTMLButtonElement>;
 
  /**
   * @ignore
   */
  @ViewChild('tooltip')
  public _tooltip?: TooltipComponent;
 
  /**
   * @ignore
   */
  @Input()
  public _focused = false;
 
  /**
   * @ignore
   */
  @Input()
  public contentDisplay: 'icon-left' | 'icon-only' | 'text-only' = 'icon-left';
 
  /**
   * @ignore
   */
  @Input()
  public _isFirstInToggleButtonGroup = false;
 
  /**
   * @ignore
   */
  @Input()
  public _isLastInToggleButtonGroup = false;
 
  /**
   * @ignore
   */
  @Output()
  public readonly onFocusEntered: EventEmitter<void> = new EventEmitter<void>();
 
  /**
   * @ignore
   */
  @Output()
  public readonly onFocusLeft: EventEmitter<void> = new EventEmitter<void>();
 
  /**
   * @ignore
   */
  @Output()
  public readonly keyPressed: EventEmitter<KeyboardEvent> =
    new EventEmitter<KeyboardEvent>();
 
  /** @ignore */
  protected readonly widgetKeys: WidgetKeySet =
    createWidgetKeySet('gc-toggle-button');
 
  /** @ignore */
  ngAfterViewInit(): void {
    if (
      this._tooltip !== undefined &&
      this._tooltip.tooltipOwner !== this._buttonElement
    ) {
      this._tooltip.tooltipOwner = this._buttonElement;
    }
  }
 
  /**
   * @ignore
   */
  _handleFocus(): void {
    this._focused = true;
    this.onFocusEntered.emit();
  }
 
  /**
   * @ignore
   */
  _handleBlur(): void {
    this._focused = false;
    this.onFocusLeft.emit();
  }
 
  /**
   * @ignore
   */
  _handleClick(): void {
    this.value = true;
    this.valueChange.emit(this.value);
  }
 
  /**
   * @ignore
   */
  _handleKeyDown(event: KeyboardEvent): void {
    this.keyPressed.emit(event);
  }
}