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

35 lines
654 B
Svelte
Raw Normal View History

<script lang="ts">
import { onDestroy } from 'svelte';
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;
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,
2024-03-02 09:27:01 +00:00
allowHTML: true,
touch: touch
2024-03-02 09:20:50 +00:00
});
}
}
onDestroy(() => {
if (tooltipInstance) {
2024-03-02 09:20:50 +00:00
tooltipInstance.destroy();
}
});
</script>
2024-03-04 21:58:39 +00:00
<div bind:this={tooltipElement} aria-label={content}>
<slot />
</div>