Overview
At Zerodha, showcasing information clearly and interactively is paramount, whether it's for financial charts, product features, or user portfolios. For our internal content management systems and public-facing applications, an efficient and intuitive image gallery component is a fundamental building block. This problem challenges you to build a functional and responsive image gallery that allows users to browse thumbnails and view full-sized images with navigation.
What you need to do / Task
Your goal is to implement an interactive image gallery component using React and TypeScript.
- Thumbnail Grid Display: Render a grid of image thumbnails from the provided mock data. Each thumbnail should be clickable.
- Full-Size Image Modal: When a thumbnail is clicked, open a modal (or overlay) displaying the full-size version of the selected image. The modal should also show the image's title and description.
- Modal Navigation: Implement "Next" and "Previous" buttons within the modal to navigate through the full-size images without closing the modal. Ensure appropriate handling for the first and last images in the gallery.
- Modal Closure: The modal must close when:
- The user clicks outside the image/content area of the modal (on the overlay background).
- The user presses the
Escape key.
UI/UX expectations
- Gallery Grid: Display thumbnails in a responsive grid layout. The exact number of columns can vary based on screen size, but aim for a visually balanced presentation (e.g., 3-4 columns on desktop).
- Thumbnail Interaction: Thumbnails should visually indicate they are clickable (e.g., slight hover effect).
- Image Modal:
- Should be centrally positioned on the screen with a semi-transparent dark overlay covering the rest of the page.
- The full-size image should be prominently displayed, potentially with a maximum height/width to fit within the viewport.
- "Next" and "Previous" navigation buttons should be clearly visible and positioned intuitively (e.g., on the sides of the image).
- The image title and description should be readable below or above the image within the modal.
- Accessibility: Ensure the
Escape key closes the modal, enhancing keyboard navigation for users.
Acceptance criteria
- A grid of image thumbnails is displayed on initial render using the provided
IMAGES data.
- Clicking any thumbnail correctly opens the modal, showing the corresponding full-size image, title, and description.
- The "Next" button in the modal navigates to the subsequent image in the
IMAGES array.
- The "Previous" button in the modal navigates to the preceding image in the
IMAGES array.
- Navigation buttons correctly disable or hide when at the first or last image, respectively.
- Clicking on the modal's overlay background closes the modal.
- Pressing the
Escape key closes the modal.
- The overall UI is functional and reasonably styled for a quick implementation.