File

src/modules/action-bar/components/action-bar.component.ts

Description

Component to display the application's action bars

Extends

AbstractStarkUiComponent

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs

Constructor

Public constructor(logger: StarkLoggingService, renderer: Renderer2, elementRef: ElementRef)

Class constructor

Parameters :
Name Type Optional Description
logger StarkLoggingService No
  • The StarkLoggingService instance of the application.
renderer Renderer2 No
  • Angular Renderer2 wrapper for DOM manipulations.
elementRef ElementRef No
  • Reference to the DOM element where this component is attached to.

Inputs

actionBarConfig
Type : StarkActionBarConfig
Default value : { actions: [] }

StarkActionBarConfig object.

actionBarId
Type : string
Default value : ""

HTML id of action bar component.

actionBarScope
Type : any

If provided, this object will be passed as parameter in every action call defined

alternativeActions
Type : StarkAction[]

Alternative actions

buttonColor
Type : StarkActionBarButtonColor | string
Default value : "primary"

Default color of the buttons

mode
Type : StarkActionBarComponentMode
Default value : "full"

Desired layout or flavour:

  • full: full featured action bar with labels, expanded view, etc...
  • compact: minimalistic layout with icons only.
color
Type : string
Inherited from AbstractStarkUiComponent

Color theme

Methods

Public ngOnInit
ngOnInit()
Inherited from AbstractStarkUiComponent

Component lifecycle hook

Returns : void
Public onClick
onClick(action: StarkAction, $event: Event)

Action onClick handler

Parameters :
Name Type Optional Description
action StarkAction No
$event Event No
  • The handled event
Returns : void
Public toggleExtendedActionBar
toggleExtendedActionBar()

toggle the extended action in full mode

Returns : void

Properties

Public isExtended
Default value : false

status of the extended action in full mode

Public logger
Type : StarkLoggingService
Decorators :
@Inject(STARK_LOGGING_SERVICE)
- The `StarkLoggingService` instance of the application.
import { ChangeDetectionStrategy, Component, ElementRef, Inject, Input, OnInit, Renderer2, ViewEncapsulation } from "@angular/core";
import { StarkActionBarConfig } from "./action-bar-config.intf";
import { StarkAction, StarkActionBarButtonColor } from "./action.intf";
import { STARK_LOGGING_SERVICE, StarkLoggingService } from "@nationalbankbelgium/stark-core";
import { AbstractStarkUiComponent } from "@nationalbankbelgium/stark-ui/src/internal-common";

export type StarkActionBarComponentMode = "full" | "compact";

/**
 * @ignore
 */
const componentName = "stark-action-bar";

/**
 * Component to display the application's action bars
 */
@Component({
	selector: "stark-action-bar",
	templateUrl: "./action-bar.component.html",
	encapsulation: ViewEncapsulation.None,
	changeDetection: ChangeDetectionStrategy.OnPush,
	// We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
	host: {
		class: componentName
	}
})
export class StarkActionBarComponent extends AbstractStarkUiComponent implements OnInit {
	/**
	 * HTML id of action bar component.
	 */
	@Input()
	public actionBarId = "";

	/**
	 * StarkActionBarConfig object.
	 */
	@Input()
	public actionBarConfig: StarkActionBarConfig = { actions: [] };

	/**
	 * If provided, this object will be passed as parameter in every
	 * action call defined
	 */
	@Input()
	public actionBarScope?: any;

	/**
	 * Alternative actions
	 */
	@Input()
	public alternativeActions?: StarkAction[];

	/**
	 * Default color of the buttons
	 */
	@Input()
	public buttonColor: StarkActionBarButtonColor | string = "primary";

	/**
	 * Desired layout or flavour:
	 *    - full: full featured action bar with labels, expanded view, etc...
	 *    - compact: minimalistic layout with icons only.
	 */
	@Input()
	public mode: StarkActionBarComponentMode = "full";

	/**
	 * status of the extended action in full mode
	 */
	public isExtended = false;

	/**
	 * Class constructor
	 * @param logger - The `StarkLoggingService` instance of the application.
	 * @param renderer - Angular `Renderer2` wrapper for DOM manipulations.
	 * @param elementRef - Reference to the DOM element where this component is attached to.
	 */
	public constructor(
		@Inject(STARK_LOGGING_SERVICE) public logger: StarkLoggingService,
		renderer: Renderer2,
		elementRef: ElementRef
	) {
		super(renderer, elementRef);
	}

	/**
	 * Component lifecycle hook
	 */
	public override ngOnInit(): void {
		super.ngOnInit();
		this.logger.debug(componentName + ": component initialized");
	}

	/**
	 * toggle the extended action in full mode
	 */
	public toggleExtendedActionBar(): void {
		this.isExtended = !this.isExtended;
	}

	/**
	 * Action onClick handler
	 * @param action - {@link StarkAction} object
	 * @param $event - The handled event
	 */
	public onClick(action: StarkAction, $event: Event): void {
		if ($event) {
			// Prevents further propagation of the current event in the capturing and bubbling phases.
			// This makes it so that the parent does not also trigger on the event.
			$event.stopPropagation();
		}
		if (action.isEnabled) {
			let scope: any = {};
			if (this.actionBarScope) {
				scope = this.actionBarScope;
			}
			action.actionCall($event, scope);
		}
	}

	/**
	 * Returns action icon based on `action.iconSwitchFunction()` state
	 * @param action - {@link StarkAction} object
	 * @ignore
	 */
	public getActionIcon(action: StarkAction): string {
		if (!!action.iconSwitchFunction && action.iconSwitchFunction()) {
			return <string>action.iconActivated;
		}
		return action.icon;
	}

	/**
	 * Returns action icon based on `action.iconSwitchFunction()` state
	 * @param action - {@link StarkAction} object
	 * @ignore
	 */
	public getActionLabel(action: StarkAction): string {
		if (!!action.labelSwitchFunction && action.labelSwitchFunction()) {
			return <string>action.labelActivated;
		}
		return action.label;
	}

	/**
	 * @ignore
	 */
	public trackAction(_index: number, action: StarkAction): string {
		return action.id;
	}
}
<div
	*ngIf="actionBarConfig.isPresent === undefined || actionBarConfig.isPresent === true"
	class="stark-action-bar"
	[ngClass]="{ extended: isExtended, 'stark-action-bar-full': mode === 'full', 'stark-action-bar-compact': mode === 'compact' }"
	[id]="actionBarId"
>
	<div class="action-bar-wrapper">
		<ng-container *ngFor="let action of actionBarConfig.actions; trackBy: trackAction">
			<button
				[id]="actionBarId + '-' + action.id"
				(click)="onClick(action, $event)"
				*ngIf="action.isVisible !== false"
				class="stark-action-bar-action"
				[color]="action.buttonColor ? action.buttonColor : buttonColor"
				[ngClass]="action.className || ''"
				[matTooltip]="getActionLabel(action) | translate"
				[disabled]="!action.isEnabled"
				mat-icon-button
				type="button"
			>
				<mat-icon [svgIcon]="getActionIcon(action)" class="stark-small-icon"></mat-icon>
				<span
					[class]="'action-label ' + (action.buttonColor ? action.buttonColor : buttonColor)"
					[ngClass]="{ disabled: !action.isEnabled }"
					*ngIf="isExtended"
				>
					{{ action.label | translate }}
				</span>
			</button>
		</ng-container>
	</div>

	<div *ngIf="mode === 'full' || alternativeActions" class="alt-actions">
		<button
			class="extend-action-bar"
			color="primary"
			mat-icon-button
			*ngIf="mode === 'full'"
			(click)="toggleExtendedActionBar()"
			type="button"
		>
			<mat-icon svgIcon="dots-horizontal" class="stark-small-icon"></mat-icon>
		</button>
		<button
			class="open-alt-actions"
			color="primary"
			mat-icon-button
			*ngIf="alternativeActions"
			[matMenuTriggerFor]="menu"
			type="button"
		>
			<mat-icon svgIcon="dots-vertical" class="stark-small-icon"></mat-icon>
		</button>
		<mat-menu #menu="matMenu" xPosition="before">
			<ng-container *ngFor="let action of alternativeActions; trackBy: trackAction">
				<button
					*ngIf="action.isVisible !== false"
					mat-menu-item
					class="stark-action-bar-menu-item"
					[ngClass]="action.className || ''"
					[id]="actionBarId + '-alt-' + action.id"
					[disabled]="!action.isEnabled"
					(click)="onClick(action, $event)"
				>
					<mat-icon [svgIcon]="action.icon" class="stark-small-icon"></mat-icon>
					<span translate>{{ action.label }}</span>
				</button>
			</ng-container>
		</mat-menu>
	</div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""