anki/ts/deckoptions/WithTooltip.svelte

43 lines
1020 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";
type TriggerType =
| "hover focus"
| "click"
| "hover"
| "focus"
| "manual"
| "click hover"
| "click focus"
| "click hover focus";
2021-06-05 14:33:35 +02:00
export let tooltip: string;
export let trigger: TriggerType = "hover focus";
2021-06-05 14:33:35 +02:00
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 },
trigger,
2021-06-05 14:33:35 +02:00
});
}
onDestroy(() => {
if (tooltipObject) {
tooltipObject.dispose();
}
});
2021-06-05 14:33:35 +02:00
</script>
<slot {createTooltip} />