Sha256: 46ba429111c3140f79e38cb49f25c5035d87fca350abeee926dd68a6e34a728c
Contents?: true
Size: 1.9 KB
Versions: 41
Compression:
Stored size: 1.9 KB
Contents
import tippy from "@libs/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
41 entries across 41 versions & 1 rubygems