Move WithTooltip to components
This commit is contained in:
parent
3de1d6e604
commit
7058d14d25
38
ts/components/WithTooltip.svelte
Normal file
38
ts/components/WithTooltip.svelte
Normal file
@ -0,0 +1,38 @@
|
||||
<!--
|
||||
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";
|
||||
import Tooltip from "bootstrap/js/dist/tooltip";
|
||||
|
||||
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";
|
||||
|
||||
let tooltipObject: Tooltip;
|
||||
|
||||
function createTooltip(element: HTMLElement): void {
|
||||
element.title = tooltip;
|
||||
tooltipObject = new Tooltip(element, {
|
||||
placement: "bottom",
|
||||
html: true,
|
||||
offset: [0, 20],
|
||||
delay: { show: 250, hide: 0 },
|
||||
trigger,
|
||||
});
|
||||
}
|
||||
|
||||
onDestroy(() => tooltipObject?.dispose());
|
||||
</script>
|
||||
|
||||
<slot {createTooltip} {tooltipObject} />
|
@ -5,7 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
<script lang="typescript">
|
||||
import marked from "marked";
|
||||
import { infoCircle } from "./icons";
|
||||
import WithTooltip from "./WithTooltip.svelte";
|
||||
import WithTooltip from "components/WithTooltip.svelte";
|
||||
import Label from "./Label.svelte";
|
||||
import Badge from "components/Badge.svelte";
|
||||
|
||||
|
@ -32,11 +32,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (tooltipObject) {
|
||||
tooltipObject.dispose();
|
||||
}
|
||||
});
|
||||
onDestroy(() => tooltipObject?.dispose());
|
||||
</script>
|
||||
|
||||
<slot {createTooltip} {tooltipObject} />
|
||||
|
Loading…
Reference in New Issue
Block a user