anki/ts/deckoptions/WithTooltip.svelte

31 lines
746 B
Svelte
Raw Normal View History

2021-06-05 14:33:35 +02:00
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import { onDestroy } from "svelte";
2021-06-05 14:33:35 +02:00
import Tooltip from "bootstrap/js/dist/tooltip";
export let tooltip: string;
let tooltipObject: Tooltip;
2021-06-05 14:33:35 +02:00
function createTooltip(element: HTMLElement): void {
element.title = tooltip;
tooltipObject = new Tooltip(element, {
2021-06-05 14:33:35 +02:00
placement: "bottom",
html: true,
offset: [0, 20],
delay: { show: 250, hide: 0 },
2021-06-05 14:33:35 +02:00
});
}
onDestroy(() => {
if (tooltipObject) {
tooltipObject.dispose();
}
});
2021-06-05 14:33:35 +02:00
</script>
<slot {createTooltip} />