open-webui/src/lib/components/common/Tooltip.svelte

42 lines
847 B
Svelte
Raw Normal View History

<script lang="ts">
import { onDestroy } from 'svelte';
2024-06-15 10:32:18 +00:00
import { marked } from 'marked';
import tippy from 'tippy.js';
export let placement = 'top';
export let content = `I'm a tooltip!`;
2024-03-02 09:27:01 +00:00
export let touch = true;
export let className = 'flex';
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,
touch: touch
2024-03-02 09:20:50 +00:00
});
}
2024-06-04 18:13:43 +00:00
} else if (tooltipInstance && content === '') {
if (tooltipInstance) {
tooltipInstance.destroy();
}
}
onDestroy(() => {
if (tooltipInstance) {
2024-03-02 09:20:50 +00:00
tooltipInstance.destroy();
}
});
</script>
<div bind:this={tooltipElement} aria-label={content} class={className}>
<slot />
</div>