-
Notifications
You must be signed in to change notification settings - Fork 7
/
Slider.tsx
64 lines (58 loc) · 1.79 KB
/
Slider.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
import Image from "next/image";
import React, { useState } from "react";
import { SliderData } from "./SliderData";
import { FaArrowCircleLeft, FaArrowCircleRight } from "react-icons/fa";
interface Props {
slides: any;
}
const Slider = ({ slides }: Props) => {
const [current, setCurrent] = useState(0);
const length = slides.length;
const nextSlide = () => {
setCurrent(current === length - 1 ? 0 : current + 1);
};
const prevSlide = () => {
setCurrent(current === 0 ? length - 1 : current - 1);
};
if (!Array.isArray(slides) || slides.length <= 0) {
return null;
}
return (
<div id="gallery" className="max-w-[1240px] mx-auto">
<h1 className="text-2xl font-bold text-center p-4 py-0">Gallery</h1>
<div className="relative flex justify-center p-4">
{SliderData.map((slide, index) => {
return (
<div
key={index}
className={
index === current ? "opacity-[1] ease-in" : "opacity-0"
}
>
<FaArrowCircleLeft
onClick={prevSlide}
className="absolute top-[50%] left-[30px] text-white/70 cursor-pointer select-none z-[2]"
size={50}
/>
{index === current && (
<Image
src={slide.image}
alt="/"
width="1440"
height="600"
objectFit="cover"
/>
)}
<FaArrowCircleRight
onClick={nextSlide}
className="absolute top-[50%] right-[30px] text-white/70 cursor-pointer select-none z-[2]"
size={50}
/>
</div>
);
})}
</div>
</div>
);
};
export default Slider;