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

88.88% Statements 8/9
66.66% Branches 2/3
100% Functions 1/1
88.88% Lines 8/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                                        1x         65x         65x         65x   65x   65x         65x     23x          
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { NgClass } from '@angular/common';
import { booleanAttribute, ChangeDetectionStrategy, Component, input } from '@angular/core';
import { SiTranslatePipe, TranslatableString } from '@siemens/element-translate-ng/translate';
 
import { SiLoadingSpinnerComponent } from './si-loading-spinner.component';
 
@Component({
  selector: 'si-loading-button',
  imports: [SiLoadingSpinnerComponent, NgClass, SiTranslatePipe],
  templateUrl: './si-loading-button.component.html',
  styleUrl: './si-loading-button.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    '[class.pe-none]': 'disabled()'
  }
})
export class SiLoadingButtonComponent {
  /**
   * Whether the button is disabled.
   * @defaultValue false
   */
  readonly disabled = input(false, { transform: booleanAttribute });
  /**
   * Whether the loading state should be displayed.
   * @defaultValue false
   */
  readonly loading = input(false, { transform: booleanAttribute });
  /**
   * Type of the button.
   * @defaultValue 'button'
   **/
  readonly type = input<'button' | 'submit' | 'reset'>('button');
  /** aria-label for the button */
  readonly ariaLabel = input<TranslatableString>();
  /** aria-labelledby for the button */
  readonly ariaLabelledBy = input<string>();
  /**
   * CSS class for the button.
   * @defaultValue ''
   */
  readonly buttonClass = input('');
 
  protected handleClick(event: Event): void {
    Iif (this.disabled() || this.loading()) {
      event.stopPropagation();
    }
  }
}