All files / progressbar si-progressbar.component.ts

100% Statements 10/10
50% Branches 2/4
100% Functions 2/2
100% Lines 9/9

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                            1x                 37x             37x             37x         37x           37x             37x   37x 39x          
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { SiTranslatePipe, t, TranslatableString } from '@siemens/element-translate-ng/translate';
 
@Component({
  selector: 'si-progressbar',
  imports: [SiTranslatePipe],
  templateUrl: './si-progressbar.component.html',
  styleUrl: './si-progressbar.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SiProgressbarComponent {
  /**
   * Needed for a11y
   *
   * @defaultValue
   * ```
   * t(() => $localize`:@@SI_PROGRESSBAR.LABEL:Progress`)
   * ```
   */
  readonly ariaLabel = input(t(() => $localize`:@@SI_PROGRESSBAR.LABEL:Progress`));
 
  /**
   * Max value for progressbar
   *
   * @defaultValue 100
   */
  readonly max = input(100);
 
  /**
   * Current value
   *
   * @defaultValue 0
   */
  readonly value = input<number | undefined>(0);
 
  /**
   * Heading to display on top of progress bar.
   */
  readonly heading = input<TranslatableString>();
 
  /**
   * Optional progress text to be shown on top right (in LTR).
   * It can be percentage value or a progress status. E.g `50 %` or `Downloading 2/8`.
   */
  readonly progress = input<string>();
 
  /**
   * Height for progress bar.
   *
   * @defaultValue 'normal'
   */
  readonly height = input<ProgressbarHeight>('normal');
 
  protected readonly percent = computed(
    () => (100 * Number(this.value() ?? 0)) / Number(this.max() ?? 100)
  );
}
 
export type ProgressbarHeight = 'small' | 'normal';