2020-06-03 06:30:17 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<transition
|
|
|
|
:name="$store.state.animation ? 'tooltip' : ''"
|
|
|
|
appear
|
|
|
|
@after-leave="emit('closed')"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
v-show="showing"
|
|
|
|
ref="el"
|
|
|
|
class="buebdbiu _acrylic _shadow"
|
|
|
|
:style="{ zIndex, maxWidth: maxWidth + 'px' }"
|
|
|
|
>
|
|
|
|
<slot>
|
|
|
|
<Mfm v-if="asMfm" :text="text" />
|
|
|
|
<span v-else>{{ text }}</span>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</transition>
|
2020-06-03 06:30:17 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-28 19:03:23 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { nextTick, onMounted, onUnmounted, ref } from "vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { calcPopupPosition } from "@/scripts/popup-position";
|
2020-06-03 06:30:17 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
showing: boolean;
|
|
|
|
targetElement?: HTMLElement;
|
|
|
|
x?: number;
|
|
|
|
y?: number;
|
|
|
|
text?: string;
|
|
|
|
asMfm?: boolean;
|
|
|
|
maxWidth?: number;
|
|
|
|
direction?: "top" | "bottom" | "right" | "left";
|
|
|
|
innerMargin?: number;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
maxWidth: 250,
|
|
|
|
direction: "top",
|
|
|
|
innerMargin: 0,
|
|
|
|
}
|
|
|
|
);
|
2021-11-28 12:07:37 +01:00
|
|
|
|
2022-01-28 19:03:23 +01:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "closed"): void;
|
2022-01-28 19:03:23 +01:00
|
|
|
}>();
|
2021-11-28 12:07:37 +01:00
|
|
|
|
2022-01-28 19:03:23 +01:00
|
|
|
const el = ref<HTMLElement>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const zIndex = os.claimZIndex("high");
|
2021-11-28 12:07:37 +01:00
|
|
|
|
2022-07-17 14:06:33 +02:00
|
|
|
function setPosition() {
|
|
|
|
const data = calcPopupPosition(el.value, {
|
|
|
|
anchorElement: props.targetElement,
|
|
|
|
direction: props.direction,
|
2023-04-08 02:01:42 +02:00
|
|
|
align: "center",
|
2022-07-17 14:06:33 +02:00
|
|
|
innerMargin: props.innerMargin,
|
|
|
|
x: props.x,
|
|
|
|
y: props.y,
|
|
|
|
});
|
2022-01-28 19:03:23 +01:00
|
|
|
|
2022-07-17 14:06:33 +02:00
|
|
|
el.value.style.transformOrigin = data.transformOrigin;
|
2023-04-08 02:01:42 +02:00
|
|
|
el.value.style.left = data.left + "px";
|
|
|
|
el.value.style.top = data.top + "px";
|
2022-07-17 14:06:33 +02:00
|
|
|
}
|
2021-11-28 12:07:37 +01:00
|
|
|
|
2022-02-12 09:29:15 +01:00
|
|
|
let loopHandler;
|
|
|
|
|
2022-01-28 19:03:23 +01:00
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
setPosition();
|
|
|
|
|
|
|
|
const loop = () => {
|
|
|
|
loopHandler = window.requestAnimationFrame(() => {
|
|
|
|
setPosition();
|
|
|
|
loop();
|
|
|
|
});
|
2021-11-28 12:07:37 +01:00
|
|
|
};
|
2022-01-28 19:03:23 +01:00
|
|
|
|
|
|
|
loop();
|
|
|
|
});
|
|
|
|
});
|
2022-02-12 09:29:15 +01:00
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.cancelAnimationFrame(loopHandler);
|
|
|
|
});
|
2020-06-03 06:30:17 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-02-16 14:17:13 +01:00
|
|
|
.tooltip-enter-active,
|
|
|
|
.tooltip-leave-active {
|
|
|
|
opacity: 1;
|
|
|
|
transform: scale(1);
|
2023-04-08 02:01:42 +02:00
|
|
|
transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1),
|
|
|
|
opacity 200ms cubic-bezier(0.23, 1, 0.32, 1);
|
2021-02-16 14:17:13 +01:00
|
|
|
}
|
|
|
|
.tooltip-enter-from,
|
|
|
|
.tooltip-leave-active {
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.75);
|
|
|
|
}
|
|
|
|
|
2020-06-03 06:30:17 +02:00
|
|
|
.buebdbiu {
|
|
|
|
position: absolute;
|
|
|
|
font-size: 0.8em;
|
2020-10-17 13:12:00 +02:00
|
|
|
padding: 8px 12px;
|
2021-10-24 07:39:24 +02:00
|
|
|
box-sizing: border-box;
|
2020-06-03 06:30:17 +02:00
|
|
|
text-align: center;
|
|
|
|
border-radius: 4px;
|
2021-10-24 07:39:24 +02:00
|
|
|
border: solid 0.5px var(--divider);
|
2020-06-03 06:30:17 +02:00
|
|
|
pointer-events: none;
|
2022-01-31 13:07:33 +01:00
|
|
|
transform-origin: center center;
|
2020-06-03 06:30:17 +02:00
|
|
|
}
|
|
|
|
</style>
|