2020-06-03 04:30:17 +00:00
|
|
|
<template>
|
2022-01-28 18:03:23 +00:00
|
|
|
<transition :name="$store.state.animation ? 'tooltip' : ''" appear @after-leave="emit('closed')">
|
2021-12-10 09:20:41 +00:00
|
|
|
<div v-show="showing" ref="el" class="buebdbiu _acrylic _shadow" :style="{ zIndex, maxWidth: maxWidth + 'px' }">
|
2020-06-03 04:30:17 +00:00
|
|
|
<slot>{{ text }}</slot>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
2021-12-10 09:20:41 +00:00
|
|
|
import * as os from '@/os';
|
2020-06-03 04:30:17 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
showing: boolean;
|
2022-01-31 12:07:33 +00:00
|
|
|
targetElement?: HTMLElement;
|
|
|
|
x?: number;
|
|
|
|
y?: number;
|
2022-01-28 18:03:23 +00:00
|
|
|
text?: string;
|
2022-01-31 12:07:33 +00:00
|
|
|
maxWidth?: number;
|
2022-01-28 18:03:23 +00:00
|
|
|
}>(), {
|
|
|
|
maxWidth: 250,
|
|
|
|
});
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
}>();
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const el = ref<HTMLElement>();
|
|
|
|
const zIndex = os.claimZIndex('high');
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const setPosition = () => {
|
|
|
|
if (el.value == null) return;
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
const contentWidth = el.value.offsetWidth;
|
|
|
|
const contentHeight = el.value.offsetHeight;
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-31 12:07:33 +00:00
|
|
|
let left: number;
|
|
|
|
let top: number;
|
|
|
|
|
|
|
|
let rect: DOMRect;
|
|
|
|
|
|
|
|
if (props.targetElement) {
|
|
|
|
rect = props.targetElement.getBoundingClientRect();
|
|
|
|
|
|
|
|
left = rect.left + window.pageXOffset + (props.targetElement.offsetWidth / 2);
|
|
|
|
top = rect.top + window.pageYOffset - contentHeight;
|
|
|
|
|
|
|
|
el.value.style.transformOrigin = 'center bottom';
|
|
|
|
} else {
|
|
|
|
left = props.x;
|
|
|
|
top = props.y - contentHeight;
|
|
|
|
}
|
2022-01-28 18:03:23 +00:00
|
|
|
|
|
|
|
left -= (el.value.offsetWidth / 2);
|
|
|
|
|
|
|
|
if (left + contentWidth - window.pageXOffset > window.innerWidth) {
|
|
|
|
left = window.innerWidth - contentWidth + window.pageXOffset - 1;
|
|
|
|
}
|
|
|
|
|
2022-01-31 12:07:33 +00:00
|
|
|
// ツールチップを上に向かって表示するスペースがなければ下に向かって出す
|
2022-01-28 18:03:23 +00:00
|
|
|
if (top - window.pageYOffset < 0) {
|
2022-01-31 12:07:33 +00:00
|
|
|
if (props.targetElement) {
|
|
|
|
top = rect.top + window.pageYOffset + props.targetElement.offsetHeight;
|
|
|
|
el.value.style.transformOrigin = 'center top';
|
|
|
|
} else {
|
|
|
|
top = props.y;
|
|
|
|
}
|
2022-01-28 18:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
el.value.style.left = left + 'px';
|
|
|
|
el.value.style.top = top + 'px';
|
|
|
|
};
|
2021-11-28 11:07:37 +00:00
|
|
|
|
2022-01-28 18:03:23 +00:00
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
setPosition();
|
|
|
|
|
|
|
|
let loopHandler;
|
|
|
|
|
|
|
|
const loop = () => {
|
|
|
|
loopHandler = window.requestAnimationFrame(() => {
|
|
|
|
setPosition();
|
|
|
|
loop();
|
|
|
|
});
|
2021-11-28 11:07:37 +00:00
|
|
|
};
|
2022-01-28 18:03:23 +00:00
|
|
|
|
|
|
|
loop();
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.cancelAnimationFrame(loopHandler);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-03 04:30:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-02-16 13:17:13 +00: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-03 04:30:17 +00:00
|
|
|
.buebdbiu {
|
|
|
|
position: absolute;
|
|
|
|
font-size: 0.8em;
|
2020-10-17 11:12:00 +00:00
|
|
|
padding: 8px 12px;
|
2021-10-24 05:39:24 +00:00
|
|
|
box-sizing: border-box;
|
2020-06-03 04:30:17 +00:00
|
|
|
text-align: center;
|
|
|
|
border-radius: 4px;
|
2021-10-24 05:39:24 +00:00
|
|
|
border: solid 0.5px var(--divider);
|
2020-06-03 04:30:17 +00:00
|
|
|
pointer-events: none;
|
2022-01-31 12:07:33 +00:00
|
|
|
transform-origin: center center;
|
2020-06-03 04:30:17 +00:00
|
|
|
}
|
|
|
|
</style>
|