hippofish/packages/client/src/components/MkUrlPreviewPopup.vue

55 lines
1.1 KiB
Vue
Raw Normal View History

2020-02-09 18:59:00 +01:00
<template>
2023-04-08 02:01:42 +02:00
<div
class="fgmtyycl"
:style="{ zIndex, top: top + 'px', left: left + 'px' }"
>
<transition
:name="defaultStore.state.animation ? 'zoom' : ''"
2023-04-08 02:01:42 +02:00
@after-leave="emit('closed')"
>
<MkUrlPreview v-if="showing" class="_popup _shadow" :url="url" />
</transition>
</div>
2020-02-09 18:59:00 +01:00
</template>
2022-09-05 11:37:41 +02:00
<script lang="ts" setup>
import { onMounted, ref } from "vue";
2023-04-08 02:01:42 +02:00
import MkUrlPreview from "@/components/MkUrlPreview.vue";
import * as os from "@/os";
import { defaultStore } from "@/store";
2020-02-09 18:59:00 +01:00
2022-09-05 11:37:41 +02:00
const props = defineProps<{
showing: boolean;
url: string;
source: HTMLElement;
}>();
2020-02-09 18:59:00 +01:00
2022-09-05 11:37:41 +02:00
const emit = defineEmits<{
2023-04-08 02:01:42 +02:00
(ev: "closed"): void;
2022-09-05 11:37:41 +02:00
}>();
2020-02-09 18:59:00 +01:00
2023-04-08 02:01:42 +02:00
const zIndex = os.claimZIndex("middle");
2023-09-02 01:27:33 +02:00
const top = ref(0);
const left = ref(0);
2020-02-09 18:59:00 +01:00
2022-09-05 11:37:41 +02:00
onMounted(() => {
const rect = props.source.getBoundingClientRect();
2023-04-08 02:01:42 +02:00
const x =
Math.max(rect.left + props.source.offsetWidth / 2 - 300 / 2, 6) +
window.scrollX;
const y = rect.top + props.source.offsetHeight + window.scrollY;
2020-02-09 18:59:00 +01:00
top.value = y;
left.value = x;
2020-02-09 18:59:00 +01:00
});
</script>
<style lang="scss" scoped>
.fgmtyycl {
position: absolute;
2020-02-09 19:13:24 +01:00
width: 500px;
max-width: calc(90vw - 12px);
2020-02-09 19:13:24 +01:00
pointer-events: none;
2020-02-09 18:59:00 +01:00
}
</style>