/// /// Copyright 2015-2026 Micro Focus or one of its affiliates. /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// import { NgTemplateOutlet, NgClass } from '@angular/common'; import { ChangeDetectionStrategy, Component, ContentChild, inject, Input, TemplateRef, } from '@angular/core'; import { getIconType } from '../../common/index'; import { TabbableListItemDirective } from '../../directives/accessibility/tabbable-list/tabbable-list-item.directive'; import { TabbableListDirective } from '../../directives/accessibility/tabbable-list/tabbable-list.directive'; import { IconComponent } from '../icon/icon.component'; import { NavigationItem } from './navigation-item.interface'; import { NavigationLinkDirective } from './navigation-link/navigation-link.directive'; import { NavigationService } from './navigation.service'; @Component({ selector: 'ux-navigation', templateUrl: './navigation.component.html', providers: [NavigationService], changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, imports: [ TabbableListDirective, NgTemplateOutlet, NavigationLinkDirective, TabbableListItemDirective, NgClass, IconComponent, ], }) export class NavigationComponent { private readonly _navigationService = inject(NavigationService); /** The navigation items to populate the menu with. */ @Input() set items(items: NavigationItem[]) { this._navigationService.items = items; } get items(): NavigationItem[] { return this._navigationService.items; } /** Whether to present the menu as a hierarchical tree. */ @Input() tree: boolean = true; /** Whether to collapse other menu items when expanding a menu item. */ @Input() set autoCollapse(autoCollapse: boolean) { this._navigationService.autoCollapse = autoCollapse; } /** Access a custom navigation item template if provided */ @ContentChild('uxNavigationItem', { static: false }) navigationItemTemplate: TemplateRef; /** The classes to be added to each different level */ _hierarchyClasses = [ '', 'nav-second-level', 'nav-third-level', 'nav-fourth-level', 'nav-fifth-level', ]; get _depthLimit(): number { return this.tree ? this._hierarchyClasses.length : 2; } /** * Returns true if the sets of items needs to be indented to make room for one or more expander. */ _needsIndent(items: NavigationItem[]): boolean { return items && items.some(item => item.children && item.children.length > 0); } /** Determine the type of icon to display. We support `ux-icon` or `component` */ _getIconType(item: NavigationItem): string { return getIconType(item.icon); } }