import type { Tooltip } from 'bootstrap'; 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'; interface TooltipContainerArgs { renderAsSpan?: boolean; cssClass?: string; tooltipCssClass?: string; tooltip: string; isHtml?: boolean; trigger?: 'click' | 'hover' | 'focus' | 'manual' | 'click hover' | 'click focus' | 'hover focus' | 'click hover focus'; textAlign?: 'left' | 'middle' | 'right'; arrowPosition?: 'left' | 'middle' | 'right'; } @Component class TooltipContainerComponent extends TsxComponent implements TooltipContainerArgs { @Prop() renderAsSpan!: boolean; @Prop() cssClass!: string; @Prop() tooltipCssClass?: string; @Prop() tooltip: string; @Prop() isHtml?: boolean; @Prop() trigger?: 'click' | 'hover' | 'focus' | 'manual' | 'click hover' | 'click focus' | 'hover focus' | 'click hover focus'; @Prop() textAlign?: 'left' | 'middle' | 'right'; @Prop() arrowPosition: 'left' | 'middle' | 'right'; mounted() { this.syncTooltip(); } beforeUnmount() { // dispose() also removes a currently-open tip from . TooltipLifecycle.dispose(this.$el); } @Watch('tooltip', { flush: 'post' }) syncTooltip() { TooltipLifecycle.sync( this.$el as HTMLElement, this.tooltip, { constructorOptions: this.getConstructorOptions() }, ); } getConstructorOptions(): Partial { return { html: this.isHtml == true, trigger: this.trigger || 'hover', template: ``, }; } getInnerStyleAttribute(): string { if (!isNullOrEmpty(this.textAlign)) { return `style="text:align: ${this.textAlign} !important;"`; } return ''; } getCssClass(): string { return `tooltip-container ${this.cssClass || ''}`; } render(h) { if (this.renderAsSpan != true) { return (
{this.$slots.default?.()}
); } return ( {this.$slots.default?.()} ); } } const TooltipContainer = toNative(TooltipContainerComponent); export default TooltipContainer;