summaryrefslogtreecommitdiff
path: root/src/client/components/ui/tooltip.vue
blob: b7a56708b7fee327fcd53d4e75d614196b9095aa (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
<transition name="zoom-in-top" appear>
	<div class="buebdbiu" v-if="show">
		<slot>{{ text }}</slot>
	</div>
</transition>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
	props: {
		source: {
			required: true,
		},
		text: {
			type: String,
			required: false
		}
	},

	data() {
		return {
			show: false
		};
	},

	mounted() {
		this.show = true;

		this.$nextTick(() => {
			if (this.source == null) {
				this.destroyDom();
				return;
			}
			const rect = this.source.getBoundingClientRect();

			const x = rect.left + window.pageXOffset + (this.source.offsetWidth / 2);
			const y = rect.top + window.pageYOffset + this.source.offsetHeight;
			this.$el.style.left = (x - 28) + 'px';
			this.$el.style.top = (y + 16) + 'px';
		});
	},

	methods: {
		close() {
			this.show = false;
			setTimeout(this.destroyDom, 300);
		}
	}
})
</script>

<style lang="scss" scoped>
.buebdbiu {
	z-index: 11000;
	display: block;
	position: absolute;
	max-width: 240px;
	font-size: 0.8em;
	padding: 6px 8px;
	background: var(--panel);
	text-align: center;
	border-radius: 4px;
	box-shadow: 0 2px 8px rgba(0,0,0,0.25);
	pointer-events: none;
	transform-origin: center -16px;

	&:before {
		content: "";
		pointer-events: none;
		display: block;
		position: absolute;
		top: -28px;
		left: 12px;
		border-top: solid 14px transparent;
		border-right: solid 14px transparent;
		border-bottom: solid 14px rgba(0,0,0,0.1);
		border-left: solid 14px transparent;
	}

	&:after {
		content: "";
		pointer-events: none;
		display: block;
		position: absolute;
		top: -27px;
		left: 12px;
		border-top: solid 14px transparent;
		border-right: solid 14px transparent;
		border-bottom: solid 14px var(--panel);
		border-left: solid 14px transparent;
	}
}
</style>