2024-03-02 09:00:20 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { onDestroy } from 'svelte';
|
|
|
|
import tippy from 'tippy.js';
|
|
|
|
|
|
|
|
export let placement = 'top';
|
|
|
|
export let content = `I'm a tooltip!`;
|
|
|
|
|
|
|
|
let tooltipElement;
|
|
|
|
let tooltipInstance;
|
|
|
|
|
|
|
|
$: if (tooltipElement && content) {
|
|
|
|
if (tooltipInstance) {
|
2024-03-02 09:20:50 +00:00
|
|
|
tooltipInstance.setContent(content);
|
|
|
|
} else {
|
|
|
|
tooltipInstance = tippy(tooltipElement, {
|
|
|
|
content: content,
|
|
|
|
placement: placement,
|
|
|
|
allowHTML: true
|
|
|
|
});
|
2024-03-02 09:00:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onDestroy(() => {
|
|
|
|
if (tooltipInstance) {
|
2024-03-02 09:20:50 +00:00
|
|
|
tooltipInstance.destroy();
|
2024-03-02 09:00:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div bind:this={tooltipElement}>
|
|
|
|
<slot />
|
|
|
|
</div>
|