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
7 handler?: (a: T) => any
8 linkBuilder?: (a: T) => (string | number)[]
9 isDisplayed?: (a: T) => boolean
12 export type DropdownButtonSize = 'normal' | 'small'
13 export type DropdownTheme = 'orange' | 'grey'
14 export type DropdownDirection = 'horizontal' | 'vertical'
17 selector: 'my-action-dropdown',
18 styleUrls: [ './action-dropdown.component.scss' ],
19 templateUrl: './action-dropdown.component.html'
22 export class ActionDropdownComponent<T> {
23 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
26 @Input() placement = 'bottom-left'
28 @Input() buttonSize: DropdownButtonSize = 'normal'
29 @Input() buttonDirection: DropdownDirection = 'horizontal'
30 @Input() buttonStyled = true
32 @Input() label: string
33 @Input() theme: DropdownTheme = 'grey'
36 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions
38 return [ this.actions ]
41 areActionsDisplayed (actions: DropdownAction<T>[], entry: T) {
42 return actions.some(a => a.isDisplayed === undefined || a.isDisplayed(entry))