Frontend School

Interactive Image Gallery

Machine Coding
medium

Interactive Image Gallery

Medium
React
TypeScript
UI Development
State Management
Modal

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.

  1. Thumbnail Grid Display: Render a grid of image thumbnails from the provided mock data. Each thumbnail should be clickable.
  2. 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.
  3. 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.
  4. 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.

Constraints

Constraints & assumptions

  • You are provided with mock image data; no need to fetch data from an external API.
  • Focus on client-side React state management. No external state libraries are required.
  • The image URLs in the mock data are public and will load.
  • Assume a modern browser environment (e.g., Chrome, Firefox, Edge).
  • Prioritize functionality and clean code over pixel-perfect design or extensive animations.
  • The solution should be implemented within the provided App.tsx and styles.css files. Additional components can be defined within App.tsx if desired, or as separate files if time permits.

Out of scope

  • Implementing image upload functionality.
  • Lazy loading images (though a good-to-have if time permits after core features).
  • Complex routing or deep linking for specific images.
  • Full internationalization (i18n).
  • Extensive error handling for image loading failures.

What interviewers evaluate

  • Code Structure & Readability: How well the code is organized, modularized, and easy to understand.
  • React State Management: Effective and idiomatic use of useState and useEffect for managing UI state (e.g., selected image, modal visibility).
  • UI/UX Implementation: Adherence to the specified layout, interactivity, and accessibility requirements.
  • Problem Solving & Logic: Correct implementation of gallery navigation, modal lifecycle, and handling of edge cases (e.g., first/last image, closing modal).
  • Styling & Presentation: Basic but functional styling that makes the application presentable and usable.

Loading editor...