All files / loading-spinner si-loading-spinner.component.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

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                              1x 1x                             1x 15x             15x             15x                 15x    
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { animate, style, transition, trigger } from '@angular/animations';
import {
  ChangeDetectionStrategy,
  Component,
  HostBinding,
  inject,
  InjectionToken,
  input
} from '@angular/core';
import { SiTranslatePipe, t } from '@siemens/element-translate-ng/translate';
 
export const LOADING_SPINNER_BLOCKING = new InjectionToken<boolean>('isBlockingSpinner');
export const LOADING_SPINNER_OVERLAY = new InjectionToken<boolean>('isSpinnerOverlay');
 
@Component({
  selector: 'si-loading-spinner',
  imports: [SiTranslatePipe],
  templateUrl: './si-loading-spinner.component.html',
  styleUrl: './si-loading-spinner.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
  animations: [
    trigger('fadeAnimation', [
      transition(':enter', [style({ opacity: 0 }), animate('200ms ease-in')]),
      transition(':leave', animate('200ms ease-out', style({ opacity: 0 })))
    ])
  ]
})
export class SiLoadingSpinnerComponent {
  @HostBinding('@fadeAnimation') protected fadeAnimation = '';
  /**
   * @defaultValue
   * ```
   * inject(LOADING_SPINNER_BLOCKING, { optional: true })
   * ```
   */
  readonly isBlockingSpinner = input(inject(LOADING_SPINNER_BLOCKING, { optional: true }));
  /**
   * @defaultValue
   * ```
   * inject(LOADING_SPINNER_OVERLAY, { optional: true })
   * ```
   */
  readonly isSpinnerOverlay = input(inject(LOADING_SPINNER_OVERLAY, { optional: true }));
  /**
   * Needed for a11y
   *
   * @defaultValue
   * ```
   * t(() => $localize`:@@SI_LOADING_SPINNER.LABEL:Loading`)
   * ```
   */
  readonly ariaLabel = input(t(() => $localize`:@@SI_LOADING_SPINNER.LABEL:Loading`));
}