import type { VNode } from 'vue'; import { Prop, toNative, Watch } from 'vue-facing-decorator'; import TsxComponent, { Component } from '../../app/vuetsx'; import { isNullOrEmpty } from '../../common/utils/is-null-or-empty'; import { TooltipLifecycle } from '../../common/utils/tooltip-lifecycle'; export interface DropdownButtonItemArgs { icon?: string; img?: ImageObj; text: string | VNode; href?: string; disabled?: boolean; hrefBlank?: boolean; clicked?: () => void; isSelected?: boolean; emptySpace?: boolean; tooltip?: string; } export interface ImageObj { class?: string; src: string; text?: string; } @Component class DropdownButtonItemComponent extends TsxComponent implements DropdownButtonItemArgs { @Prop() icon!: string; @Prop() img!: ImageObj; @Prop() text!: string | VNode; @Prop() href!: string; @Prop() disabled!: boolean; @Prop() hrefBlank!: boolean; @Prop() isSelected!: boolean; @Prop() clicked?: () => void; @Prop() emptySpace!: boolean; @Prop() tooltip!: string; mounted() { this.syncTooltip(); } beforeUnmount() { TooltipLifecycle.dispose(this.$el); } @Watch('tooltip', { flush: 'post' }) syncTooltip() { TooltipLifecycle.sync(this.$el as HTMLElement, this.tooltip); } raiseClickEvent() { if (this.disabled == true) { return; } if (!isNullOrEmpty(this.tooltip)) { TooltipLifecycle.dismiss(this.$el as HTMLElement); } if (this.clicked != null) { this.clicked(); } } getHref(): string { if (!isNullOrEmpty(this.href) && this.disabled != true) { return this.href; } else { return 'javascript:'; } } getHrefTarget(): string { if (this.hrefBlank == true && this.disabled != true) { return '_blank'; } return null; } get useRouterLink(): boolean { return !isNullOrEmpty(this.href) && this.hrefBlank != true && this.disabled != true && this.href.startsWith('/'); } get itemCssClass(): string { return `dropdown-item${this.isSelected ? ' dropdown-selectable-section' : ''}${this.disabled == true ? ' disabled ' : ''}`; } renderContent() { return [ !isNullOrEmpty(this.icon) && ( {this.emptySpace != false &&   } ), this.img != null && ( {this.emptySpace != false &&   } {this.img.text} ), {this.text}, this.isSelected && , ]; } render(h) { if (this.useRouterLink) { return ( this.raiseClickEvent()} > {this.renderContent()} ); } return ( this.raiseClickEvent()} > {this.renderContent()} ); } } const DropdownButtonItem = toNative(DropdownButtonItemComponent); export default DropdownButtonItem;