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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 1x 1x 1x 4x 1x 1x 1x 2x | /** * Copyright (c) Siemens 2016 - 2025 * SPDX-License-Identifier: MIT */ import { A11yModule } from '@angular/cdk/a11y'; import { NgTemplateOutlet } from '@angular/common'; import { booleanAttribute, Component, input, OnChanges, output, signal, SimpleChanges, viewChild } from '@angular/core'; import { App, AppCategory, FavoriteChangeEvent, SiApplicationHeaderComponent, SiHeaderAccountItemComponent, SiHeaderActionsDirective, SiHeaderBrandDirective, SiHeaderCollapsibleActionsComponent, SiHeaderLogoDirective, SiHeaderNavigationComponent, SiHeaderNavigationItemComponent, SiLaunchpadFactoryComponent } from '@siemens/element-ng/application-header'; import { MenuItem } from '@siemens/element-ng/common'; import { HeaderWithDropdowns, SI_HEADER_WITH_DROPDOWNS, SiHeaderDropdownComponent, SiHeaderDropdownItemsFactoryComponent, SiHeaderDropdownTriggerDirective } from '@siemens/element-ng/header-dropdown'; import { Link, SiLinkDirective } from '@siemens/element-ng/link'; import { SiTranslatePipe, t } from '@siemens/element-translate-ng/translate'; import { defer } from 'rxjs'; import { AccountItem } from '../account.model'; import { AppItem, AppItemCategory } from './si-navbar-primary.model'; /** @deprecated Use the new `si-application-header` instead. */ @Component({ selector: 'si-navbar-primary', imports: [ A11yModule, NgTemplateOutlet, SiLinkDirective, SiTranslatePipe, SiApplicationHeaderComponent, SiLaunchpadFactoryComponent, SiHeaderAccountItemComponent, SiHeaderDropdownComponent, SiHeaderDropdownTriggerDirective, SiHeaderDropdownItemsFactoryComponent, SiHeaderNavigationItemComponent, SiHeaderBrandDirective, SiHeaderNavigationComponent, SiHeaderActionsDirective, SiHeaderCollapsibleActionsComponent, SiHeaderLogoDirective ], templateUrl: './si-navbar-primary.component.html', styles: ` .header-custom-logo { content: initial; inline-size: auto; } `, providers: [{ provide: SI_HEADER_WITH_DROPDOWNS, useExisting: SiNavbarPrimaryComponent }] }) export class SiNavbarPrimaryComponent implements OnChanges, HeaderWithDropdowns { /** * List of navbar items which should be displayed at the left (in LTR) side next to the * banner. * * @defaultValue [] */ readonly primaryItems = input<MenuItem[]>([]); /** * List of account dropdown elements (defined by `title` and `link`). * * The menu item can have submenu items (supplying `items`: MenuItem[]). * Submenu items can be divided into groups by separators. A separator is * an item with only '-' set as `title`. * * Alternatively, you can can create a custom content by putting your html * code between the <si-navbar-primary> tags. In this case you don't need this * property (will be ignored if you set anyway). */ readonly accountItems = input<MenuItem[]>(); /** * Account settings name (`title`) and profile picture (`image` or `icon`) */ readonly account = input<AccountItem>(); /** * URL of the navbar brand. */ readonly logoUrl = input<string>(); /** * Title of the application. */ readonly appTitle = input<string>(); /** * Configurable home link that is used at the logo and app title. * Use `undefined` to disable the link. * * @defaultValue * ``` * { link: '/' } * ``` */ readonly home = input<Link | undefined>({ link: '/' }); /** * title for the launchpad * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.TITLE:Launchpad`) * ``` */ readonly appSwitcherTitle = input(t(() => $localize`:@@SI_LAUNCHPAD.TITLE:Launchpad`)); /** * sub-title for the launchpad * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.SUB_TITLE:Access all your apps`) * ``` */ readonly appSwitcherSubTitle = input( t(() => $localize`:@@SI_LAUNCHPAD.SUB_TITLE:Access all your apps`) ); /** * Title or translate key for the favorite apps section. * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.FAVORITE_APPS:Favorite apps`) * ``` */ readonly favoriteAppsTitle = input( t(() => $localize`:@@SI_LAUNCHPAD.FAVORITE_APPS:Favorite apps`) ); /** * Title or translate key for the default apps section. * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.DEFAULT_CATEGORY_TITLE:Apps`) * ``` */ readonly defaultAppsTitle = input( t(() => $localize`:@@SI_LAUNCHPAD.DEFAULT_CATEGORY_TITLE:Apps`) ); /** * Title or translate key for the show more apps button. * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.SHOW_MORE:Show more`) * ``` */ readonly showMoreAppsTitle = input(t(() => $localize`:@@SI_LAUNCHPAD.SHOW_MORE:Show more`)); /** * Title or translate key for the show less apps button. * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.SHOW_LESS:Show less`) * ``` */ readonly showLessAppsTitle = input(t(() => $localize`:@@SI_LAUNCHPAD.SHOW_LESS:Show less`)); /** * All app items shown in the launchpad. The launchpad will not be visible if the * app items are undefined. The launchpad will be visible if the app items are an * empty array. */ readonly appItems = input<AppItem[]>(); /** * Like `appItems` but with the addition of categories. If this is set, `appItems` is ignored. */ readonly appCategoryItems = input<AppItemCategory[]>(); /** * Allow the user to favorite apps which will then be displayed at the top. * * @defaultValue false */ readonly appItemsFavorites = input(false, { transform: booleanAttribute }); /** * "all apps" link in the launchpad */ readonly allAppsLink = input<MenuItem>(); /** * Specifies whether the component should automatically be focused as soon as it is loaded. * * @defaultValue false */ readonly focusOnLoad = input(false, { transform: booleanAttribute }); /** * Marks the navbar as primary navigation element. Needed for a11y (screen reader). * Only one element should be primary. If multiple navbars are used, it's up to the * user of the components to label them in the correct order. * * @defaultValue 'Primary' */ readonly navAriaLabel = input('Primary'); /** * Text to close the launchpad. Needed for a11y. * * @defaultValue * ``` * t(() => $localize`:@@SI_LAUNCHPAD.CLOSE:Close launchpad`) * ``` */ readonly closeAppSwitcherText = input(t(() => $localize`:@@SI_LAUNCHPAD.CLOSE:Close launchpad`)); /** * Text for the launchpad icon. Needed for a11y. * * @defaultValue * ``` * t(() => $localize`:@@SI_NAVBAR.OPEN_LAUNCHPAD:Open launchpad`) * ``` */ readonly openAppSwitcherText = input( t(() => $localize`:@@SI_NAVBAR.OPEN_LAUNCHPAD:Open launchpad`) ); /** * Text or translate key for the toggle navigation icon. Needed for a11y. * * @defaultValue * ``` * t(() => $localize`:@@SI_NAVBAR.TOGGLE_NAVIGATION:Toggle navigation`) * ``` */ readonly toggleNavigationText = input( t(() => $localize`:@@SI_NAVBAR.TOGGLE_NAVIGATION:Toggle navigation`) ); /** * Aria label for the main menu landmark * * @defaultValue 'Header main' */ readonly ariaLabelMainMenu = input('Header main'); /** * Aria label for the secondary menu landmark * * @defaultValue 'Header secondary' */ readonly ariaLabelSecondaryMenu = input('Header secondary'); readonly appItemFavoriteChanged = output<[AppItem, boolean]>(); /** @internal */ readonly header = viewChild.required(SiApplicationHeaderComponent); /** @internal */ readonly collapsibleActions = viewChild(SiHeaderCollapsibleActionsComponent); /** @internal */ readonly navItemCount = signal(0); protected newAppItems?: App[] | AppCategory[]; protected active?: MenuItem; /** @internal */ // defer is required as header is not available at the time of creation.` readonly inlineDropdown = defer(() => this.header().inlineDropdown); /** @internal */ onDropdownItemTriggered(): void { this.header().onDropdownItemTriggered(); } /** @internal */ ngOnChanges(changes: SimpleChanges): void { if (changes.appItems || changes.appCategoryItems) { const appItems = this.appItems(); const appCategoryItems = this.appCategoryItems(); if (appCategoryItems) { this.newAppItems = appCategoryItems.map(category => ({ // Violation by intention. // Empty strings should also be replaced by the default title. // We rely on this in our examples, so projects might as well. // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing name: category.category || this.defaultAppsTitle(), apps: this.convertApps(category.items) })); const allAppsLink = this.allAppsLink(); Iif (allAppsLink && this.newAppItems.length) { const lastCategory = this.newAppItems.at(-1)!; lastCategory.apps.push({ name: allAppsLink.title!, iconClass: allAppsLink.icon ?? 'element-plus', href: allAppsLink.href!, target: allAppsLink.target, _noFavorite: true // this should not show up in public API, but we need it for now. } as App); } } else if (appItems) { this.newAppItems = this.convertApps(appItems!); const allAppsLink = this.allAppsLink(); Iif (allAppsLink) { this.newAppItems.push({ name: allAppsLink.title!, iconClass: allAppsLink.icon ?? 'element-plus', href: allAppsLink.href!, target: allAppsLink.target, _noFavorite: true // this should not show up in public API, but we need it for now. } as App); } } } } private convertApps(apps: AppItem[]): App[] { return apps.map(app => ({ name: app.title!, href: app.href!, external: app.isExternal, active: app.isActive, target: app.target, iconClass: app.icon, favorite: app.isFavorite, _src: app // this should not show up in public API, but we need it for now. })); } protected onFavoriteChange({ app, favorite }: FavoriteChangeEvent): void { this.appItemFavoriteChanged.emit([(app as any)._src, favorite]); } } |