Skip to content

Commit

Permalink
feat(vue): Add image viewer in images mosaic
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Ribiere committed Oct 24, 2024
1 parent df41c12 commit 035490d
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions vue/src/components/content/ImagesMosaic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
:key="index"
:class="imageClasses[index]"
:style="`background-image: url('${(image as MediaObject).contentUrl ? (image as MediaObject).contentUrl : (image as string)}')`"
/>
@click="viewImage(image)"
/>
</ul>
</div>
<v-dialog
v-model="showImageViewer"
width="auto"
>
<img
:src="imageViewerSrc"
class="ImageViewer" />
</v-dialog>
</template>

<script setup lang="ts">
Expand All @@ -19,6 +28,12 @@ const props = defineProps<{
images: (string | MediaObject)[];
}>();
onMounted(() => {
props.images.forEach((image, index) => {
classifyImage(image, index);
});
});
const imageClasses = ref<string[]>(Array(props.images.length).fill('MosaicImg--square'));
const classifyImage = (image: string | MediaObject, index: number) => {
Expand All @@ -38,11 +53,16 @@ const classifyImage = (image: string | MediaObject, index: number) => {
};
};
onMounted(() => {
props.images.forEach((image, index) => {
classifyImage(image, index);
});
});
const imageViewerSrc = ref<string>('');
const showImageViewer = ref<boolean>(false);
function viewImage(image: string | MediaObject) {
if (typeof image === 'string') {
imageViewerSrc.value = image;
} else {
imageViewerSrc.value = (image as MediaObject).contentUrl;
}
showImageViewer.value = true;
}
</script>

<style lang="scss">
Expand All @@ -62,6 +82,7 @@ onMounted(() => {
background-size: cover;
border-radius: 0.5rem;
overflow: hidden;
cursor: pointer;
&.MosaicImg--square {
width: 18rem;
Expand All @@ -80,4 +101,9 @@ onMounted(() => {
}
}
}
.ImageViewer{
background-color: white;
max-width: 90vw;
max-height: 90vh;
}
</style>

0 comments on commit 035490d

Please sign in to comment.