11import React , { useEffect , useState } from "react" ;
22import { motion } from "framer-motion" ;
3- import { ArrowLeft , ArrowRight , Image } from "lucide-react" ;
4- import { cn } from "libs/utils" ;
3+ import { ArrowLeft , ArrowRight } from "lucide-react" ;
54import { Button } from "libComponents/Button" ;
65
76interface ImageSliderProps {
8- imageUrls : string [ ] ;
7+ media : { url : string ; type : string } [ ] ;
98 autoSlide ?: boolean ;
109 autoSlideInterval ?: number ;
11- imageWidth ?: string ;
12- imageHeight ?: string ;
1310 onLoad ?: ( ) => void ;
14- openNftDetailsDrawer ?: ( ) => void ;
1511}
1612
1713//Spring animation parameters
@@ -22,14 +18,14 @@ const spring = {
2218} ;
2319
2420const ImageSlider : React . FC < ImageSliderProps > = ( props ) => {
25- const { imageUrls , autoSlide = false , autoSlideInterval = 6000 , imageWidth = "210px" , imageHeight = "210px" , onLoad, openNftDetailsDrawer } = props ;
21+ const { media , autoSlide = false , autoSlideInterval = 6000 , onLoad } = props ;
2622 const [ imageIndex , setImageIndex ] = useState ( 0 ) ;
2723 const [ switchedImageManually , setSwitchedImageManually ] = useState ( false ) ;
2824 const [ nextImageIndex , setNextImageIndex ] = useState ( 0 ) ;
2925 const makeFlip = nextImageIndex !== imageIndex ;
3026
3127 useEffect ( ( ) => {
32- if ( autoSlide && imageUrls . length > 1 && ! switchedImageManually ) {
28+ if ( autoSlide && media . length > 1 && ! switchedImageManually ) {
3329 const interval = setInterval ( ( ) => {
3430 goToNextImage ( ) ;
3531 } , autoSlideInterval ) ;
@@ -38,17 +34,17 @@ const ImageSlider: React.FC<ImageSliderProps> = (props) => {
3834 } , [ switchedImageManually ] ) ;
3935
4036 function goToPreviousImage ( autoSwitch = false ) {
41- setNextImageIndex ( ( prevIndex ) => ( prevIndex === 0 ? imageUrls . length - 1 : prevIndex - 1 ) ) ;
37+ setNextImageIndex ( ( prevIndex ) => ( prevIndex === 0 ? media . length - 1 : prevIndex - 1 ) ) ;
4238 setSwitchedImageManually ( autoSwitch ) ;
4339 }
4440
4541 function goToNextImage ( autoSwitch = false ) {
46- setNextImageIndex ( ( prevIndex ) => ( prevIndex === imageUrls . length - 1 ? 0 : prevIndex + 1 ) ) ;
42+ setNextImageIndex ( ( prevIndex ) => ( prevIndex === media . length - 1 ? 0 : prevIndex + 1 ) ) ;
4743 setSwitchedImageManually ( autoSwitch ) ;
4844 }
4945
5046 return (
51- < div className = "mb-8 w-full justify-center base:h-[15rem] md:h-[18rem] object-cover relative " >
47+ < div className = "mb-8 w-full justify-center base:h-[15rem] md:h-[18rem] relative " >
5248 < div className = "perspective-1200 transform-style-preserve-3d " >
5349 < motion . div
5450 transition = { spring }
@@ -59,7 +55,11 @@ const ImageSlider: React.FC<ImageSliderProps> = (props) => {
5955 backfaceVisibility : "hidden" ,
6056 position : "absolute" ,
6157 } } >
62- < img className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" src = { imageUrls [ imageIndex ] } onLoad = { onLoad } />
58+ { media [ imageIndex ] . type . includes ( "video" ) ? (
59+ < video autoPlay loop src = { media [ imageIndex ] . url } className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" > </ video >
60+ ) : (
61+ < img className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" src = { media [ imageIndex ] . url } onLoad = { onLoad } />
62+ ) }
6363 </ motion . div >
6464 { makeFlip && (
6565 < motion . div
@@ -76,18 +76,20 @@ const ImageSlider: React.FC<ImageSliderProps> = (props) => {
7676 onAnimationComplete = { ( ) => {
7777 setImageIndex ( nextImageIndex ) ;
7878 } } >
79- < img className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" src = { imageUrls [ nextImageIndex ] } onLoad = { onLoad } />
79+ { media [ nextImageIndex ] . type . includes ( "video" ) ? (
80+ < video autoPlay loop src = { media [ imageIndex ] . url } className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" > </ video >
81+ ) : (
82+ < img className = "md:w-auto base:w-[15rem] rounded-3xl base:h-[15rem] md:h-[18rem] mx-auto" src = { media [ nextImageIndex ] . url } onLoad = { onLoad } />
83+ ) }
8084 </ motion . div >
8185 ) }
8286 </ div >
83- { imageUrls . length > 1 && (
87+ { media . length > 1 && (
8488 < div className = "z-10 flex flex-row h-full w-full justify-center items-end my-2 mt-8 gap-2 " >
85- < Button className = "p-1 h-6 !rounded-3xl" disabled = { makeFlip } >
86- { " " }
89+ < Button className = "p-1 h-6 !rounded-3xl" disabled = { makeFlip } >
8790 < ArrowLeft onClick = { ( ) => goToPreviousImage ( true ) } />
8891 </ Button >
8992 < Button className = "p-1 h-6 !rounded-3xl" disabled = { makeFlip } >
90- { " " }
9193 < ArrowRight onClick = { ( ) => goToNextImage ( true ) } /> { " " }
9294 </ Button >
9395 </ div >
0 commit comments