From 149edaecab3d160a1f480160caee055e2aff28bf Mon Sep 17 00:00:00 2001
From: syuilo <Syuilotan@yahoo.co.jp>
Date: Sat, 29 Jan 2022 03:03:23 +0900
Subject: refactor(client): use setup sugar

---
 packages/client/src/components/ui/tooltip.vue | 141 +++++++++++---------------
 1 file changed, 62 insertions(+), 79 deletions(-)

(limited to 'packages/client/src/components/ui/tooltip.vue')

diff --git a/packages/client/src/components/ui/tooltip.vue b/packages/client/src/components/ui/tooltip.vue
index 394b068352..e2721ed69a 100644
--- a/packages/client/src/components/ui/tooltip.vue
+++ b/packages/client/src/components/ui/tooltip.vue
@@ -1,99 +1,82 @@
 <template>
-<transition :name="$store.state.animation ? 'tooltip' : ''" appear @after-leave="$emit('closed')">
+<transition :name="$store.state.animation ? 'tooltip' : ''" appear @after-leave="emit('closed')">
 	<div v-show="showing" ref="el" class="buebdbiu _acrylic _shadow" :style="{ zIndex, maxWidth: maxWidth + 'px' }">
 		<slot>{{ text }}</slot>
 	</div>
 </transition>
 </template>
 
-<script lang="ts">
-import { defineComponent, nextTick, onMounted, onUnmounted, ref } from 'vue';
+<script lang="ts" setup>
+import { nextTick, onMounted, onUnmounted, ref } from 'vue';
 import * as os from '@/os';
 
-export default defineComponent({
-	props: {
-		showing: {
-			type: Boolean,
-			required: true,
-		},
-		source: {
-			required: true,
-		},
-		text: {
-			type: String,
-			required: false
-		},
-		maxWidth: {
-			type: Number,
-			required: false,
-			default: 250,
-		},
-	},
-
-	emits: ['closed'],
-
-	setup(props, context) {
-		const el = ref<HTMLElement>();
-		const zIndex = os.claimZIndex('high');
-
-		const setPosition = () => {
-			if (el.value == null) return;
-
-			const rect = props.source.getBoundingClientRect();
-
-			const contentWidth = el.value.offsetWidth;
-			const contentHeight = el.value.offsetHeight;
-
-			let left = rect.left + window.pageXOffset + (props.source.offsetWidth / 2);
-			let top = rect.top + window.pageYOffset - contentHeight;
-
-			left -= (el.value.offsetWidth / 2);
-
-			if (left + contentWidth - window.pageXOffset > window.innerWidth) {
-				left = window.innerWidth - contentWidth + window.pageXOffset - 1;
-			}
-
-			if (top - window.pageYOffset < 0) {
-				top = rect.top + window.pageYOffset + props.source.offsetHeight;
-				el.value.style.transformOrigin = 'center top';
-			}
-
-			el.value.style.left = left + 'px';
-			el.value.style.top = top + 'px';
-		};
+const props = withDefaults(defineProps<{
+	showing: boolean;
+	source: HTMLElement;
+	text?: string;
+	maxWidth?; number;
+}>(), {
+	maxWidth: 250,
+});
 
-		onMounted(() => {
-			nextTick(() => {
-				if (props.source == null) {
-					context.emit('closed');
-					return;
-				}
+const emit = defineEmits<{
+	(ev: 'closed'): void;
+}>();
 
-				setPosition();
+const el = ref<HTMLElement>();
+const zIndex = os.claimZIndex('high');
 
-				let loopHandler;
+const setPosition = () => {
+	if (el.value == null) return;
 
-				const loop = () => {
-					loopHandler = window.requestAnimationFrame(() => {
-						setPosition();
-						loop();
-					});
-				};
+	const rect = props.source.getBoundingClientRect();
 
-				loop();
+	const contentWidth = el.value.offsetWidth;
+	const contentHeight = el.value.offsetHeight;
 
-				onUnmounted(() => {
-					window.cancelAnimationFrame(loopHandler);
-				});
-			});
-		});
+	let left = rect.left + window.pageXOffset + (props.source.offsetWidth / 2);
+	let top = rect.top + window.pageYOffset - contentHeight;
+
+	left -= (el.value.offsetWidth / 2);
+
+	if (left + contentWidth - window.pageXOffset > window.innerWidth) {
+		left = window.innerWidth - contentWidth + window.pageXOffset - 1;
+	}
+
+	if (top - window.pageYOffset < 0) {
+		top = rect.top + window.pageYOffset + props.source.offsetHeight;
+		el.value.style.transformOrigin = 'center top';
+	}
+
+	el.value.style.left = left + 'px';
+	el.value.style.top = top + 'px';
+};
 
-		return {
-			el,
-			zIndex,
+onMounted(() => {
+	nextTick(() => {
+		if (props.source == null) {
+			emit('closed');
+			return;
+		}
+
+		setPosition();
+
+		let loopHandler;
+
+		const loop = () => {
+			loopHandler = window.requestAnimationFrame(() => {
+				setPosition();
+				loop();
+			});
 		};
-	},
-})
+
+		loop();
+
+		onUnmounted(() => {
+			window.cancelAnimationFrame(loopHandler);
+		});
+	});
+});
 </script>
 
 <style lang="scss" scoped>
-- 
cgit v1.2.3-freya

