Sha256: 400ae462df57eac5af5ab51478f617149073b494a7b90fa8596572396ade695e
Contents?: true
Size: 1.75 KB
Versions: 16
Compression:
Stored size: 1.75 KB
Contents
import tippy from "@libs/tippy"; export default function withTooltip(props = {}) { function withTooltipMixin(component) { const el = component.$root; const oldDestroy = component.destroy; if (!component.hasData("tippy-content")) { component.setData("tippy-disabled", true); } const content = component.getData("tippy-content"); const tooltip = tippy(el, { theme: "coco-tooltip", onShow() { if (component.onTooltipShow) { return component.onTooltipShow(); } else { return component.refuteData("tippy-disabled", true); } }, content() { return content; }, ...props, }); Object.assign( component, Alpine.reactive({ tooltip: { content, instance: tooltip, originalContent: content, }, getTooltip() { return this.tooltip; }, setTooltip(content) { this.tooltip.content = content; }, resetTooltip() { this.tooltip.content = this.tooltip.originalContent; }, destroy() { if (this.tooltip && this.tooltip.instance) { this.tooltip.instance.destroy(); this.tooltip = null; } if (oldDestroy) { oldDestroy.call(this); } }, }) ); Alpine.effect(() => { if (component.tooltip && component.tooltip.instance) { const value = component.tooltip.content; if (value !== null) { component.tooltip.instance.setContent(value); component.setData("tippy-content", value); } } }); return component; } withTooltipMixin.props = ["tooltip"]; return withTooltipMixin; }
Version data entries
16 entries across 16 versions & 1 rubygems