]>
Commit | Line | Data |
---|---|---|
eacb25c4 | 1 | import { Component, Input } from '@angular/core' |
3a0fb65c | 2 | import { GlobalIconName } from '@app/shared/images/global-icon.component' |
eacb25c4 C |
3 | |
4 | export type DropdownAction<T> = { | |
eacb25c4 | 5 | label?: string |
3a0fb65c | 6 | iconName?: GlobalIconName |
c199c427 C |
7 | handler?: (a: T) => any |
8 | linkBuilder?: (a: T) => (string | number)[] | |
9 | isDisplayed?: (a: T) => boolean | |
eacb25c4 C |
10 | } |
11 | ||
3a0fb65c C |
12 | export type DropdownButtonSize = 'normal' | 'small' |
13 | export type DropdownTheme = 'orange' | 'grey' | |
14 | export type DropdownDirection = 'horizontal' | 'vertical' | |
15 | ||
eacb25c4 C |
16 | @Component({ |
17 | selector: 'my-action-dropdown', | |
18 | styleUrls: [ './action-dropdown.component.scss' ], | |
19 | templateUrl: './action-dropdown.component.html' | |
20 | }) | |
21 | ||
22 | export class ActionDropdownComponent<T> { | |
f97c91f7 | 23 | @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = [] |
eacb25c4 | 24 | @Input() entry: T |
3a0fb65c | 25 | |
791645e6 | 26 | @Input() placement = 'bottom-left' |
3a0fb65c C |
27 | |
28 | @Input() buttonSize: DropdownButtonSize = 'normal' | |
29 | @Input() buttonDirection: DropdownDirection = 'horizontal' | |
30 | @Input() buttonStyled = true | |
31 | ||
791645e6 | 32 | @Input() label: string |
3a0fb65c | 33 | @Input() theme: DropdownTheme = 'grey' |
f97c91f7 C |
34 | |
35 | getActions () { | |
36 | if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions | |
37 | ||
38 | return [ this.actions ] | |
39 | } | |
3a0fb65c C |
40 | |
41 | areActionsDisplayed (actions: DropdownAction<T>[], entry: T) { | |
42 | return actions.some(a => a.isDisplayed === undefined || a.isDisplayed(entry)) | |
43 | } | |
eacb25c4 | 44 | } |