X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fbuttons%2Faction-dropdown.component.ts;h=c9dbbfda243035c10b905903ae5ba594e6f0de9e;hb=b5f919ac8eb2a1c20e26582fdfd377d687710d8f;hp=9877f639dd4062c4625da2e775f2790ea23f2c88;hpb=244b4ae3973bc1511464a08158a123767f83179c;p=oweals%2Fpeertube.git diff --git a/client/src/app/shared/buttons/action-dropdown.component.ts b/client/src/app/shared/buttons/action-dropdown.component.ts index 9877f639d..c9dbbfda2 100644 --- a/client/src/app/shared/buttons/action-dropdown.component.ts +++ b/client/src/app/shared/buttons/action-dropdown.component.ts @@ -1,12 +1,18 @@ import { Component, Input } from '@angular/core' +import { GlobalIconName } from '@app/shared/images/global-icon.component' export type DropdownAction = { label?: string - handler?: (T: any) => any - linkBuilder?: (T: any) => (string | number)[] - isDisplayed?: (T: any) => boolean + iconName?: GlobalIconName + handler?: (a: T) => any + linkBuilder?: (a: T) => (string | number)[] + isDisplayed?: (a: T) => boolean } +export type DropdownButtonSize = 'normal' | 'small' +export type DropdownTheme = 'orange' | 'grey' +export type DropdownDirection = 'horizontal' | 'vertical' + @Component({ selector: 'my-action-dropdown', styleUrls: [ './action-dropdown.component.scss' ], @@ -14,10 +20,25 @@ export type DropdownAction = { }) export class ActionDropdownComponent { - @Input() actions: DropdownAction[] = [] + @Input() actions: DropdownAction[] | DropdownAction[][] = [] @Input() entry: T + @Input() placement = 'bottom-left' - @Input() buttonSize: 'normal' | 'small' = 'normal' + + @Input() buttonSize: DropdownButtonSize = 'normal' + @Input() buttonDirection: DropdownDirection = 'horizontal' + @Input() buttonStyled = true + @Input() label: string - @Input() theme: 'orange' | 'grey' = 'grey' + @Input() theme: DropdownTheme = 'grey' + + getActions () { + if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions + + return [ this.actions ] + } + + areActionsDisplayed (actions: DropdownAction[], entry: T) { + return actions.some(a => a.isDisplayed === undefined || a.isDisplayed(entry)) + } }