]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/buttons/action-dropdown.component.ts
Refactor follow/mute as modals in admin, add actions in abuse list
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / buttons / action-dropdown.component.ts
CommitLineData
eacb25c4 1import { Component, Input } from '@angular/core'
3a0fb65c 2import { GlobalIconName } from '@app/shared/images/global-icon.component'
eacb25c4
C
3
4export 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
15export type DropdownButtonSize = 'normal' | 'small'
16export type DropdownTheme = 'orange' | 'grey'
17export 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
25export 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'
3a0fb65c
C
30
31 @Input() buttonSize: DropdownButtonSize = 'normal'
32 @Input() buttonDirection: DropdownDirection = 'horizontal'
33 @Input() buttonStyled = true
34
791645e6 35 @Input() label: string
3a0fb65c 36 @Input() theme: DropdownTheme = 'grey'
f97c91f7 37
be27ef3b
C
38 getActions (): DropdownAction<T>[][] {
39 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
f97c91f7 40
be27ef3b 41 return [ this.actions as DropdownAction<T>[] ]
f97c91f7 42 }
3a0fb65c 43
3d216ea0
C
44 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
45 return actions.some(a => {
46 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
47
48 return a.isDisplayed === undefined || a.isDisplayed(entry)
49 })
3a0fb65c 50 }
eacb25c4 51}