diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-28 20:07:37 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-28 20:07:37 +0900 |
| commit | e8005c8d3a6edf2c8cdce3fe098fb9acff8a57c6 (patch) | |
| tree | 4283a0a36f5cb03f0fb3a534142c06783f8ff725 /packages/client/src/components/ui/tooltip.vue | |
| parent | /antennas/notes API で日付による絞り込みができるようにする... (diff) | |
| download | misskey-e8005c8d3a6edf2c8cdce3fe098fb9acff8a57c6.tar.gz misskey-e8005c8d3a6edf2c8cdce3fe098fb9acff8a57c6.tar.bz2 misskey-e8005c8d3a6edf2c8cdce3fe098fb9acff8a57c6.zip | |
client: refine ui
Diffstat (limited to 'packages/client/src/components/ui/tooltip.vue')
| -rw-r--r-- | packages/client/src/components/ui/tooltip.vue | 63 |
1 files changed, 46 insertions, 17 deletions
diff --git a/packages/client/src/components/ui/tooltip.vue b/packages/client/src/components/ui/tooltip.vue index dbc1a1c9b7..2a63c207fd 100644 --- a/packages/client/src/components/ui/tooltip.vue +++ b/packages/client/src/components/ui/tooltip.vue @@ -1,13 +1,13 @@ <template> <transition name="tooltip" appear @after-leave="$emit('closed')"> - <div v-show="showing" ref="content" class="buebdbiu _acrylic _shadow" :style="{ maxWidth: maxWidth + 'px' }"> + <div v-show="showing" ref="el" class="buebdbiu _acrylic _shadow" :style="{ maxWidth: maxWidth + 'px' }"> <slot>{{ text }}</slot> </div> </transition> </template> <script lang="ts"> -import { defineComponent } from 'vue'; +import { defineComponent, nextTick, onMounted, onUnmounted, ref } from 'vue'; export default defineComponent({ props: { @@ -31,35 +31,64 @@ export default defineComponent({ emits: ['closed'], - mounted() { - this.$nextTick(() => { - if (this.source == null) { - this.$emit('closed'); - return; - } + setup(props, context) { + const el = ref<HTMLElement>(); + + const setPosition = () => { + if (el.value == null) return; - const rect = this.source.getBoundingClientRect(); + const rect = props.source.getBoundingClientRect(); - const contentWidth = this.$refs.content.offsetWidth; - const contentHeight = this.$refs.content.offsetHeight; + const contentWidth = el.value.offsetWidth; + const contentHeight = el.value.offsetHeight; - let left = rect.left + window.pageXOffset + (this.source.offsetWidth / 2); + let left = rect.left + window.pageXOffset + (props.source.offsetWidth / 2); let top = rect.top + window.pageYOffset - contentHeight; - left -= (this.$el.offsetWidth / 2); + 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 + this.source.offsetHeight; - this.$refs.content.style.transformOrigin = 'center top'; + top = rect.top + window.pageYOffset + props.source.offsetHeight; + el.value.style.transformOrigin = 'center top'; } - this.$el.style.left = left + 'px'; - this.$el.style.top = top + 'px'; + 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); + }); + }); }); + + return { + el, + }; }, }) </script> |