All files / navbar-vertical si-navbar-vertical-item-legacy.component.ts

94.73% Statements 18/19
62.5% Branches 10/16
100% Functions 5/5
94.44% Lines 17/18

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                                                              1x 24x 24x 24x 24x   24x 8x 8x                 24x 28x 28x     24x 2x             24x 24x   12x   24x    
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Component, computed, inject, input, model, viewChildren } from '@angular/core';
import { MenuItem } from '@siemens/element-ng/common';
import { SiLinkDirective } from '@siemens/element-ng/link';
import { SiTranslatePipe } from '@siemens/element-translate-ng/translate';
 
import { SiNavbarVerticalGroupTriggerDirective } from './si-navbar-vertical-group-trigger.directive';
import { SiNavbarVerticalGroupComponent } from './si-navbar-vertical-group.component';
import { SiNavbarVerticalHeaderComponent } from './si-navbar-vertical-header.component';
import { SiNavbarVerticalItemComponent } from './si-navbar-vertical-item.component';
import { SI_NAVBAR_VERTICAL } from './si-navbar-vertical.provider';
 
@Component({
  selector: 'si-navbar-vertical-item-legacy',
  imports: [
    SiLinkDirective,
    SiTranslatePipe,
    SiNavbarVerticalItemComponent,
    SiNavbarVerticalGroupTriggerDirective,
    SiNavbarVerticalGroupComponent,
    SiNavbarVerticalHeaderComponent
  ],
  templateUrl: './si-navbar-vertical-item-legacy.component.html',
  styleUrl: './si-navbar-vertical-item-legacy.component.scss',
  host: {
    'class': 'd-block mb-4'
  }
})
export class SiNavbarVerticalItemLegacyComponent {
  readonly item = input.required<MenuItem>();
  readonly navbarExpandButtonText = input.required();
  readonly navbarCollapseButtonText = input.required();
  readonly expanded = model.required<boolean>();
 
  protected readonly flyoutItems = computed(() => {
    if (!this.navbar.collapsed()) {
      return this.item().items;
    } else E{
      return [
        this.isLink() ? { ...this.item(), items: undefined } : [],
        this.item().items ?? []
      ].flat();
    }
  });
 
  protected readonly isLink = computed(() => {
    const item = this.item();
    return !!item.action || !!item.link || !!item.href;
  });
 
  protected readonly toggleButtonLabel = computed(() =>
    this.navbar.collapsed()
      ? this.navbarExpandButtonText()
      : this.expanded()
        ? this.navbarCollapseButtonText()
        : this.navbarExpandButtonText()
  );
 
  protected readonly siLinks = viewChildren(SiLinkDirective);
  protected readonly itemActive = computed(
    () =>
      (this.navbar.collapsed() || !this.expanded()) && this.siLinks().some(link => link.active())
  );
  protected navbar = inject(SI_NAVBAR_VERTICAL);
}