-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f30138
commit c17ed4f
Showing
3 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,57 @@ | ||
import Image from 'next/image'; | ||
import Image from "next/image"; | ||
import { useState } from "react"; | ||
|
||
export default function CommunityImages({ images, basePath }) { | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
|
||
const nextImage = () => { | ||
setCurrentIndex((prevIndex) => (prevIndex + 1) % images.length); | ||
}; | ||
|
||
const prevImage = () => { | ||
setCurrentIndex( | ||
(prevIndex) => (prevIndex - 1 + images.length) % images.length | ||
); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col sm:flex-row items-center mx-auto max-w-6xl"> | ||
{images.map((image, index) => ( | ||
<div key={index} className="w-full sm:w-1/2 mx-4 mb-6 flex flex-col justify-center items-center"> | ||
<p className="text-base mt-2">{image.name}</p> | ||
<Image | ||
width={500} | ||
height={500} | ||
<div className="flex flex-col items-center mx-auto max-w-6xl"> | ||
<div className="relative w-full"> | ||
<button | ||
onClick={prevImage} | ||
className="absolute left-0 top-1/2 transform -translate-y-1/2 bg-gray-500 text-white p-2 rounded" | ||
> | ||
❮ | ||
</button> | ||
<div | ||
style={{ | ||
margin: "auto", | ||
width: "1000px", | ||
height: "600px", | ||
}} | ||
> | ||
<img | ||
src={ | ||
basePath | ||
? `${basePath}/images/community/${image.image}` | ||
: `/images/community/${image.image}` | ||
? `${basePath}/images/community/${images[currentIndex].image}` | ||
: `/images/community/${images[currentIndex].image}` | ||
} | ||
alt={image.name} | ||
alt={images[currentIndex].name} | ||
style={{ | ||
width: "100%", | ||
height: "100%", | ||
objectFit: "cover", // Ensure the image covers the container while maintaining aspect ratio | ||
}} | ||
/> | ||
</div> | ||
))} | ||
<button | ||
onClick={nextImage} | ||
className="absolute right-0 top-1/2 transform -translate-y-1/2 bg-gray-500 text-white p-2 rounded" | ||
> | ||
❯ | ||
</button> | ||
</div> | ||
<p className="text-base mt-2">{images[currentIndex].name}</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.