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

47 lines
1.1 KiB
Vue
Raw Normal View History

2020-02-09 11:59:00 -06:00
<template>
2023-05-13 20:21:56 -05:00
<div :class="$style.root" :style="{ zIndex, top: top + 'px', left: left + 'px' }">
2023-03-31 23:42:40 -05:00
<Transition :name="defaultStore.state.animation ? '_transition_zoom' : ''" @after-leave="emit('closed')">
2021-11-19 04:36:12 -06:00
<MkUrlPreview v-if="showing" class="_popup _shadow" :url="url"/>
2022-12-29 22:37:14 -06:00
</Transition>
2020-02-09 11:59:00 -06:00
</div>
</template>
2022-09-05 04:37:41 -05:00
<script lang="ts" setup>
import { onMounted } from 'vue';
import MkUrlPreview from '@/components/MkUrlPreview.vue';
2021-11-11 11:02:25 -06:00
import * as os from '@/os';
2023-03-31 23:42:40 -05:00
import { defaultStore } from '@/store';
2020-02-09 11:59:00 -06:00
2022-09-05 04:37:41 -05:00
const props = defineProps<{
showing: boolean;
url: string;
source: HTMLElement;
}>();
2020-02-09 11:59:00 -06:00
2022-09-05 04:37:41 -05:00
const emit = defineEmits<{
(ev: 'closed'): void;
}>();
2020-02-09 11:59:00 -06:00
2022-09-05 04:37:41 -05:00
const zIndex = os.claimZIndex('middle');
let top = $ref(0);
let left = $ref(0);
2020-02-09 11:59:00 -06:00
2022-09-05 04:37:41 -05: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 11:59:00 -06:00
2022-09-05 04:37:41 -05:00
top = y;
left = x;
2020-02-09 11:59:00 -06:00
});
</script>
2023-05-13 20:21:56 -05:00
<style lang="scss" module>
.root {
2020-02-09 11:59:00 -06:00
position: absolute;
2020-02-09 12:13:24 -06:00
width: 500px;
max-width: calc(90vw - 12px);
2020-02-09 12:13:24 -06:00
pointer-events: none;
2020-02-09 11:59:00 -06:00
}
</style>