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