mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.0 KiB
145 lines
4.0 KiB
2 years ago
|
<script lang="ts" setup>
|
||
|
import { onKeyDown } from '@vueuse/core'
|
||
|
import { useAttachmentCell } from './utils'
|
||
2 years ago
|
import { computed, isImage, onClickOutside, ref } from '#imports'
|
||
2 years ago
|
|
||
|
const { selectedImage, visibleItems, downloadFile } = useAttachmentCell()!
|
||
|
|
||
2 years ago
|
const carouselRef = ref()
|
||
2 years ago
|
|
||
|
const imageItems = computed(() => visibleItems.value.filter((item) => isImage(item.title, item.mimetype)))
|
||
|
|
||
2 years ago
|
/** navigate to previous image on button click */
|
||
2 years ago
|
onKeyDown(
|
||
|
(e) => ['Left', 'ArrowLeft', 'A'].includes(e.key),
|
||
|
() => {
|
||
|
if (carouselRef.value) carouselRef.value.prev()
|
||
|
},
|
||
|
)
|
||
|
|
||
2 years ago
|
/** navigate to next image on button click */
|
||
2 years ago
|
onKeyDown(
|
||
|
(e) => ['Right', 'ArrowRight', 'D'].includes(e.key),
|
||
|
() => {
|
||
|
if (carouselRef.value) carouselRef.value.next()
|
||
|
},
|
||
|
)
|
||
|
|
||
2 years ago
|
/** set our selected image when slide changes */
|
||
2 years ago
|
function onSlideChange(index: number) {
|
||
|
selectedImage.value = imageItems.value[index]
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
/** set our carousel ref and move to initial slide */
|
||
|
const setCarouselRef = (el: Element) => {
|
||
|
carouselRef.value = el
|
||
|
|
||
|
carouselRef.value?.goTo(
|
||
|
imageItems.value.findIndex((item) => item === selectedImage.value),
|
||
|
true,
|
||
|
)
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
/** close overlay view when clicking outside of image */
|
||
2 years ago
|
onClickOutside(carouselRef, () => {
|
||
|
selectedImage.value = false
|
||
|
})
|
||
2 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
|
<general-overlay v-model="selectedImage">
|
||
|
<template v-if="selectedImage">
|
||
2 years ago
|
<div class="overflow-hidden p-12 text-center relative">
|
||
2 years ago
|
<div class="text-white group absolute top-5 right-5">
|
||
|
<MdiCloseCircle class="group-hover:text-red-500 cursor-pointer text-4xl" @click.stop="selectedImage = false" />
|
||
|
</div>
|
||
|
|
||
|
<div
|
||
2 years ago
|
class="select-none group hover:ring active:ring-accent cursor-pointer leading-8 inline-block px-3 py-1 bg-gray-300 text-white mb-4 text-center rounded shadow"
|
||
2 years ago
|
@click.stop="downloadFile(selectedImage)"
|
||
|
>
|
||
|
<h3 class="group-hover:text-primary">{{ selectedImage && selectedImage.title }}</h3>
|
||
|
</div>
|
||
|
|
||
|
<a-carousel
|
||
|
v-if="!!selectedImage"
|
||
2 years ago
|
:ref="setCarouselRef"
|
||
2 years ago
|
dots-class="slick-dots slick-thumb"
|
||
|
:after-change="onSlideChange"
|
||
|
arrows
|
||
|
>
|
||
|
<template #prevArrow>
|
||
|
<div class="custom-slick-arrow left-2 z-1">
|
||
2 years ago
|
<MaterialSymbolsArrowCircleLeftRounded class="bg-white rounded-full" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<template #nextArrow>
|
||
|
<div class="custom-slick-arrow !right-2 z-1">
|
||
2 years ago
|
<MaterialSymbolsArrowCircleRightRounded class="bg-white rounded-full" />
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<template #customPaging="props">
|
||
|
<a>
|
||
2 years ago
|
<nuxt-img
|
||
2 years ago
|
class="!block"
|
||
2 years ago
|
:alt="imageItems[props.i].title || `#${props.i}`"
|
||
|
:src="imageItems[props.i].url || imageItems[props.i].data"
|
||
|
/>
|
||
|
</a>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<div v-for="item of imageItems" :key="item.url">
|
||
|
<div
|
||
2 years ago
|
:style="{ backgroundImage: `url('${item.url || item.data}')` }"
|
||
2 years ago
|
class="min-w-70vw min-h-70vh w-full h-full bg-contain bg-center bg-no-repeat"
|
||
|
/>
|
||
2 years ago
|
</div>
|
||
|
</a-carousel>
|
||
|
</div>
|
||
|
</template>
|
||
|
</general-overlay>
|
||
|
</template>
|
||
|
|
||
|
<style scoped>
|
||
|
.ant-carousel :deep(.slick-dots) {
|
||
|
@apply relative mt-4;
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-slide) {
|
||
|
@apply w-full;
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-slide img) {
|
||
|
@apply border-1 m-auto;
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-thumb) {
|
||
|
@apply bottom-2;
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-thumb li) {
|
||
|
@apply w-[60px] h-[45px];
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-thumb li img) {
|
||
|
@apply w-full h-full block;
|
||
|
filter: grayscale(100%);
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep .slick-thumb li.slick-active img {
|
||
|
filter: grayscale(0%);
|
||
|
}
|
||
|
|
||
|
.ant-carousel :deep(.slick-arrow.custom-slick-arrow) {
|
||
2 years ago
|
@apply text-4xl text-white hover:text-primary active:text-accent opacity-100 cursor-pointer z-1;
|
||
2 years ago
|
}
|
||
|
.ant-carousel :deep(.custom-slick-arrow:before) {
|
||
|
display: none;
|
||
|
}
|
||
|
.ant-carousel :deep(.custom-slick-arrow:hover) {
|
||
|
opacity: 0.5;
|
||
|
}
|
||
|
</style>
|