Skip to content

Commit be44039

Browse files
committed
refactor ClickableImage component: extract width constants for improved maintainability and enhance modal image styling for responsiveness
1 parent 4f48e1b commit be44039

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/components/ClickableImage.astro

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ interface Props {
88
}
99
1010
const { src, alt, class: className = "" } = Astro.props;
11+
12+
// Image size constants
13+
const THUMBNAIL_WIDTH = 800;
14+
const MODAL_WIDTH = 2000; // 40% bigger than thumbnail (1080 * 1.4)
1115
---
1216

1317
<div class={`clickable-image-container ${className}`}>
1418
<Image
1519
src={src}
1620
alt={alt}
17-
width={800}
21+
width={THUMBNAIL_WIDTH}
1822
class="clickable-image cursor-pointer hover:opacity-80 transition-opacity h-auto"
1923
/>
2024
</div>
@@ -26,7 +30,6 @@ const { src, alt, class: className = "" } = Astro.props;
2630
src={src.src}
2731
alt={alt}
2832
class="object-contain rounded-lg shadow-2xl modal-image"
29-
style="width: 1120px; max-width: 90vw; max-height: 70vh;"
3033
/>
3134

3235
<!-- Close button below the image -->
@@ -127,7 +130,7 @@ const { src, alt, class: className = "" } = Astro.props;
127130
document.addEventListener('astro:page-load', initClickableImages);
128131
</script>
129132

130-
<style>
133+
<style define:vars={{ modalWidth: MODAL_WIDTH + 'px' }}>
131134
.clickable-image-container {
132135
display: inline-block;
133136
position: relative;
@@ -155,7 +158,10 @@ const { src, alt, class: className = "" } = Astro.props;
155158
display: none !important;
156159
}
157160

158-
.image-modal img {
161+
.image-modal .modal-image {
162+
width: var(--modalWidth) !important;
163+
max-width: 90vw !important;
164+
max-height: 70vh !important;
159165
border-radius: 8px;
160166
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
161167
}

0 commit comments

Comments
 (0)