From 67ed6552b831df66713bac9e672738796128d33f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:10:17 +0200 Subject: Reorganize client shared modules --- .../buttons/action-dropdown.component.ts | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 client/src/app/shared/shared-main/buttons/action-dropdown.component.ts (limited to 'client/src/app/shared/shared-main/buttons/action-dropdown.component.ts') 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 @@ +import { Component, Input } from '@angular/core' +import { GlobalIconName } from '@app/shared/shared-icons' + +export type DropdownAction = { + label?: string + iconName?: GlobalIconName + description?: string + title?: string + handler?: (a: T) => any + linkBuilder?: (a: T) => (string | number)[] + isDisplayed?: (a: T) => boolean + isHeader?: 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' ], + templateUrl: './action-dropdown.component.html' +}) + +export class ActionDropdownComponent { + @Input() actions: DropdownAction[] | DropdownAction[][] = [] + @Input() entry: T + + @Input() placement = 'bottom-left auto' + @Input() container: null | 'body' + + @Input() buttonSize: DropdownButtonSize = 'normal' + @Input() buttonDirection: DropdownDirection = 'horizontal' + @Input() buttonStyled = true + + @Input() label: string + @Input() theme: DropdownTheme = 'grey' + + getActions (): DropdownAction[][] { + if (this.actions.length !== 0 && Array.isArray(this.actions[0])) return this.actions as DropdownAction[][] + + return [ this.actions as DropdownAction[] ] + } + + 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) + }) + } +} -- cgit v1.2.3