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

96.71% Statements 147/152
90% Branches 9/10
85.71% Functions 6/7
96.71% Lines 147/152

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 1531x 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 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 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 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 31x   31x 31x 31x 1x 1x 1x 1x 1x 6x 6x 6x 6x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  AfterViewInit,
  Component,
  ElementRef,
  EventEmitter,
  Input,
  NgZone,
  OnDestroy,
  Output,
  TemplateRef,
  ViewChild,
} from '@angular/core';
 
import { ActionEvent } from '../utils/event.types';
import { badgeListAsString, observeSize } from '../utils/internal-utils';
import {
  BadgeItem,
  Callback,
  FocusableElementOwner,
} from '../utils/util.types';
 
import { ButtonComponent } from '../button/button.component';
 
/**
 * `gc-component-group` is a container component that wraps around other components and marks it's area with a border.
 */
@Component({
  selector: 'gc-component-group',
  templateUrl: './component-group.component.html',
  styleUrls: ['./component-group.component.css'],
})
export class ComponentGroupComponent
  implements AfterViewInit, OnDestroy, FocusableElementOwner
{
  /**
   * Label of the group.
   */
  @Input()
  public label = '';
 
  /**
   * Decides if the button is shown or not.
   */
  @Input()
  public showButton = false;
 
  /**
   * Decides if the component group is deactivated or not.
   */
  @Input()
  public deactivated = false;
 
  /**
   * Badge items to display in the header
   */
  @Input()
  public badgeItems: readonly BadgeItem[] = [];
 
  /**
   * Icon provider for badge
   */
  @Input()
  public badgeIconProvider?: TemplateRef<unknown>;
 
  /**
   * The method that gets fired when the button is pressed.
   */
  @Output()
  public readonly onAction: EventEmitter<ActionEvent> =
    new EventEmitter<ActionEvent>();
 
  /**
   * @ignore
   */
  @ViewChild('content')
  private contentElement!: ElementRef<HTMLDivElement>;
 
  /**
   * @ignore
   */
  @ViewChild('removeButton', { read: ButtonComponent })
  private removeButton?: ButtonComponent;
 
  /**
   * @ignore
   */
  public _titleIsTooNarrow = false;
 
  /**
   * @ignore
   */
  private resizeObserver?: Callback;
 
  constructor(private zone: NgZone) {}
 
  /**
   * @ignore
   */
  ngAfterViewInit(): void {
    this.resizeObserver = observeSize(
      this.contentElement,
      this.zone,
      this.resizeCallback.bind(this),
    );
  }
 
  /**
   * @ignore
   */
  ngOnDestroy(): void {
    if (this.resizeObserver) {
      this.resizeObserver();
    }
  }
 
  public focusChild(): boolean {
    if (this.removeButton) {
      return this.removeButton.focusChild();
    } else {
      return false;
    }
  }
 
  /**
   * @ignore
   */
  _onButtonPress(event: ActionEvent): void {
    this.onAction.emit(event);
  }
 
  /** @ignore */
  _badgeLegendText() {
    if (this.badgeItems.length > 0) {
      return ', ' + badgeListAsString(this.badgeItems);
    }
    return '';
  }
 
  /**
   * @ignore
   */
  private resizeCallback(): void {
    // 148 === padding of title with icon-right button
    this._titleIsTooNarrow =
      this.contentElement.nativeElement.clientWidth - 148 < 200;
  }
}