Frontend School

Build an Interactive Image Carousel Component

Machine Coding
medium

Build an Interactive Image Carousel Component

Medium
React
TypeScript
UI
Carousel
Frontend
Component

Overview

At Blinkit, product presentation is crucial for customer engagement and sales. Our product detail pages heavily rely on rich media to showcase items like groceries, electronics, and household essentials. A well-designed image carousel allows customers to effortlessly browse through multiple product angles, variations, or related items, significantly enhancing their shopping experience and aiding in purchase decisions.

This problem challenges you to build a robust and user-friendly image carousel component, similar to what you'd find on our product pages. This component will be reusable across various parts of our application, requiring attention to detail, performance, and accessibility.

What you need to do / Task

Your primary task is to create a functional and visually appealing ImageCarousel React component that displays a series of images.

  1. Component Structure: Create a reusable ImageCarousel component that accepts an array of image data as a prop.
  2. Image Display: Display one image at a time prominently within the carousel.
  3. Navigation Controls: Implement 'Previous' and 'Next' buttons (e.g., left and right arrows) that allow users to cycle through the images.
  4. Pagination Indicators: Add a set of 'dot' indicators (or similar) below the carousel. Each dot should correspond to an image, visually indicating the current image, and allowing users to directly jump to any image by clicking its corresponding dot.
  5. Edge Case Handling: Ensure navigation wraps around (e.g., clicking 'Next' on the last image goes to the first, and 'Previous' on the first goes to the last).

UI/UX expectations

  • Layout: The carousel should have a clear main display area for the current image, with navigation buttons positioned intuitively (e.g., on the sides of the image). Pagination dots should be centered below the image.
  • Interactions:
    • Clicking 'Previous'/'Next' buttons should smoothly transition to the adjacent image.
    • Clicking a pagination dot should smoothly transition to the corresponding image.
    • The active pagination dot should be visually distinct.
  • Accessibility: Ensure navigation buttons have appropriate aria-label attributes and images have alt text (you can use a placeholder for alt if not provided in mock data).
  • Visuals: Implement a subtle transition effect (e.g., fade-in/out or slide) when changing images to enhance user experience.

Acceptance criteria

  • The ImageCarousel component is rendered correctly in App.tsx.
  • It displays the first image from the provided data upon initial render.
  • 'Previous' and 'Next' buttons correctly navigate through images, including wrapping around at the ends.
  • Pagination dots are rendered for each image, with the current image's dot highlighted.
  • Clicking a pagination dot correctly navigates to the corresponding image.
  • Images include basic alt text.
  • Navigation buttons are accessible via aria-label.
  • A smooth visual transition occurs when changing images.

Constraints

Constraints & assumptions

  • You must use React and TypeScript.
  • Do not use any external carousel libraries (e.g., react-slick, swiper). Build the core functionality from scratch.
  • Image data will be provided as an array of simple objects containing url and alt properties.
  • Focus on functional correctness and clean, maintainable code within the given time limit.
  • Assume images are already optimized and preloaded for display; no need to implement lazy loading.

Out of scope

  • Keyboard navigation (e.g., arrow keys).
  • Auto-play functionality.
  • Complex responsiveness beyond basic layout adjustments.
  • Error handling for broken image URLs.

What interviewers evaluate

  • Component Design & Reusability: How well the ImageCarousel component is structured, its props interface, and its potential for reuse.
  • State Management & Logic: Correctness and efficiency of managing the current image state and navigation logic.
  • UI/UX Implementation: Fidelity to the visual and interactive requirements, including transitions and accessibility.
  • Code Quality: Readability, maintainability, adherence to TypeScript best practices, and overall code organization.

Loading editor...