|
| 1 | +'use client'; |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import { aboutTimelineData } from '@/constants'; |
| 4 | +import { motion } from 'framer-motion'; |
| 5 | +import TimelineCard from './TimelineCard'; |
| 6 | +import { ChevronLeft, ChevronRight } from 'lucide-react'; |
| 7 | +import ProgressiveeBarSvg from './ProgressiveeBarSvg'; |
| 8 | + |
| 9 | +const ImageSlider = () => { |
| 10 | + const [currentIndex, setCurrentIndex] = useState(0); |
| 11 | + const totalItems = aboutTimelineData.length; |
| 12 | + |
| 13 | + const next = () => { |
| 14 | + setCurrentIndex(prevIndex => (prevIndex + 1) % totalItems); |
| 15 | + }; |
| 16 | + |
| 17 | + const prev = () => { |
| 18 | + setCurrentIndex(prevIndex => (prevIndex - 1 + totalItems) % totalItems); |
| 19 | + }; |
| 20 | + |
| 21 | + const getPosition = ( |
| 22 | + index: number |
| 23 | + ): 'center' | 'left' | 'right' | 'hidden' => { |
| 24 | + const diff = (index - currentIndex + totalItems) % totalItems; |
| 25 | + |
| 26 | + if (diff === 0) return 'center'; |
| 27 | + if (diff === 1 || diff === totalItems - 1) { |
| 28 | + return diff === 1 ? 'right' : 'left'; |
| 29 | + } |
| 30 | + return 'hidden'; |
| 31 | + }; |
| 32 | + |
| 33 | + const imageVariants = { |
| 34 | + center: { |
| 35 | + x: '0%', |
| 36 | + scale: 1, |
| 37 | + zIndex: 5, |
| 38 | + opacity: 1, |
| 39 | + rotateY: 0, |
| 40 | + }, |
| 41 | + left: { |
| 42 | + x: '-40%', |
| 43 | + scale: 0.8, |
| 44 | + zIndex: 2, |
| 45 | + opacity: 0.7, |
| 46 | + rotateY: 15, |
| 47 | + }, |
| 48 | + right: { |
| 49 | + x: '40%', |
| 50 | + scale: 0.8, |
| 51 | + zIndex: 2, |
| 52 | + opacity: 0.7, |
| 53 | + rotateY: -15, |
| 54 | + }, |
| 55 | + hidden: { |
| 56 | + x: '0%', |
| 57 | + scale: 0.5, |
| 58 | + zIndex: 1, |
| 59 | + opacity: 0, |
| 60 | + }, |
| 61 | + }; |
| 62 | + |
| 63 | + return ( |
| 64 | + <div className='flex relative min-h-[500px] max-w-[800px] mx-auto items-center'> |
| 65 | + <div className='relative w-full h-[400px]'> |
| 66 | + {aboutTimelineData.map((item, index) => { |
| 67 | + const position = getPosition(index); |
| 68 | + const { img, year, title, subTitle, backgroundImage } = item; |
| 69 | + return ( |
| 70 | + <motion.div |
| 71 | + key={index} |
| 72 | + initial='center' |
| 73 | + animate={position} |
| 74 | + variants={imageVariants} |
| 75 | + transition={{ |
| 76 | + duration: 0.6, |
| 77 | + ease: 'easeInOut', |
| 78 | + }} |
| 79 | + className='absolute inset-0 flex justify-center items-center' |
| 80 | + style={{ |
| 81 | + width: '450px', |
| 82 | + left: '50%', |
| 83 | + marginLeft: '-200px', |
| 84 | + }} |
| 85 | + > |
| 86 | + <TimelineCard |
| 87 | + img={img} |
| 88 | + year={year} |
| 89 | + title={title} |
| 90 | + subTitle={subTitle} |
| 91 | + backgroundImage={backgroundImage} |
| 92 | + /> |
| 93 | + </motion.div> |
| 94 | + ); |
| 95 | + })} |
| 96 | + </div> |
| 97 | + |
| 98 | + {/* Left and Right button */} |
| 99 | + <button |
| 100 | + onClick={prev} |
| 101 | + className='absolute left-32 top-1/2 -translate-y-1/2 bg-gray-900/80 hover:bg-gray-800 rounded-full p-2 shadow-lg transition-colors z-10' |
| 102 | + > |
| 103 | + <ChevronLeft className='w-6 h-6 text-white' /> |
| 104 | + </button> |
| 105 | + |
| 106 | + <button |
| 107 | + onClick={next} |
| 108 | + className='absolute right-24 top-1/2 -translate-y-1/2 bg-gray-900/80 hover:bg-gray-800 rounded-full p-2 shadow-lg transition-colors z-10' |
| 109 | + > |
| 110 | + <ChevronRight className='w-6 h-6 text-white' /> |
| 111 | + </button> |
| 112 | + |
| 113 | + {/* Progress Bar and Number */} |
| 114 | + <div className='absolute bottom-0 left-1/2 -translate-x-1/2 flex items-center'> |
| 115 | + {aboutTimelineData.map((_, index) => ( |
| 116 | + <div key={index} className='flex items-center'> |
| 117 | + <button |
| 118 | + onClick={() => setCurrentIndex(index)} |
| 119 | + className={`text-sm font-medium transition-colors ${ |
| 120 | + index === currentIndex ? 'text-white' : 'text-gray-700/65' |
| 121 | + }`} |
| 122 | + > |
| 123 | + {String(index + 1).padStart(2, '0')} |
| 124 | + </button> |
| 125 | + |
| 126 | + {index < aboutTimelineData.length - 1 && ( |
| 127 | + <div className='mx-4'> |
| 128 | + <ProgressiveeBarSvg /> |
| 129 | + </div> |
| 130 | + )} |
| 131 | + </div> |
| 132 | + ))} |
| 133 | + </div> |
| 134 | + </div> |
| 135 | + ); |
| 136 | +}; |
| 137 | + |
| 138 | +export default ImageSlider; |
0 commit comments