Sha256: 506840ca200cb57e4118c39635b42d9fdcb6a4af9ea701985a7aa79091663d5b
Contents?: true
Size: 1.91 KB
Versions: 26
Compression:
Stored size: 1.91 KB
Contents
import tippy from "@assets/js/base/tippy"; import buildConfig from "../utils/tippy_modifiers"; import { setData } from "@helpers/alpine"; export default function (Alpine) { Alpine.directive( "tooltip", (el, { modifiers, expression }, { evaluate, evaluateLater, effect }) => { const config = buildConfig(modifiers); if (!el.__x_tippy) { el.__x_tippy = tippy(el, { theme: "coco-tooltip", ...config, }); } let initialContent = null; const enableTooltip = () => el.__x_tippy.enable(); const disableTooltip = () => el.__x_tippy.disable(); const setupTooltip = (content) => { if (!content) { disableTooltip(); } else { enableTooltip(); el.__x_tippy.setContent(content); initialContent = initialContent || content; } }; // Evaluate initital content immediately if // marked as raw, otherwise defer evaluation if (modifiers.includes("raw")) { setupTooltip(expression); } else { const getContent = evaluateLater(expression); effect(() => { getContent((content) => { if (typeof content === "object" && content !== null) { el.__x_tippy.setProps(content); initialContent = initialContent || content.content; enableTooltip(); } else { setupTooltip(content); } }); }); } // Add some helper methods under the `.tooltip` // property for getting/setting tooltip content setData(el, { tooltip: { setContent(content) { setupTooltip(content); }, disable: () => disableTooltip(), enable: () => enableTooltip(), reset() { if (initialContent) setupTooltip(initialContent); }, }, }); } ).before("bind"); }
Version data entries
26 entries across 26 versions & 1 rubygems