summaryrefslogtreecommitdiff
path: root/src/client/components/ui/tooltip.vue
blob: 6ea344c54d6e43db187f1151567093a713c40103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
<transition name="zoom-in-top" appear @after-leave="$emit('closed')">
	<div class="buebdbiu _acrylic _shadow" v-if="showing">
		<slot>{{ text }}</slot>
	</div>
</transition>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
	props: {
		showing: {
			type: Boolean,
			required: true,
		},
		source: {
			required: true,
		},
		text: {
			type: String,
			required: false
		}
	},

	emits: ['closed'],

	mounted() {
		this.$nextTick(() => {
			if (this.source == null) {
				this.$emit('closed');
				return;
			}

			const rect = this.source.getBoundingClientRect();

			let x = rect.left + window.pageXOffset + (this.source.offsetWidth / 2);
			let y = rect.top + window.pageYOffset + this.source.offsetHeight;

			x -= (this.$el.offsetWidth / 2);

			this.$el.style.left = x + 'px';
			this.$el.style.top = y + 'px';
		});
	},
})
</script>

<style lang="scss" scoped>
.buebdbiu {
	position: absolute;
	z-index: 11000;
	max-width: 240px;
	font-size: 0.8em;
	padding: 8px 12px;
	text-align: center;
	border-radius: 4px;
	pointer-events: none;
	transform-origin: center -16px;
}
</style>