Skip to content

Instantly share code, notes, and snippets.

@adarsh-gupta101
Created May 8, 2025 17:38
Show Gist options
  • Save adarsh-gupta101/4830a1f194fd4a67568c0599bde4ed00 to your computer and use it in GitHub Desktop.
Save adarsh-gupta101/4830a1f194fd4a67568c0599bde4ed00 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
import { Box, Image } from "theme-ui";
const ImageCarousel = () => {
const [currentImageIndex, setCurrentImageIndex] = useState(0);
const images = [
"https://images.pexels.com/photos/15130357/pexels-photo-15130357.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
"https://images.pexels.com/photos/15316227/pexels-photo-15316227.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
"https://images.pexels.com/videos/7592810/cavalry-cold-dawn-daylight-7592810.jpeg",
"https://images.pexels.com/photos/14437079/pexels-photo-14437079.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
"https://images.pexels.com/photos/14737533/pexels-photo-14737533.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
];
const handleImageClick = (index) => {
setCurrentImageIndex(index);
};
return (
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
height: "100vh",
width: "100vw",
backgroundColor: "black",
}}
>
{images.map((src, index) => (
<Box
key={index}
sx={{
width: "200px",
height: "200px",
border: "1px solid gray",
overflow: "hidden",
cursor: "pointer",
mx: 2,
transition: "all .3s ease-in-out",
transform: currentImageIndex === index ? "scale(1.5)" : "none",
}}
onClick={() => handleImageClick(index)}
>
<Image
src={src}
sx={{ width: "100%", height: "100%", objectFit: "cover" }}
/>
</Box>
))}
</Box>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment