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

93.8% Statements 106/113
88.23% Branches 15/17
90% Functions 9/10
93.8% Lines 106/113

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 1141x 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 1x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 1x 1x 1x 167x 167x 1x 1x 5x 5x 5x     5x 1x 1x 1x 370x 370x 370x 370x 1x 1x 1x 74x 74x 1x 1x 1x         1x 1x 1x 74x 74x   74x 1x 1x 1x 1x 1x 45x 45x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import { Component, ElementRef, Input, ViewChild } from '@angular/core';
 
import { LinkEvent } from '../../utils/event.types';
import {
  Consumer,
  FocusableElementOwner,
  FormattedTextContent,
  Item,
  LinkItem,
} from '../../utils/util.types';
import { itemTrack } from '../../utils/utilities';
 
export type FormattedDescription = FormattedTextContent | string;
 
/**
 * 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'],
  standalone: false,
})
export class HintComponent implements FocusableElementOwner {
  /**
   * @ignore
   */
  @ViewChild('focusContainer')
  public focusContainer?: ElementRef<HTMLElement>;
 
  /**
   * 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[] = [];
 
  /**
   * Optional content block that can contain a string or an array of strings and/or formatted text.
   * If an array is provided, each entry is rendered in a separate div element.
   */
  @Input()
  public description: readonly FormattedDescription[] | string = '';
 
  /**
   * Optional handler to customize handling of navigation requests
   */
  @Input()
  public linkHandler?: Consumer<LinkEvent>;
 
  /** @ignore */
  protected get _ariaSectionName(): string {
    return this.shortLabel ? `Hinweis: ${this.shortLabel}` : 'Hinweis';
  }
 
  focusChild(): boolean {
    if (this.focusContainer) {
      this.focusContainer.nativeElement.focus();
      return true;
    }
    return false;
  }
 
  /** @ignore */
  protected _isFormattedType(
    content: FormattedDescription | string,
  ): content is Exclude<FormattedDescription, string> {
    return typeof content !== 'string';
  }
 
  /** @ignore */
  protected _isSingleValuedDescription() {
    return typeof this.description === 'string';
  }
 
  /** @ignore */
  protected _singleValueDescription(): string {
    return typeof this.description === 'string'
      ? this.description
      : 'ERROR: multi valued';
  }
 
  /** @ignore */
  protected _multiValueDescription(): readonly FormattedDescription[] {
    return typeof this.description !== 'string'
      ? this.description
      : ['ERROR: single valued'];
  }
 
  /**
   * @ignore
   */
  protected _itemTrackBy(item: Item): string {
    return itemTrack(item);
  }
}