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
15 export type DropdownButtonSize = 'normal' | 'small'
16 export type DropdownTheme = 'orange' | 'grey'
17 export type DropdownDirection = 'horizontal' | 'vertical'
20 selector: 'my-action-dropdown',
21 styleUrls: [ './action-dropdown.component.scss' ],
22 templateUrl: './action-dropdown.component.html'
25 export class ActionDropdownComponent<T> {
26 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
29 @Input() placement = 'bottom-left auto'
30 @Input() container: null | 'body'
32 @Input() buttonSize: DropdownButtonSize = 'normal'
33 @Input() buttonDirection: DropdownDirection = 'horizontal'
34 @Input() buttonStyled = true
36 @Input() label: string
37 @Input() theme: DropdownTheme = 'grey'
39 getActions (): DropdownAction<T>[][] {
40 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
42 return [ this.actions as DropdownAction<T>[] ]
45 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
46 return actions.some(a => {
47 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
49 return a.isDisplayed === undefined || a.isDisplayed(entry)