Merge branch 'develop' into pr/1217
[oweals/peertube.git] / client / src / app / shared / buttons / action-dropdown.component.ts
1 import { Component, Input } from '@angular/core'
2
3 export type DropdownAction<T> = {
4   label?: string
5   handler?: (a: T) => any
6   linkBuilder?: (a: T) => (string | number)[]
7   isDisplayed?: (a: T) => boolean
8 }
9
10 @Component({
11   selector: 'my-action-dropdown',
12   styleUrls: [ './action-dropdown.component.scss' ],
13   templateUrl: './action-dropdown.component.html'
14 })
15
16 export class ActionDropdownComponent<T> {
17   @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
18   @Input() entry: T
19   @Input() placement = 'bottom-left'
20   @Input() buttonSize: 'normal' | 'small' = 'normal'
21   @Input() label: string
22   @Input() theme: 'orange' | 'grey' = 'grey'
23
24   getActions () {
25     if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions
26
27     return [ this.actions ]
28   }
29 }