-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportfolio-carousel.tsx
64 lines (58 loc) · 1.78 KB
/
portfolio-carousel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use client";
import Image from "next/image";
import { useEffect, useState } from "react";
import { images } from "./constants";
import Description from "./Description";
const PortfolioCarousel = () => {
const [activeImage, setActiveImage] = useState(0);
const clickNext = () => {
activeImage === images.length - 1
? setActiveImage(0)
: setActiveImage(activeImage + 1);
};
const clickPrev = () => {
activeImage === 0
? setActiveImage(images.length - 1)
: setActiveImage(activeImage - 1);
};
useEffect(() => {
const timer = setTimeout(() => {
clickNext();
}, 1800000 );
return () => {
clearTimeout(timer);
};
}, [activeImage]);
return (
<main className="grid place-items-center lg:grid-cols-2 grid-cols-1 w-full mx-auto max-w-5xl shadow-2xl rounded-2xl mt-10">
<div
className={`w-full flex justify-center items-center gap-4 transition-transform ease-in-out duration-500 md:rounded-2xl p-0 md:p-0`}
>
{images.map((elem, idx) => (
<div
key={idx}
className={`${
idx === activeImage
? "block w-full h-[30vh] lg:h-[45vh] object-cover transition-all duration-500 ease-in-out"
: "hidden"
}`}
>
<Image
src={elem.src}
alt={elem.alt_text}
width={400}
height={400}
className="w-full h-[30vh] lg:h-[45vh] object-cover rounded-tl-3xl rounded-tr-3xl lg:rounded-tl-3xl lg:rounded-bl-3xl lg:rounded-tr-none"
/>
</div>
))}
</div>
<Description
activeImage={activeImage}
clickNext={clickNext}
clickPrev={clickPrev}
/>
</main>
);
};
export default PortfolioCarousel;