Overview
In modern web applications, displaying a collection of images in an engaging and efficient manner is crucial for user experience. Whether it's a product gallery on an e-commerce site, a portfolio showcase, or a photo album in a social media app, an interactive image carousel is a fundamental UI component. This problem challenges you to build a functional and intuitive image carousel, similar to those found across Meta's various platforms, focusing on core state management and user interaction.
What you need to do / Task
Your primary goal is to build a React component that displays a series of images in a carousel format. Specifically, you must:
- Display a Single Image: Render only one image from a given list at a time within the carousel viewport.
- Implement Navigation Buttons: Add "Previous" and "Next" buttons to allow users to cycle through the images.
- Handle Wrap-Around Logic: Ensure that navigating "Next" from the last image goes to the first image, and navigating "Previous" from the first image goes to the last image.
- Implement Dot Indicators: Display a set of clickable dot indicators, one for each image. The dot corresponding to the currently displayed image should be visually distinct (e.g., highlighted).
- Direct Navigation via Dots: Clicking on a dot indicator should immediately navigate the carousel to the corresponding image.
UI/UX expectations
- The main image should be centrally displayed.
- "Previous" and "Next" buttons should be clearly visible and positioned to the left and right of the main image, respectively.
- Dot indicators should be arranged horizontally, typically below the main image.
- The active dot indicator should have a distinct visual style (e.g., different background color, border, or size).
- Basic styling should be applied to make the carousel functional and presentable. Focus on clarity and interaction rather than pixel-perfect design.
Acceptance criteria
- Only one image is visible in the main display area at any given time.
- Clicking the "Next" button advances the carousel to the subsequent image. If at the last image, it cycles to the first.
- Clicking the "Previous" button moves the carousel to the prior image. If at the first image, it cycles to the last.
- The correct dot indicator is visually highlighted to reflect the currently displayed image.
- Clicking any dot indicator updates the main image display to show the image corresponding to that dot.
- The component should be reusable with different sets of image data.