anki/ts/components/WithTooltip.svelte
Henrik Giesel 30bbbaf00b
Use eslint for sorting our imports (#1637)
* Make eslint sort our imports

* fix missing deps in eslint rule (dae)

Caught on Linux due to the stricter sandboxing

* Remove exports-last eslint rule (for now?)

* Adjust browserslist settings

- We use ResizeObserver which is not supported in browsers like KaiOS,
  Baidu or Android UC

* Raise minimum iOS version 13.4

- It's the first version that supports ResizeObserver

* Apply new eslint rules to sort imports
2022-02-04 18:36:34 +10:00

61 lines
1.6 KiB
Svelte

<!--
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";
import { onDestroy } from "svelte";
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";
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;
let tooltipObject: Tooltip;
function createTooltip(element: HTMLElement): void {
element.title = tooltip;
tooltipObject = new Tooltip(element, {
placement,
html,
offset,
delay: { show: showDelay, hide: hideDelay },
trigger,
});
}
onDestroy(() => tooltipObject?.dispose());
// hack to update field description tooltips
let previousTooltip: string = tooltip;
$: if (tooltip !== previousTooltip) {
previousTooltip = tooltip;
const element: HTMLElement = tooltipObject["_element"];
tooltipObject.dispose();
createTooltip(element);
}
</script>
<slot {createTooltip} {tooltipObject} />
<style lang="scss">
/* tooltip is inserted under the body tag
/* long tooltips can cause x-overflow */
:global(body) {
overflow-x: hidden;
}
</style>