87 lines
2.2 KiB
Vue
87 lines
2.2 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, ref } from 'vue'
|
|
|
|
const props = defineProps<{ source: string }>()
|
|
const emit = defineEmits<{ close: [] }>()
|
|
const dialog = ref<HTMLDialogElement | null>(null)
|
|
const isActualSize = ref<boolean>(false)
|
|
|
|
onMounted((): void => {
|
|
dialog.value?.showModal()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<Teleport to="body">
|
|
<dialog
|
|
ref="dialog"
|
|
class="image-preview"
|
|
aria-label="Просмотр изображения"
|
|
@click.self="emit('close')"
|
|
@cancel.prevent="emit('close')"
|
|
@keydown.stop
|
|
>
|
|
<div class="preview-panel">
|
|
<div class="preview-toolbar">
|
|
<button type="button" @click="isActualSize = !isActualSize">
|
|
{{ isActualSize ? 'Вписать в окно' : 'Исходный размер' }}
|
|
</button>
|
|
<button type="button" aria-label="Закрыть просмотр" @click="emit('close')">Закрыть</button>
|
|
</div>
|
|
<div class="preview-content" :class="{ 'actual-size': isActualSize }">
|
|
<img :src="props.source" alt="Полное изображение" />
|
|
</div>
|
|
</div>
|
|
</dialog>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.image-preview {
|
|
position: fixed;
|
|
inset: 0;
|
|
width: 100vw;
|
|
max-width: none;
|
|
height: 100vh;
|
|
max-height: none;
|
|
margin: 0;
|
|
padding: 24px;
|
|
border: none;
|
|
background: transparent;
|
|
color: var(--text-primary);
|
|
}
|
|
.image-preview::backdrop { background: rgba(0, 0, 0, 0.8); }
|
|
.preview-panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: fit-content;
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
margin: auto;
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
background: var(--bg-primary, #19191e);
|
|
}
|
|
.preview-toolbar {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 12px;
|
|
padding: 10px;
|
|
}
|
|
.preview-toolbar button {
|
|
padding: 6px 12px;
|
|
color: inherit;
|
|
background: transparent;
|
|
border: 1px solid currentColor;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
}
|
|
.preview-content { min-height: 0; overflow: auto; }
|
|
.preview-content img {
|
|
display: block;
|
|
max-width: calc(100vw - 48px);
|
|
max-height: calc(100vh - 110px);
|
|
object-fit: contain;
|
|
}
|
|
.actual-size img { max-width: none; max-height: none; }
|
|
</style>
|