File

projects/isy-angular-widgets/src/lib/seitentoolbar/seitentoolbar.component.ts

Description

Represents a toolbar component that can be used to insert a toolbar at the top of the page.

Responsive behaviour

Responsive behaviour is disabled by default and enabled through the responsive attribute. At a screen width of 320px or less, the visible label of the home/back button is hidden while the icon and the accessible label are kept. Without responsive the visible label remains in place even on narrow screens.

Example :
<isy-seiten-toolbar
  responsive
  [showSidebar]="true"
  sidebarHomeButtonLabel="Zurück"
  sidebarHomeButtonAriaLabel="Zurück zur Übersicht"
/>

Metadata

Index

Properties
Methods
Inputs
Accessors

Inputs

responsive
Type : boolean
Default value : false

Determines whether responsive behavior is enabled.

showSidebar
Type : boolean
Default value : false

Determines whether to show or hide the Seitentoolbar, a sticky toolbar at the top of the screen.

sidebarHomeButtonAriaLabel
Type : string

Accessible label for the home button.

sidebarHomeButtonLabel
Type : string

Label for the home button.

sidebarHomeRoute
Type : string
Default value : '/'

Route for the home button.

Methods

Async navigateHome
navigateHome()

Method to navigate to the homeRoute.

Returns : Promise<void>

A promise that resolves when the navigation is complete.

Properties

Protected Readonly configService
Type : unknown
Default value : inject(WidgetsConfigService)

A service used to translate labels within the widgets library.

Accessors

effectiveSidebarHomeButtonAriaLabel
geteffectiveSidebarHomeButtonAriaLabel()

Returns the accessible label for the home button.

Returns : string
import {booleanAttribute, Component, inject, Input} from '@angular/core';
import {Router, RouterModule} from '@angular/router';
import {ButtonModule} from 'primeng/button';
import {ToolbarModule} from 'primeng/toolbar';
import {WidgetsConfigService} from '../i18n/widgets-config.service';

/**
 * Represents a toolbar component that can be used to insert a toolbar at the top of the page.
 *
 * ## Responsive behaviour
 *
 * Responsive behaviour is disabled by default and enabled through the `responsive` attribute.
 * At a screen width of `320px` or less, the visible label of the home/back button is hidden
 * while the icon and the accessible label are kept. Without `responsive` the visible label
 * remains in place even on narrow screens.
 * @example
 * ```html
 * <isy-seiten-toolbar
 *   responsive
 *   [showSidebar]="true"
 *   sidebarHomeButtonLabel="Zurück"
 *   sidebarHomeButtonAriaLabel="Zurück zur Übersicht"
 * />
 * ```
 */
@Component({
  standalone: true,
  selector: 'isy-seiten-toolbar',
  templateUrl: './seitentoolbar.component.html',
  styleUrls: ['./seitentoolbar.component.scss'],
  imports: [ToolbarModule, ButtonModule, RouterModule]
})
export class SeitentoolbarComponent {
  /**
   * Determines whether to show or hide the Seitentoolbar, a sticky toolbar at the top of the screen.
   */
  @Input() showSidebar: boolean = false;

  /**
   * Determines whether responsive behavior is enabled.
   */
  @Input({transform: booleanAttribute}) responsive: boolean = false;

  /**
   * Label for the home button.
   */
  @Input() sidebarHomeButtonLabel?: string;

  /**
   * Accessible label for the home button.
   */
  @Input() sidebarHomeButtonAriaLabel?: string;

  /**
   * Route for the home button.
   */
  @Input() sidebarHomeRoute: string = '/';

  private readonly router = inject(Router);

  /**
   * A service used to translate labels within the widgets library.
   */
  protected readonly configService = inject(WidgetsConfigService);

  /**
   * Returns the accessible label for the home button.
   * @returns The effective accessible label for the home button.
   */
  get effectiveSidebarHomeButtonAriaLabel(): string {
    return (
      this.sidebarHomeButtonAriaLabel ??
      this.sidebarHomeButtonLabel ??
      this.configService.getTranslation('seitentoolbar.back')
    );
  }

  /**
   * Method to navigate to the homeRoute.
   * @returns A promise that resolves when the navigation is complete.
   */
  async navigateHome(): Promise<void> {
    await this.router.navigate([this.sidebarHomeRoute]);
  }
}
@if (showSidebar) {
  <p-toolbar class="dont-print" [class.isy-seiten-toolbar-responsive]="responsive">
    <div class="p-toolbar-left">
      <p-button
        class="isy-seiten-toolbar-home-button"
        [link]="true"
        [label]="sidebarHomeButtonLabel"
        [ariaLabel]="effectiveSidebarHomeButtonAriaLabel"
        icon="pi pi-arrow-circle-left"
        (onClick)="navigateHome()"
      />
    </div>
    <div class="p-toolbar-middle">
      <ng-content select="[middle]"></ng-content>
    </div>
    <div class="p-toolbar-right">
      <ng-content select="[right]"></ng-content>
    </div>
  </p-toolbar>
}

./seitentoolbar.component.scss

::ng-deep isy-seiten-toolbar {
  position: sticky;
  top: 0;
  z-index: 9;

  .p-toolbar {
    background-color: var(--isyfact-surface-section);
  }

  @media (max-width: 320px) {
    .isy-seiten-toolbar-responsive {
      .isy-seiten-toolbar-home-button {
        .p-button {
          border: 1px solid currentColor;
          border-radius: var(--p-button-border-radius);
          background: transparent;
        }

        .p-button-label {
          display: none;
        }

        .p-button-icon {
          margin: 0;
        }
      }
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""