]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/buttons/action-dropdown.component.ts
f5345831b86dd5827d28a11a14411347945ecdc1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / buttons / action-dropdown.component.ts
1 import { Component, Input } from '@angular/core'
2 import { GlobalIconName } from '@app/shared/images/global-icon.component'
3
4 export type DropdownAction<T> = {
5 label?: string
6 iconName?: GlobalIconName
7 handler?: (a: T) => any
8 linkBuilder?: (a: T) => (string | number)[]
9 isDisplayed?: (a: T) => boolean
10 }
11
12 export type DropdownButtonSize = 'normal' | 'small'
13 export type DropdownTheme = 'orange' | 'grey'
14 export type DropdownDirection = 'horizontal' | 'vertical'
15
16 @Component({
17 selector: 'my-action-dropdown',
18 styleUrls: [ './action-dropdown.component.scss' ],
19 templateUrl: './action-dropdown.component.html'
20 })
21
22 export class ActionDropdownComponent<T> {
23 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
24 @Input() entry: T
25
26 @Input() placement = 'bottom-left'
27
28 @Input() buttonSize: DropdownButtonSize = 'normal'
29 @Input() buttonDirection: DropdownDirection = 'horizontal'
30 @Input() buttonStyled = true
31
32 @Input() label: string
33 @Input() theme: DropdownTheme = 'grey'
34
35 getActions () {
36 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions
37
38 return [ this.actions ]
39 }
40
41 areActionsDisplayed (actions: DropdownAction<T>[], entry: T) {
42 return actions.some(a => a.isDisplayed === undefined || a.isDisplayed(entry))
43 }
44
45 handleClick (event: Event, action: DropdownAction<T>) {
46 event.preventDefault()
47
48 // action.handler(entry)
49 }
50 }