1 import { Component, Input } from '@angular/core'
2 import { GlobalIconName } from '@app/shared/images/global-icon.component'
4 export type DropdownAction<T> = {
6 iconName?: GlobalIconName
9 handler?: (a: T) => any
10 linkBuilder?: (a: T) => (string | number)[]
11 isDisplayed?: (a: T) => boolean
14 export type DropdownButtonSize = 'normal' | 'small'
15 export type DropdownTheme = 'orange' | 'grey'
16 export type DropdownDirection = 'horizontal' | 'vertical'
19 selector: 'my-action-dropdown',
20 styleUrls: [ './action-dropdown.component.scss' ],
21 templateUrl: './action-dropdown.component.html'
24 export class ActionDropdownComponent<T> {
25 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
28 @Input() placement = 'bottom-left auto'
30 @Input() buttonSize: DropdownButtonSize = 'normal'
31 @Input() buttonDirection: DropdownDirection = 'horizontal'
32 @Input() buttonStyled = true
34 @Input() label: string
35 @Input() theme: DropdownTheme = 'grey'
37 getActions (): DropdownAction<T>[][] {
38 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
40 return [ this.actions as DropdownAction<T>[] ]
43 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
44 return actions.some(a => {
45 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
47 return a.isDisplayed === undefined || a.isDisplayed(entry)