2024-03-02 09:00:20 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { onDestroy } from 'svelte';
|
2024-06-15 10:32:18 +00:00
|
|
|
import { marked } from 'marked';
|
|
|
|
|
2024-03-02 09:00:20 +00:00
|
|
|
import tippy from 'tippy.js';
|
2024-07-08 22:26:43 +00:00
|
|
|
import { roundArrow } from 'tippy.js';
|
2024-03-02 09:00:20 +00:00
|
|
|
|
|
|
|
export let placement = 'top';
|
|
|
|
export let content = `I'm a tooltip!`;
|
2024-03-02 09:27:01 +00:00
|
|
|
export let touch = true;
|
2024-05-19 10:57:13 +00:00
|
|
|
export let className = 'flex';
|
2024-07-08 22:26:43 +00:00
|
|
|
export let theme = '';
|
2024-03-02 09:00:20 +00:00
|
|
|
|
|
|
|
let tooltipElement;
|
|
|
|
let tooltipInstance;
|
|
|
|
|
|
|
|
$: if (tooltipElement && content) {
|
|
|
|
if (tooltipInstance) {
|
2024-03-02 09:20:50 +00:00
|
|
|
tooltipInstance.setContent(content);
|
|
|
|
} else {
|
|
|
|
tooltipInstance = tippy(tooltipElement, {
|
2024-06-15 16:43:10 +00:00
|
|
|
content: content,
|
2024-03-02 09:20:50 +00:00
|
|
|
placement: placement,
|
2024-03-02 09:27:01 +00:00
|
|
|
allowHTML: true,
|
2024-07-08 22:26:43 +00:00
|
|
|
touch: touch,
|
|
|
|
...(theme !== '' ? { theme } : { theme: 'dark' }),
|
|
|
|
arrow: false,
|
|
|
|
offset: [0, 4]
|
2024-03-02 09:20:50 +00:00
|
|
|
});
|
2024-03-02 09:00:20 +00:00
|
|
|
}
|
2024-06-04 18:13:43 +00:00
|
|
|
} else if (tooltipInstance && content === '') {
|
|
|
|
if (tooltipInstance) {
|
|
|
|
tooltipInstance.destroy();
|
|
|
|
}
|
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>
|
|
|
|
|
2024-05-19 10:57:13 +00:00
|
|
|
<div bind:this={tooltipElement} aria-label={content} class={className}>
|
2024-03-02 09:00:20 +00:00
|
|
|
<slot />
|
|
|
|
</div>
|