From 5e80e21637817a694e1770adb62d526c344cdfb5 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Sat, 31 May 2025 12:15:00 +0100 Subject: [PATCH] add Micromodal for preview images --- web/src/components/MicroModalInit.astro | 11 +++++ web/src/components/PreviewImages.astro | 43 ++++++++++++++++---- web/src/styles/custom.css | 54 ++++++++++++++++++++++++- 3 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 web/src/components/MicroModalInit.astro diff --git a/web/src/components/MicroModalInit.astro b/web/src/components/MicroModalInit.astro new file mode 100644 index 00000000..6cb13e3f --- /dev/null +++ b/web/src/components/MicroModalInit.astro @@ -0,0 +1,11 @@ +--- +// MicroModalInit.astro +--- + + diff --git a/web/src/components/PreviewImages.astro b/web/src/components/PreviewImages.astro index a772c4b0..6fe351d4 100644 --- a/web/src/components/PreviewImages.astro +++ b/web/src/components/PreviewImages.astro @@ -1,22 +1,51 @@ --- import { Image } from 'astro:assets'; import { getAssetImagePath } from '@src/utils/general'; - +import MicroModalInit from '@src/components/MicroModalInit.astro'; interface Props { images?: any; } -const { images } = Astro.props; +let { images } = Astro.props; + +// Assign id to each image for modal functionality +images = images.map((imageInfo: any, index: number) => { + return { + ...imageInfo, + id: `image-modal-${index}`, + }; +}); --- {images && images.length > 0 && (
{images.map((imageInfo: any) => ( - {imageInfo.description + + {imageInfo.description + + + ))}
-)} \ No newline at end of file +)} + + \ No newline at end of file diff --git a/web/src/styles/custom.css b/web/src/styles/custom.css index d7ddad8a..75e02ead 100644 --- a/web/src/styles/custom.css +++ b/web/src/styles/custom.css @@ -65,4 +65,56 @@ .mta-keyword-link:hover { font-weight: 100; -} \ No newline at end of file +} + +/* Micromodal */ +.modal { display: none; } +.modal.is-open { display: block; } + +.modal__overlay { + background: rgba(0, 0, 0, 0.8); + position: fixed; + inset: 0; + display: flex; + justify-content: center; + align-items: center; + z-index: 1000; +} + +.modal__container { + max-width: 90vw; + max-height: 90vh; + overflow: visible; + position: relative; +} + +.modal__content { + padding: 0; + margin: 0; +} + +.modal__image { + display: block; + max-width: 100%; + max-height: 90vh; + object-fit: contain; +} + +.modal__close { + position: absolute; + top: 0; + right: 0; + transform: translate(50%, -50%); /* Shift to place center of the circle at corner */ + background-color: var(--sl-color-black); + color: var(--sl-color-white); + border: none; + border-radius: 50%; + width: 24px; + height: 24px; + font-size: 24px; + font-weight: bold; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; +}