anki/ts/graphs/Tooltip.svelte
Damien Elmes 0026506543 update ts deps
- prettier's formatting has changed, so files needed to be reformatted
- dart is spitting out deprecation warnings like:

254 │   2: $spacer / 2,
    │      ^^^^^^^^^^^
    ╵
    bazel-out/darwin-fastbuild/bin/ts/sass/bootstrap/_variables.scss 254:6  @import
    ts/sass/button_mixins.scss 2:9                                          @use
    ts/components/ColorPicker.svelte 2:5                                    root stylesheet

DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0.

Recommendation: math.div($grid-gutter-width, 2)
2021-05-26 09:37:40 +10:00

52 lines
1.2 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">
export let html = "";
export let x: number = 0;
export let y: number = 0;
export let show = true;
let container = null as unknown as HTMLDivElement;
let adjustedX: number, adjustedY: number;
let shiftLeftAmount = 0;
$: shiftLeftAmount = container
? Math.round(container.clientWidth * 1.2 * (x / document.body.clientWidth))
: 0;
$: {
// move tooltip away from edge as user approaches right side
adjustedX = x + 40 - shiftLeftAmount;
adjustedY = y + 40;
}
</script>
<div
bind:this={container}
class="tooltip"
style="left: {adjustedX}px; top: {adjustedY}px; opacity: {show ? 1 : 0}"
>
{@html html}
</div>
<style lang="scss">
.tooltip {
position: absolute;
padding: 15px;
border-radius: 5px;
font-size: 15px;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
color: var(--text-fg);
background: var(--tooltip-bg);
:global(table) {
border-spacing: 1em 0;
}
}
</style>