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