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

47 lines
1004 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';
2024-07-08 22:26:43 +00:00
import { roundArrow } 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';
2024-07-08 22:26:43 +00:00
export let theme = '';
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-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>