@@ -48,9 +48,9 @@ const testimonials = [
4848] ;
4949
5050const Testimonial = ( { testimonial } ) => (
51- < div className = "bg-black p-4 rounded-xl delay-150 hover:-translate-y-1 duration-300 hover:scale-110 md:m-6 m-2 mt-8 h-100 border-2 border-white" >
51+ < div className = " bg-black p-4 rounded-xl delay-150 hover:-translate-y-1 duration-300 hover:scale-110 md:m-6 m-2 mt-8 h-96 w-auto border-2 border-white text-lg text-center justify-center items-center " >
5252 < p className = "text-white" > { testimonial . text } </ p >
53- < div className = "flex items -center mt-4 " >
53+ < div className = "flex justify -center mt-8 " >
5454 < div className = "flex-shrink-0" >
5555 < Image
5656 className = "w-12 h-12 rounded-full"
@@ -70,71 +70,89 @@ const Testimonial = ({ testimonial }) => (
7070const TestimonialCarousel = ( ) => {
7171 const [ current , setCurrent ] = useState ( 0 ) ;
7272 const [ numVisible , setNumVisible ] = useState ( 3 ) ;
73-
73+ const [ intervalId , setIntervalId ] = useState ( null ) ;
7474 useEffect ( ( ) => {
7575 const handleResize = ( ) => {
7676 const screenWidth = window . innerWidth ;
77- if ( screenWidth < 640 ) {
77+ if ( screenWidth <= 700 ) {
7878 setNumVisible ( 1 ) ;
79- } else if ( screenWidth < 768 ) {
79+ } else if ( screenWidth >= 700 && screenWidth < 1024 ) {
80+ setNumVisible ( 2 ) ;
81+ } else if ( screenWidth >= 1024 && screenWidth < 1300 ) {
8082 setNumVisible ( 2 ) ;
8183 } else {
8284 setNumVisible ( 3 ) ;
8385 }
8486 } ;
8587
88+ const startAutoCarousel = ( ) => {
89+ const id = setInterval ( ( ) => {
90+ goToNext ( ) ;
91+ } , 5000 ) ;
92+
93+ return id ;
94+ } ;
95+
8696 if ( typeof window !== "undefined" ) {
8797 window . addEventListener ( "resize" , handleResize ) ;
8898 }
89-
90- return ( ) => {
91- if ( typeof window !== "undefined" ) {
92- window . removeEventListener ( "resize" , handleResize ) ;
93- }
94- } ;
99+ const intervalId = startAutoCarousel ( ) ;
100+ return ( ) => clearInterval ( intervalId ) ;
95101 } , [ ] ) ;
96102
97103 const visibleTestimonials = testimonials . slice ( current , current + numVisible ) ;
98104
99105 const goToPrev = ( ) => {
100- if ( current === 0 ) {
101- setCurrent ( testimonials . length - numVisible ) ;
102- } else {
103- setCurrent ( current - 1 ) ;
104- }
106+ setCurrent ( ( prev ) => {
107+ if ( prev === 0 ) {
108+ return testimonials . length - numVisible ;
109+ } else {
110+ return prev - 1 ;
111+ }
112+ } ) ;
105113 } ;
106114
107115 const goToNext = ( ) => {
108- if ( current === testimonials . length - numVisible ) {
109- setCurrent ( 0 ) ;
110- } else {
111- setCurrent ( current + 1 ) ;
112- }
116+ setCurrent ( ( prev ) => {
117+ if ( prev + numVisible === testimonials . length ) {
118+ return 0 ;
119+ } else {
120+ return prev + 1 ;
121+ }
122+ } ) ;
113123 } ;
114124
115125 return (
116126 < div className = "py-10" >
117127 < Header name = "What Our Members Say About Us" />
118- < div className = "flex flex-col items-center justify-center" >
119- < div className = "flex items-center mb-6" >
120- < button
121- onClick = { goToPrev }
122- className = "bg-gray-800 text-white rounded-full p-3 flex justify-center items-center mr-2"
123- >
124- { "<" }
125- </ button >
128+ < div className = "flex items-center justify-center" >
129+ < button
130+ onClick = { goToPrev }
131+ className = "bg-gray-800 text-white rounded-full p-3 flex justify-center items-center mr-2"
132+ >
133+ { "<" }
134+ </ button >
135+ < div className = "flex items-center mb-6 mx-auto" >
126136 { visibleTestimonials . map ( ( testimonial ) => (
127137 < div key = { testimonial . id } >
128138 < Testimonial testimonial = { testimonial } />
129139 </ div >
130140 ) ) }
131- < button
132- onClick = { goToNext }
133- className = "bg-gray-800 text-white rounded-full p-4 flex justify-center items-center ml-2"
134- >
135- { ">" }
136- </ button >
137141 </ div >
142+ < button
143+ onClick = { goToNext }
144+ className = "bg-gray-800 text-white rounded-full p-3 flex justify-center items-center mr-2"
145+ >
146+ { ">" }
147+ </ button >
148+ </ div >
149+ < div className = "flex justify-center items-center gap-4" >
150+ { /* <button
151+ onClick={goToPrev}
152+ className="bg-gray-800 text-white rounded-full p-3 flex justify-center items-center mr-2"
153+ >
154+ {"<"}
155+ </button> */ }
138156 < div className = "flex justify-center" >
139157 { testimonials . map ( ( testimonial , index ) => (
140158 < div
@@ -146,6 +164,12 @@ const TestimonialCarousel = () => {
146164 > </ div >
147165 ) ) }
148166 </ div >
167+ { /* <button
168+ onClick={goToNext}
169+ className="bg-gray-800 text-white rounded-full p-3 flex justify-center items-center mr-2"
170+ >
171+ {">"}
172+ </button> */ }
149173 </ div >
150174 </ div >
151175 ) ;
0 commit comments