2021-07-08 21:47:27 +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 Tooltip from "bootstrap/js/dist/tooltip";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { onDestroy } from "svelte";
|
2021-07-08 21:47:27 +02:00
|
|
|
|
|
|
|
type TriggerType =
|
|
|
|
| "hover focus"
|
|
|
|
| "click"
|
|
|
|
| "hover"
|
|
|
|
| "focus"
|
|
|
|
| "manual"
|
|
|
|
| "click hover"
|
|
|
|
| "click focus"
|
|
|
|
| "click hover focus";
|
|
|
|
|
|
|
|
export let tooltip: string;
|
|
|
|
export let trigger: TriggerType = "hover focus";
|
|
|
|
|
2021-07-08 23:35:54 +02:00
|
|
|
export let placement: "auto" | "top" | "bottom" | "left" | "right" = "top";
|
|
|
|
export let html = true;
|
|
|
|
export let offset: Tooltip.Offset = [0, 0];
|
|
|
|
export let showDelay = 0;
|
|
|
|
export let hideDelay = 0;
|
|
|
|
|
2023-08-02 12:29:44 +02:00
|
|
|
let tooltipElement: HTMLElement;
|
|
|
|
|
2021-07-08 21:47:27 +02:00
|
|
|
let tooltipObject: Tooltip;
|
|
|
|
function createTooltip(element: HTMLElement): void {
|
2023-08-02 12:29:44 +02:00
|
|
|
tooltipElement = element;
|
2021-07-08 21:47:27 +02:00
|
|
|
element.title = tooltip;
|
|
|
|
tooltipObject = new Tooltip(element, {
|
2021-07-08 23:35:54 +02:00
|
|
|
placement,
|
|
|
|
html,
|
|
|
|
offset,
|
|
|
|
delay: { show: showDelay, hide: hideDelay },
|
2021-07-08 21:47:27 +02:00
|
|
|
trigger,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-02 12:29:44 +02:00
|
|
|
onDestroy(() => {
|
|
|
|
tooltipElement?.addEventListener("hidden.bs.tooltip", () => {
|
|
|
|
tooltipObject?.dispose();
|
|
|
|
});
|
|
|
|
tooltipObject?.hide();
|
|
|
|
});
|
2021-07-08 21:47:27 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<slot {createTooltip} {tooltipObject} />
|
2021-09-15 02:18:42 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
/* tooltip is inserted under the body tag
|
|
|
|
/* long tooltips can cause x-overflow */
|
|
|
|
:global(body) {
|
|
|
|
overflow-x: hidden;
|
|
|
|
}
|
|
|
|
</style>
|