简体   繁体   English

Svelte:如何在嵌套组件上实现 use:tippy

[英]Svelte: How to implement use:tippy on a nested component

I've found the svelte-tippy implementation of the tooltip library Tippy.js which I understand is a Svelte Action, ie it uses the use:tippy attribute, like this:我发现工具提示库Tippy.jssvelte-tippy实现,我理解它是一个 Svelte Action,即它使用use:tippy属性,如下所示:

<button use:tippy={props}>
  Hover me
</button>

How would I go about implementing a Tippy.js tooltip for a heatmap ?我将如何 go 关于为热图实现 Tippy.js 工具提示? The configuration (at least, true / false for using tooltips, but also some template or function for the actual tooltip contents) would happen at the top-level component ( SvelteHeatmap ), but the actual implementation would happen on the Cell level which represents a day, with the Month or Week components, respectively, in between, and would be based on the configuration provided on the top-level.配置(至少, true / false用于使用工具提示,还有一些模板或Cell用于实际工具提示内容)将发生在顶级组件( SvelteHeatmap ),但实际实现将发生在代表日, MonthWeek组件,分别在两者之间,并且将基于顶层提供的配置。

As I would like to suggest a Pull Request for the Svelte Heatmap component but am only a Svelte beginner, I'd like to get some generic explanation as to how this works, or should work.由于我想为Svelte Heatmap组件建议一个拉取请求,但我只是一个 Svelte 初学者,我想获得一些关于它如何工作或应该如何工作的通用解释。 The official documentation has some info on Actions, but not really a best practice for this kind of thing (I may be wrong about this though).官方文档有一些关于 Actions 的信息,但并不是这类事情的最佳实践(虽然我可能错了)。

Note I've made a basic test to make sure this works with SVG , it does.注意我已经进行了基本测试,以确保它适用于 SVG ,它确实如此。

I couldn't find anything really that would clearly explain how to do this.我找不到任何可以清楚地解释如何做到这一点的东西。 After some fiddling I came up with this use经过一番摆弄后,我想出了这个用法



  
  
<div id="my_selector"></div>

<div id="nested_elements"> 
    <button>Option_1</button>
    <button>Option_2</button>
    <button>Option_3</button>
</div>


<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>


  
  
tippy('#my_selector', {
            content: document.querySelector('#nested_elements').innerHTML,
            interactive: true,
            allowHTML: true,
          });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM