@@ -1,73 +0,0 @@
1−import tippy from 'tippy.js';
2−// import DocLink from '@/docs/DocLink.svelte'; // TODO try to add a link in the tooltip somehow or something, like:
3−// const app = new DocLink({
4−// target: document.getElementBySelector('.tippy')
5−// })
6−
7−const defaultParams = {
8− theme: 'astrolabe',
9− delay: [500, 0],
10−};
11−
12−function getParams(paramsOrContent:any = {}, overrides = {}) {
13− let params = paramsOrContent;
14− if (typeof paramsOrContent === 'string') {
15− params = { content: paramsOrContent };
16− }
17− return {
18− ...defaultParams,
19− ...params,
20− ...overrides,
21− };
22−}
23−
24−export default function tooltip(node, paramsOrContent: any = {}) {
25− const onTrigger = () => {
26− console.log('triggered');
27− node.dispatchEvent(new CustomEvent("tooltipTriggered"));
28− };
29− const onUntrigger = () => {
30− console.log('untriggered');
31− node.dispatchEvent(new CustomEvent("tooltipUntriggered"));
32− };
33− const onClickOutside = (_, e) => {
34− e.stopPropagation();
35− };
36− const listeners = {
37− onTrigger,
38− onUntrigger,
39− onClickOutside,
40− }
41−
42− const params = getParams(paramsOrContent, listeners);
43− const { content } = params;
44−
45− // Let's make sure the "aria-label" attribute
46− // is set so our element is accessible:
47− // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
48− if (!node.getAttribute("aria-label")) node.setAttribute("aria-label", content);
49−
50−
51− // Support any of the Tippy props by forwarding all "params":
52− // https://atomiks.github.io/tippyjs/v6/all-props/
53− const tip: any = tippy(node, params);
54− const hideTip = (e) => {
55− if (tip.state.isShown) {
56− tip.hide();
57− // e.stopPropagation();
58− }
59− }
60− node.addEventListener('click', hideTip);
61−
62−
63− return {
64− // If the props change, let's update the Tippy instance:
65− update: (newParams) => tip.setProps(getParams(newParams)),
66−
67− // Clean up the Tippy instance on unmount:
68− destroy: () => {
69− node.removeEventListener('click', hideTip);
70− tip.destroy();
71− }
72− };
73−};