Overview
Image carousels are fundamental UI components in many web applications, from e-commerce product pages to personal portfolios. They allow users to browse multiple images in a compact and interactive manner. For this problem, you will implement a simplified image carousel that displays a series of images and allows users to navigate through them. This exercise evaluates your ability to manage component state, handle user interactions, and render dynamic UI elements.
What you need to do / Task
Your primary goal is to build a functional ImageCarousel React component that displays a collection of images.
- Display Images: Render a single image from a provided list at a time.
- Navigation Controls: Implement "Previous" and "Next" buttons to cycle through the images.
- Index Indicator: Show the current image's index relative to the total number of images (e.g., "1 of 5").
- Wrap Around: When navigating past the last image, the carousel should loop back to the first image. Similarly, navigating before the first image should loop to the last image.
UI/UX expectations
- The currently displayed image should be clearly visible and centered within its container.
- "Previous" and "Next" buttons should be easily clickable and positioned appropriately relative to the image (e.g., on either side or below).
- The index indicator should be legible, indicating the current image number and the total count (e.g., "Image 3 of 7").
- No advanced styling or animations are required, but the basic layout should be clean and functional.
Acceptance criteria
- The
ImageCarousel component renders without errors.
- Initial render displays the first image in the provided list.
- Clicking "Next" advances to the subsequent image.
- Clicking "Previous" moves to the preceding image.
- Clicking "Next" on the last image displays the first image.
- Clicking "Previous" on the first image displays the last image.
- The index indicator correctly updates to reflect the current image (e.g., "2 of 5" when the second image is shown).
- All images from the provided data are accessible via navigation.