]>
Commit | Line | Data |
---|---|---|
eacb25c4 | 1 | import { Component, Input } from '@angular/core' |
67ed6552 | 2 | import { GlobalIconName } from '@app/shared/shared-icons' |
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 | |
bb152476 | 12 | isHeader?: boolean |
eacb25c4 C |
13 | } |
14 | ||
3a0fb65c C |
15 | export type DropdownButtonSize = 'normal' | 'small' |
16 | export type DropdownTheme = 'orange' | 'grey' | |
17 | export type DropdownDirection = 'horizontal' | 'vertical' | |
18 | ||
eacb25c4 C |
19 | @Component({ |
20 | selector: 'my-action-dropdown', | |
21 | styleUrls: [ './action-dropdown.component.scss' ], | |
22 | templateUrl: './action-dropdown.component.html' | |
23 | }) | |
24 | ||
25 | export class ActionDropdownComponent<T> { | |
f97c91f7 | 26 | @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = [] |
eacb25c4 | 27 | @Input() entry: T |
3a0fb65c | 28 | |
3921166d | 29 | @Input() placement = 'bottom-left auto' |
9b4241e3 | 30 | @Input() container: null | 'body' |
3a0fb65c C |
31 | |
32 | @Input() buttonSize: DropdownButtonSize = 'normal' | |
33 | @Input() buttonDirection: DropdownDirection = 'horizontal' | |
34 | @Input() buttonStyled = true | |
35 | ||
791645e6 | 36 | @Input() label: string |
3a0fb65c | 37 | @Input() theme: DropdownTheme = 'grey' |
f97c91f7 | 38 | |
be27ef3b C |
39 | getActions (): DropdownAction<T>[][] { |
40 | if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][] | |
f97c91f7 | 41 | |
be27ef3b | 42 | return [ this.actions as DropdownAction<T>[] ] |
f97c91f7 | 43 | } |
3a0fb65c | 44 | |
3d216ea0 C |
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) | |
48 | ||
49 | return a.isDisplayed === undefined || a.isDisplayed(entry) | |
50 | }) | |
3a0fb65c | 51 | } |
eacb25c4 | 52 | } |