X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fbuttons%2Faction-dropdown.component.ts;h=5330ca220958e365e7541ffbba0bad207c09ca09;hb=c78d3db71baa397971a83b110c0159169646eae4;hp=17f9cc6188d54ac839a19084c179a0ee8ee11f76;hpb=141b177db088891e84040f68aa95008fb52f1d44;p=github%2FChocobozzz%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 17f9cc618..5330ca220 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 - linkBuilder?: (T) => (string | number)[] - isDisplayed?: (T) => 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,7 +20,29 @@ export type DropdownAction = { }) export class ActionDropdownComponent { - @Input() actions: DropdownAction[] = [] + @Input() actions: DropdownAction[] | DropdownAction[][] = [] @Input() entry: T - @Input() placement = 'left' + + @Input() placement = 'bottom-left auto' + + @Input() buttonSize: DropdownButtonSize = 'normal' + @Input() buttonDirection: DropdownDirection = 'horizontal' + @Input() buttonStyled = true + + @Input() label: string + @Input() theme: DropdownTheme = 'grey' + + getActions () { + if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions + + return [ this.actions ] + } + + areActionsDisplayed (actions: Array | DropdownAction[]>, entry: T): boolean { + return actions.some(a => { + if (Array.isArray(a)) return this.areActionsDisplayed(a, entry) + + return a.isDisplayed === undefined || a.isDisplayed(entry) + }) + } }