aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/shared-main/buttons/action-dropdown.component.ts')
-rw-r--r--client/src/app/shared/shared-main/buttons/action-dropdown.component.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts b/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
new file mode 100644
index 000000000..36d7d6229
--- /dev/null
+++ b/client/src/app/shared/shared-main/buttons/action-dropdown.component.ts
@@ -0,0 +1,52 @@
1import { Component, Input } from '@angular/core'
2import { GlobalIconName } from '@app/shared/shared-icons'
3
4export 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 isHeader?: boolean
13}
14
15export type DropdownButtonSize = 'normal' | 'small'
16export type DropdownTheme = 'orange' | 'grey'
17export type DropdownDirection = 'horizontal' | 'vertical'
18
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> {
26 @Input() actions: DropdownAction<T>[] | DropdownAction<T>[][] = []
27 @Input() entry: T
28
29 @Input() placement = 'bottom-left auto'
30 @Input() container: null | 'body'
31
32 @Input() buttonSize: DropdownButtonSize = 'normal'
33 @Input() buttonDirection: DropdownDirection = 'horizontal'
34 @Input() buttonStyled = true
35
36 @Input() label: string
37 @Input() theme: DropdownTheme = 'grey'
38
39 getActions (): DropdownAction<T>[][] {
40 if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction<T>[][]
41
42 return [ this.actions as DropdownAction<T>[] ]
43 }
44
45 areActionsDisplayed (actions: Array<DropdownAction<T> | DropdownAction<T>[]>, entry: T): boolean {
46 return actions.some(a => {
47 if (Array.isArray(a)) return this.areActionsDisplayed(a, entry)
48
49 return a.isDisplayed === undefined || a.isDisplayed(entry)
50 })
51 }
52}