]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
Fix report modal error
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / buttons / action-dropdown.component.ts
1 import { Component, Input } from '@angular/core'
2 import { GlobalIconName } from '@app/shared/shared-icons'
3
4 export type DropdownAction<T> = {
5 label?: string
6 iconName?: GlobalIconName
7 description?: string
8 title?: string
9 handler?: (a: T) => any
10 linkBuilder?: (a: T) => (string | number)[]
11 isDisplayed?: (a: T) => boolean
12
13 class?: string[]
14 isHeader?: boolean
15 }
16
17 export type DropdownButtonSize = 'normal' | 'small'
18 export type DropdownTheme = 'orange' | 'grey'
19 export type DropdownDirection = 'horizontal' | 'vertical'
20
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> {
28 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
29 @Input() entry: T
30
31 @Input() placement = 'bottom-left auto'
32 @Input() container: null | 'body'
33
34 @Input() buttonSize: DropdownButtonSize = 'normal'
35 @Input() buttonDirection: DropdownDirection = 'horizontal'
36 @Input() buttonStyled = true
37
38 @Input() label: string
39 @Input() theme: DropdownTheme = 'grey'
40
41 getActions (): DropdownAction<T>[][] {
42 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
43
44 return [ this.actions as DropdownAction<T>[] ]
45 }
46
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 })
53 }
54 }