All files / lib/internal/hint hint.component.ts

98.11% Statements 104/106
100% Branches 12/12
85.71% Functions 6/7
98.11% Lines 104/106

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 1071x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  Input,
  NgZone,
  OnDestroy,
  QueryList,
  ViewChildren,
} from '@angular/core';
 
import { observeElementSize } from '../../utils/internal-utils';
import {
  Callback,
  FocusableElementOwner,
  LinkItem,
} from '../../utils/util.types';
 
import { LinkComponent } from '../../link/link.component';
 
/**
 * Hint component that is used to show hint messages in forms or accordions.
 */
@Component({
  selector: 'gc-hint',
  templateUrl: './hint.component.html',
  styleUrls: ['./hint.component.css'],
})
export class HintComponent implements OnDestroy, FocusableElementOwner {
  /**
   * Text that will be shown as the hint.
   */
  @Input()
  public label = '';
 
  /**
   * Additional abbreviated version of the (long) label, which is used to improve presentation
   * to accessibility technologies if present.
   */
  @Input()
  public shortLabel = '';
 
  /**
   * Decides if the passed content will be shown.
   */
  @Input()
  public items: readonly LinkItem[] = [];
 
  @ViewChildren(LinkComponent)
  public links?: QueryList<LinkComponent>;
 
  /** @ignore */
  public get _ariaSectionName(): string {
    return this.shortLabel ? `Hinweis: ${this.shortLabel}` : 'Hinweis';
  }
 
  /**
   * @ignore
   */
  public narrow = false;
 
  /** @ignore */
  private readonly resizeObserverCleanup: Callback;
 
  constructor(
    private el: ElementRef<HTMLElement>,
    zone: NgZone,
  ) {
    this.resizeObserverCleanup = observeElementSize(
      el.nativeElement,
      zone,
      this.resizeHandler.bind(this),
    );
  }
 
  /**
   * @ignore
   */
  ngOnDestroy(): void {
    this.resizeObserverCleanup();
  }
 
  focusChild(): boolean {
    if (this.links && this.links.length > 0) {
      return this.links.first.focusChild();
    }
    return false;
  }
 
  /**
   * @ignore
   */
  private resizeHandler(): void {
    const width = this.el.nativeElement.getBoundingClientRect().width;
 
    if (width < 400) {
      this.narrow = true;
    } else {
      this.narrow = false;
    }
  }
}