2018-08-28 13:54:25 +02:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reusable head bar component for Apps.
|
|
|
|
*
|
|
|
|
* Will translate the title automatically.
|
|
|
|
*
|
|
|
|
* Use `PlusButton=true` and `(plusButtonClicked)=myFunction()` if a plus button is needed
|
|
|
|
*
|
|
|
|
* Use `[menuLust]=myArray` and `(ellipsisMenuItem)=myFunction($event)` if a menu is needed
|
|
|
|
*
|
|
|
|
* ## Examples:
|
|
|
|
*
|
|
|
|
* ### Usage of the selector:
|
|
|
|
*
|
|
|
|
* ```html
|
2018-09-03 17:57:20 +02:00
|
|
|
* <os-head-bar
|
2018-08-28 13:54:25 +02:00
|
|
|
* appName="Files"
|
|
|
|
* PlusButton=true
|
|
|
|
* [menuList]=myMenu
|
|
|
|
* (plusButtonClicked)=onPlusButton()
|
|
|
|
* (ellipsisMenuItem)=onEllipsisItem($event)>
|
2018-09-03 17:57:20 +02:00
|
|
|
* </os-head-bar>
|
2018-08-28 13:54:25 +02:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ### Declaration of a menu provided as `[menuList]=myMenu`:
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* myMenu = [
|
|
|
|
* {
|
|
|
|
* text: 'Download All',
|
|
|
|
* icon: 'download',
|
|
|
|
* action: 'downloadAllFiles'
|
|
|
|
* },
|
|
|
|
* ];
|
|
|
|
* ```
|
|
|
|
* The parent needs to react to `action` like the following.
|
|
|
|
* This will execute a function with the name provided in the
|
|
|
|
* `action` field.
|
|
|
|
* ```ts
|
|
|
|
* onEllipsisItem(event: any) {
|
|
|
|
* if (event.action) {
|
|
|
|
* this[event.action]();
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Component({
|
2018-09-03 17:57:20 +02:00
|
|
|
selector: 'os-head-bar',
|
2018-08-28 13:54:25 +02:00
|
|
|
templateUrl: './head-bar.component.html',
|
|
|
|
styleUrls: ['./head-bar.component.scss']
|
|
|
|
})
|
|
|
|
export class HeadBarComponent implements OnInit {
|
|
|
|
/**
|
|
|
|
* Input declaration for the app name
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
@Input() public appName: string;
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if there should be a plus button.
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
@Input() public plusButton: false;
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If not empty shows a ellipsis menu on the right side
|
|
|
|
*
|
|
|
|
* The parent needs to provide a menu, i.e `[menuList]=myMenu`.
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
@Input() public menuList: any[];
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Emit a signal to the parent component if the plus button was clicked
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
@Output() public plusButtonClicked = new EventEmitter<boolean>();
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Emit a signal to the parent of an item in the menuList was selected.
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
@Output() public ellipsisMenuItem = new EventEmitter<any>();
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty constructor
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public constructor() {}
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* empty onInit
|
|
|
|
*/
|
2018-09-07 13:12:59 +02:00
|
|
|
public ngOnInit(): void {}
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits a signal to the parent if an item in the menu was clicked.
|
|
|
|
* @param item
|
|
|
|
*/
|
2018-09-07 13:12:59 +02:00
|
|
|
public clickMenu(item: any): void {
|
2018-08-28 13:54:25 +02:00
|
|
|
this.ellipsisMenuItem.emit(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits a signal to the parent if
|
|
|
|
*/
|
2018-09-07 13:12:59 +02:00
|
|
|
public clickPlusButton(): void {
|
2018-08-28 13:54:25 +02:00
|
|
|
this.plusButtonClicked.emit(true);
|
|
|
|
}
|
|
|
|
}
|