All files / card si-card.component.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8

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           69x           69x           69x               69x             69x       69x 40x      
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Component, computed, input } from '@angular/core';
import { MenuItem as MenuItemLegacy } from '@siemens/element-ng/common';
import {
  ContentActionBarMainItem,
  SiContentActionBarComponent,
  ViewType
} from '@siemens/element-ng/content-action-bar';
import { MenuItem } from '@siemens/element-ng/menu';
import { SiTranslatePipe, TranslatableString } from '@siemens/element-translate-ng/translate';
 
import { SiCardBaseDirective } from './si-card-base.directive';
 
@Component({
  selector: 'si-card',
  imports: [SiContentActionBarComponent, SiTranslatePipe],
  templateUrl: './si-card.component.html',
  styleUrl: './si-card.component.scss'
})
export class SiCardComponent extends SiCardBaseDirective {
  /**
   * Input list of primary action items. Supports up to **4** actions and omits additional ones.
   *
   * @defaultValue []
   */
  readonly primaryActions = input<(MenuItemLegacy | ContentActionBarMainItem)[]>([]);
  /**
   * Input list of secondary action items.
   *
   * @defaultValue []
   */
  readonly secondaryActions = input<(MenuItemLegacy | MenuItem)[]>([]);
  /**
   * A param that will be passed to the `action` in the primary/secondary actions.
   * This allows to re-use the same primary/secondary action arrays across rows
   * in a table.
   */
  readonly actionParam = input<any>();
  /**
   * The view type of the content action bar of the card. Default is `collapsible`
   * for dashboards. However, in some cases you might need to change to `expanded`
   * or `mobile`.
   *
   * @defaultValue 'collapsible'
   */
  readonly actionBarViewType = input<ViewType>('collapsible');
  /**
   * Optional setting of html title attribute for the content action bar.
   * Helpful for a11y when only one action is configured in expand mode.
   *
   * @defaultValue ''
   */
  readonly actionBarTitle = input<TranslatableString>('');
  /**
   * Returns `true` when primary or secondary actions are set.
   */
  readonly displayContentActionBar = computed(
    () => this.primaryActions()?.length > 0 || this.secondaryActions()?.length > 0
  );
}