All files / lib/accordion accordion-panel.component.ts

98.88% Statements 177/179
100% Branches 16/16
88.88% Functions 8/9
98.88% Lines 177/179

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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 1801x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 53x 53x 53x 53x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 16x 16x 16x 1x 1x 1x 1x 1x 14x 14x 14x 4x 14x 14x 14x 1x 1x 1x 10x 10x 1x 1x 1x 14x 14x 1x 1x 1x 1x 1x 1x 1x 14x 10x 14x 14x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  HostBinding,
  Input,
  Output,
  TemplateRef,
  ViewChild,
} from '@angular/core';
 
import { badgeListAsString } from '../utils/internal-utils';
import {
  BadgeItem,
  FocusableElementOwner,
  LinkItem,
} from '../utils/util.types';
import { createWidgetKeySet } from '../utils/utilities';
 
import { BadgeItemTemplateContext } from '../badge-list/badge-list.component';
import {
  DynamicHeadingLevelPassthroughService,
  DynamicHeadingLevelService,
} from '../dynamic-heading/dynamic-heading-level.service';
import { AccordionComponent } from './accordion.component';
 
/**
 * Accordion panel component that represents a single panel in the 'gc-accordion' component.
 */
@Component({
  selector: 'gc-accordion-panel',
  templateUrl: './accordion-panel.component.html',
  styleUrls: ['./accordion-panel.component.css'],
  providers: [DynamicHeadingLevelService],
  viewProviders: [
    {
      provide: DynamicHeadingLevelService,
      useClass: DynamicHeadingLevelPassthroughService,
    },
  ],
})
export class AccordionPanelComponent implements FocusableElementOwner {
  /**
   * Title of the top hint section. If set the top hint section will be shown.
   */
  @Input()
  public hintTitle = '';
 
  /**
   * List of elements that will be rendered as hint items at the top of the accordion panel.
   */
  @Input()
  public hintItems: readonly LinkItem[] = [];
 
  /**
   * Title shown in the header
   */
  @Input()
  public label = '';
 
  /**
   * Control if the section is expanded=true, collapsed=false
   */
  @HostBinding('class.gc-expanded')
  @Input()
  public expanded = true;
 
  /**
   * Badge items to display in the header
   */
  @Input()
  public badgeItems: readonly BadgeItem[] = [];
 
  /**
   * Icon provider for badge
   */
  @Input()
  public badgeIconProvider?: TemplateRef<BadgeItemTemplateContext>;
 
  /**
   * Internal API - if enabled the badges will be displayed in a new separate row instead wrapping with the label.
   * @ignore
   */
  @Input()
  public _badgesShownInSeparateRow = false;
 
  /**
   * Inform about the change of the expanded state
   */
  @Output()
  public readonly expandedChange: EventEmitter<boolean> =
    new EventEmitter<boolean>();
 
  /**
   * Internal API - allows to reuse the component in other controls and disables some styles, e.g. top borders.
   * @ignore
   */
  @Input()
  @HostBinding('class.gc-accordion-embedded')
  public _embedded = false;
 
  /** @ignore */
  @ViewChild('headerbutton')
  protected _headerButton!: ElementRef<HTMLButtonElement>;
 
  /** @ignore */
  public _parent?: AccordionComponent;
 
  /** @ignore */
  protected readonly sectionId: string;
 
  /** @ignore */
  protected readonly headerId: string;
 
  constructor() {
    const widgetKeys = createWidgetKeySet('gc-accordion-panel');
    this.sectionId = `${widgetKeys.baseKey}-content`;
    this.headerId = `${widgetKeys.baseKey}-header`;
  }
 
  public focusChild(): boolean {
    this._headerButton.nativeElement.focus();
    return true;
  }
 
  /**
   * @ignore
   * @deprecated use moveFocus
   */
  public _focus(): void {
    this._headerButton.nativeElement.focus();
  }
 
  /**
   * @ignore
   */
  protected _toggle(): void {
    this.expanded = !this.expanded;
    this.expandedChange.emit(this.expanded);
  }
 
  /**
   * @ignore
   */
  protected _handleKeyDown(event: KeyboardEvent): void {
    if (this._parent) {
      const action = this.mapAction(event.key);
      if (action !== undefined && this._parent._moveFocus(this, action)) {
        event.preventDefault();
      }
    }
  }
 
  /** @ignore */
  protected _badgeScreenReaderText(): string {
    return ' - ' + badgeListAsString(this.badgeItems);
  }
 
  /** @ignore */
  private mapAction(key: string) {
    switch (key) {
      case 'ArrowDown':
        return 'next';
      case 'ArrowUp':
        return 'previous';
      case 'End':
        return 'last';
      case 'Home':
        return 'first';
      default:
        return undefined;
    }
  }
}