monkeeShark/packages/frontend/src/components/MkUrlPreviewPopup.vue

52 lines
1.2 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2020-02-09 17:59:00 +00:00
<template>
2023-05-14 01:21:56 +00:00
<div :class="$style.root" :style="{ zIndex, top: top + 'px', left: left + 'px' }">
2023-05-19 04:58:09 +00:00
<Transition :name="defaultStore.state.animation ? '_transition_zoom' : ''" @afterLeave="emit('closed')">
<MkUrlPreview v-if="showing" class="_popup _shadow" :url="url" :showActions="false"/>
2022-12-30 04:37:14 +00:00
</Transition>
2020-02-09 17:59:00 +00:00
</div>
</template>
2022-09-05 09:37:41 +00:00
<script lang="ts" setup>
import { onMounted } from 'vue';
import MkUrlPreview from '@/components/MkUrlPreview.vue';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { defaultStore } from '@/store.js';
2020-02-09 17:59:00 +00:00
2022-09-05 09:37:41 +00:00
const props = defineProps<{
showing: boolean;
url: string;
source: HTMLElement;
}>();
2020-02-09 17:59:00 +00:00
2022-09-05 09:37:41 +00:00
const emit = defineEmits<{
(ev: 'closed'): void;
}>();
2020-02-09 17:59:00 +00:00
2022-09-05 09:37:41 +00:00
const zIndex = os.claimZIndex('middle');
let top = $ref(0);
let left = $ref(0);
2020-02-09 17:59:00 +00:00
2022-09-05 09:37:41 +00:00
onMounted(() => {
const rect = props.source.getBoundingClientRect();
const x = Math.max((rect.left + (props.source.offsetWidth / 2)) - (300 / 2), 6) + window.pageXOffset;
const y = rect.top + props.source.offsetHeight + window.pageYOffset;
2020-02-09 17:59:00 +00:00
2022-09-05 09:37:41 +00:00
top = y;
left = x;
2020-02-09 17:59:00 +00:00
});
</script>
2023-05-14 01:21:56 +00:00
<style lang="scss" module>
.root {
2020-02-09 17:59:00 +00:00
position: absolute;
2020-02-09 18:13:24 +00:00
width: 500px;
max-width: calc(90vw - 12px);
2020-02-09 18:13:24 +00:00
pointer-events: none;
2020-02-09 17:59:00 +00:00
}
</style>