2020-06-02 22:30:17 -06:00
|
|
|
<template>
|
2022-01-25 07:18:21 -07:00
|
|
|
<transition :name="$store.state.animation ? 'tooltip' : ''" appear @after-leave="$emit('closed')">
|
2021-12-10 02:20:41 -07:00
|
|
|
<div v-show="showing" ref="el" class="buebdbiu _acrylic _shadow" :style="{ zIndex, maxWidth: maxWidth + 'px' }">
|
2020-06-02 22:30:17 -06:00
|
|
|
<slot>{{ text }}</slot>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-11-28 04:07:37 -07:00
|
|
|
import { defineComponent, nextTick, onMounted, onUnmounted, ref } from 'vue';
|
2021-12-10 02:20:41 -07:00
|
|
|
import * as os from '@/os';
|
2020-06-02 22:30:17 -06:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
export default defineComponent({
|
2020-06-02 22:30:17 -06:00
|
|
|
props: {
|
2020-10-17 05:12:00 -06:00
|
|
|
showing: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-06-02 22:30:17 -06:00
|
|
|
source: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
2021-10-23 23:39:24 -06:00
|
|
|
},
|
|
|
|
maxWidth: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 250,
|
|
|
|
},
|
2020-06-02 22:30:17 -06:00
|
|
|
},
|
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
emits: ['closed'],
|
2020-06-02 22:30:17 -06:00
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
setup(props, context) {
|
|
|
|
const el = ref<HTMLElement>();
|
2021-12-17 20:12:47 -07:00
|
|
|
const zIndex = os.claimZIndex('high');
|
2021-11-28 04:07:37 -07:00
|
|
|
|
|
|
|
const setPosition = () => {
|
|
|
|
if (el.value == null) return;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
const rect = props.source.getBoundingClientRect();
|
2020-06-02 22:30:17 -06:00
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
const contentWidth = el.value.offsetWidth;
|
|
|
|
const contentHeight = el.value.offsetHeight;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
let left = rect.left + window.pageXOffset + (props.source.offsetWidth / 2);
|
2021-04-17 08:53:05 -06:00
|
|
|
let top = rect.top + window.pageYOffset - contentHeight;
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
left -= (el.value.offsetWidth / 2);
|
2021-02-16 06:17:13 -07:00
|
|
|
|
|
|
|
if (left + contentWidth - window.pageXOffset > window.innerWidth) {
|
|
|
|
left = window.innerWidth - contentWidth + window.pageXOffset - 1;
|
|
|
|
}
|
|
|
|
|
2021-04-17 08:53:05 -06:00
|
|
|
if (top - window.pageYOffset < 0) {
|
2021-11-28 04:07:37 -07:00
|
|
|
top = rect.top + window.pageYOffset + props.source.offsetHeight;
|
|
|
|
el.value.style.transformOrigin = 'center top';
|
2021-02-16 06:17:13 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 04:07:37 -07:00
|
|
|
el.value.style.left = left + 'px';
|
|
|
|
el.value.style.top = top + 'px';
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
if (props.source == null) {
|
|
|
|
context.emit('closed');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPosition();
|
|
|
|
|
|
|
|
let loopHandler;
|
|
|
|
|
|
|
|
const loop = () => {
|
|
|
|
loopHandler = window.requestAnimationFrame(() => {
|
|
|
|
setPosition();
|
|
|
|
loop();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
loop();
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.cancelAnimationFrame(loopHandler);
|
|
|
|
});
|
|
|
|
});
|
2020-06-02 22:30:17 -06:00
|
|
|
});
|
2021-11-28 04:07:37 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
el,
|
2021-12-10 02:20:41 -07:00
|
|
|
zIndex,
|
2021-11-28 04:07:37 -07:00
|
|
|
};
|
2020-06-02 22:30:17 -06:00
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-02-16 06:17:13 -07:00
|
|
|
.tooltip-enter-active,
|
|
|
|
.tooltip-leave-active {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
.tooltip-enter-from,
|
|
|
|
.tooltip-leave-active {
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.75);
|
|
|
|
}
|
|
|
|
|
2020-06-02 22:30:17 -06:00
|
|
|
.buebdbiu {
|
|
|
|
position: absolute;
|
|
|
|
font-size: 0.8em;
|
2020-10-17 05:12:00 -06:00
|
|
|
padding: 8px 12px;
|
2021-10-23 23:39:24 -06:00
|
|
|
box-sizing: border-box;
|
2020-06-02 22:30:17 -06:00
|
|
|
text-align: center;
|
|
|
|
border-radius: 4px;
|
2021-10-23 23:39:24 -06:00
|
|
|
border: solid 0.5px var(--divider);
|
2020-06-02 22:30:17 -06:00
|
|
|
pointer-events: none;
|
2021-04-17 08:53:05 -06:00
|
|
|
transform-origin: center bottom;
|
2020-06-02 22:30:17 -06:00
|
|
|
}
|
|
|
|
</style>
|