Skip to main content

PostImages

Location: src/components/post-parts/PostImages.jsx

Overview​

PostImages renders an adaptive image gallery within a post card. The layout changes based on the number of images: single image at full width, two images side by side, three in a 1+2 arrangement, and four or more in a 2x2 grid with a "+N" overlay for additional images.

Clicking any image triggers the lightbox via the onImageClick callback. All click events stop propagation to prevent the parent post card's navigation handler from firing.

Props​

PropTypeRequiredDefaultDescription
imagesstring[]Yes--Array of image URLs to display
onImageClickfunctionYes--Callback receiving (index, triggerElement) when an image is clicked

Layout Rules​

Image CountLayoutCSS Class
0Nothing rendered--
1Single full-width imagepost-images-1
2Two images side by sidepost-images-2
3One large image + two smaller stackedpost-images-3
4+2x2 grid; 4th image shows "+N" overlay for extraspost-images-4

Key Behaviors​

  • Adaptive Grid: The component selects the appropriate layout based on images.length.
  • Overflow Indicator: When there are more than 4 images, only 4 are displayed with a "+N" overlay on the last one showing how many more exist.
  • Click Handling: Each image is a <button> element for accessibility. Clicks call onImageClick(index, element) where the element is used for lightbox focus return.
  • Event Isolation: All click events call e.stopPropagation() to prevent the post card from navigating to the detail view.

Usage​

import PostImages from '@/components/post-parts/PostImages';

<PostImages
images={imageUrls}
onImageClick={(index, trigger) => openLightbox(index, trigger)}
/>
  • Post -- Parent component that renders PostImages
  • Lightbox -- Full-screen image viewer opened by clicking images
  • PostDetail -- Has its own inline image gallery

Last updated: 2026-02-07