aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/buttons/action-dropdown.component.ts
blob: 275e2b51ecfbabd82e4816b18c3414f8e9a60dd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Component, Input } from '@angular/core'

export type DropdownAction<T> = {
  label?: string
  handler?: (a: T) => any
  linkBuilder?: (a: T) => (string | number)[]
  isDisplayed?: (a: T) => boolean
}

@Component({
  selector: 'my-action-dropdown',
  styleUrls: [ './action-dropdown.component.scss' ],
  templateUrl: './action-dropdown.component.html'
})

export class ActionDropdownComponent<T> {
  @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
  @Input() entry: T
  @Input() placement = 'bottom-left'
  @Input() buttonSize: 'normal' | 'small' = 'normal'
  @Input() label: string
  @Input() theme: 'orange' | 'grey' = 'grey'

  getActions () {
    if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions

    return [ this.actions ]
  }
}