1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-18 08:38:01 +09:00
elk/components/modal/ModalMediaPreview.vue

70 lines
2.0 KiB
Vue
Raw Normal View History

2022-11-30 12:27:19 +09:00
<script setup lang="ts">
const emit = defineEmits(['close'])
const current = computed(() => mediaPreviewList.value[mediaPreviewIndex.value])
const hasNext = computed(() => mediaPreviewIndex.value < mediaPreviewList.value.length - 1)
const hasPrev = computed(() => mediaPreviewIndex.value > 0)
const keys = useMagicKeys()
whenever(keys.arrowLeft, prev)
whenever(keys.arrowRight, next)
function next() {
if (hasNext.value)
mediaPreviewIndex.value++
}
function prev() {
if (hasPrev.value)
mediaPreviewIndex.value--
}
function onClick(e: MouseEvent) {
const path = e.composedPath() as HTMLElement[]
const el = path.find(el => ['A', 'BUTTON', 'IMG', 'VIDEO'].includes(el.tagName?.toUpperCase()))
if (!el)
emit('close')
}
</script>
<template>
2022-12-02 16:02:44 +09:00
<div relative h-full w-full flex select-none pointer-events-none>
<div absolute top-0 left-0 right-0 text-white text-center>
2022-11-30 12:27:19 +09:00
{{ mediaPreviewIndex + 1 }} / {{ mediaPreviewList.length }}
</div>
<button
v-if="hasNext"
pointer-events-auto
btn-action-icon bg="black/20" aria-label="Close"
hover:bg="black/40" dark:bg="white/30" dark:hover:bg="white/20"
absolute top="1/2" right-1
:title="$t('action.next')"
@click="next"
>
<div i-ri:arrow-right-s-line text-white />
2022-11-30 12:27:19 +09:00
</button>
<button
v-if="hasPrev"
pointer-events-auto
btn-action-icon bg="black/20" aria-label="Close"
hover:bg="black/40" dark:bg="white/30" dark:hover:bg="white/20"
absolute top="1/2" left-1
:title="$t('action.prev')"
@click="prev"
>
<div i-ri:arrow-left-s-line text-white />
2022-11-30 12:27:19 +09:00
</button>
<img :src="current.url || current.previewUrl" :alt="current.description || ''" max-h="95%" max-w="95%" ma>
2022-12-02 16:02:44 +09:00
<button
btn-action-icon bg="black/20" aria-label="Close"
hover:bg="black/40" dark:bg="white/30" dark:hover:bg="white/20"
absolute top-0 right-0 m1 pointer-events-auto
@click="emit('close')"
>
<div i-ri:close-fill text-white />
</button>
2022-11-30 12:27:19 +09:00
</div>
</template>