All files / summary-chip si-summary-chip.component.ts

100% Statements 17/17
66.66% Branches 2/3
100% Functions 2/2
100% Lines 17/17

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                                                  1x 5x   5x   5x   5x   5x   5x   5x   5x         5x         5x         5x   5x 5x 5x                     2x 1x        
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { NgClass } from '@angular/common';
import {
  booleanAttribute,
  ChangeDetectionStrategy,
  Component,
  computed,
  inject,
  input,
  model
} from '@angular/core';
import { ExtendedStatusType } from '@siemens/element-ng/common';
import { SiIconComponent, STATUS_ICON_CONFIG } from '@siemens/element-ng/icon';
import { SiTranslatePipe, TranslatableString } from '@siemens/element-translate-ng/translate';
 
@Component({
  selector: 'si-summary-chip',
  imports: [NgClass, SiIconComponent, SiTranslatePipe],
  templateUrl: './si-summary-chip.component.html',
  styleUrl: './si-summary-chip.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SiSummaryChipComponent {
  private readonly statusIcons = inject(STATUS_ICON_CONFIG);
  /** Status. Alternatively, use {@link icon} and {@link color}. */
  readonly status = input<ExtendedStatusType>();
  /** Icon token, see {@link https://element.siemens.io/icons/element}. */
  readonly icon = input<string>();
  /** Color class, see {@link https://element.siemens.io/typography/#color-variants-classes}. */
  readonly color = input<string>();
  /** Icon token, see {@link https://element.siemens.io/fundamentals/icons/}. */
  readonly stackedIcon = input<string>();
  /** Color class, see {@link https://element.siemens.io/fundamentals/icons/}. */
  readonly stackedColor = input<string>();
  /** The label. */
  readonly label = input.required<TranslatableString>();
  /** Value to display. */
  readonly value = input.required<TranslatableString>();
  /**
   * Selected state, will change when clicked.
   * @defaultValue false
   */
  readonly selected = model(false);
  /**
   * Disabled state.
   * @defaultValue false
   */
  readonly disabled = input(false, { transform: booleanAttribute });
  /**
   * Whether to hide the label. The label will still be used for screen-readers.
   * @defaultValue false
   */
  readonly hideLabel = input(false, { transform: booleanAttribute });
 
  protected readonly statusIcon = computed(() => {
    const status = this.status();
    return status
      ? this.statusIcons[status]
      : {
          icon: this.icon(),
          color: this.color(),
          stacked: this.stackedIcon(),
          stackedColor: this.stackedColor()
        };
  });
 
  protected toggleSelected(): void {
    if (!this.disabled()) {
      this.selected.set(!this.selected());
    }
  }
}