]>
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 |
9b82d49d RK |
7 | description?: string |
8 | title?: string | |
c199c427 C |
9 | handler?: (a: T) => any |
10 | linkBuilder?: (a: T) => (string | number)[] | |
11 | isDisplayed?: (a: T) => boolean | |
eacb25c4 C |
12 | } |
13 | ||
3a0fb65c C |
14 | export type DropdownButtonSize = 'normal' | 'small' |
15 | export type DropdownTheme = 'orange' | 'grey' | |
16 | export type DropdownDirection = 'horizontal' | 'vertical' | |
17 | ||
eacb25c4 C |
18 | @Component({ |
19 | selector: 'my-action-dropdown', | |
20 | styleUrls: [ './action-dropdown.component.scss' ], | |
21 | templateUrl: './action-dropdown.component.html' | |
22 | }) | |
23 | ||
24 | export class ActionDropdownComponent<T> { | |
f97c91f7 | 25 | @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = [] |
eacb25c4 | 26 | @Input() entry: T |
3a0fb65c | 27 | |
3921166d | 28 | @Input() placement = 'bottom-left auto' |
3a0fb65c C |
29 | |
30 | @Input() buttonSize: DropdownButtonSize = 'normal' | |
31 | @Input() buttonDirection: DropdownDirection = 'horizontal' | |
32 | @Input() buttonStyled = true | |
33 | ||
791645e6 | 34 | @Input() label: string |
3a0fb65c | 35 | @Input() theme: DropdownTheme = 'grey' |
f97c91f7 | 36 | |
be27ef3b C |
37 | getActions (): DropdownAction<T>[][] { |
38 | if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][] | |
f97c91f7 | 39 | |
be27ef3b | 40 | return [ this.actions as DropdownAction<T>[] ] |
f97c91f7 | 41 | } |
3a0fb65c | 42 | |
3d216ea0 C |
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) | |
46 | ||
47 | return a.isDisplayed === undefined || a.isDisplayed(entry) | |
48 | }) | |
3a0fb65c | 49 | } |
eacb25c4 | 50 | } |