1 import { Component, Input } from '@angular/core'
2 import { GlobalIconName } from '@app/shared/shared-icons'
4 export type DropdownAction<T> = {
6 iconName?: GlobalIconName
9 handler?: (a: T) => any
10 linkBuilder?: (a: T) => (string | number)[]
11 isDisplayed?: (a: T) => boolean
17 export type DropdownButtonSize = 'normal' | 'small'
18 export type DropdownTheme = 'orange' | 'grey'
19 export type DropdownDirection = 'horizontal' | 'vertical'
22 selector: 'my-action-dropdown',
23 styleUrls: [ './action-dropdown.component.scss' ],
24 templateUrl: './action-dropdown.component.html'
27 export class ActionDropdownComponent<T> {
28 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
31 @Input() placement = 'bottom-left auto'
32 @Input() container: null | 'body'
34 @Input() buttonSize: DropdownButtonSize = 'normal'
35 @Input() buttonDirection: DropdownDirection = 'horizontal'
36 @Input() buttonStyled = true
38 @Input() label: string
39 @Input() theme: DropdownTheme = 'grey'
41 getActions (): DropdownAction<T>[][] {
42 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
44 return [ this.actions as DropdownAction<T>[] ]
47 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
48 return actions.some(a => {
49 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
51 return a.isDisplayed === undefined || a.isDisplayed(entry)