-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added swiper for products and header
- Loading branch information
Showing
18 changed files
with
298 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useEffect, useState } from 'react' | ||
|
||
import { Navigation, Pagination, Scrollbar, A11y, Autoplay } from 'swiper/modules'; | ||
|
||
import { Swiper, SwiperSlide, useSwiper } from 'swiper/react'; | ||
|
||
// Import Swiper styles | ||
import 'swiper/css'; | ||
import 'swiper/css/navigation'; | ||
import 'swiper/css/scrollbar'; | ||
import './swiper.css'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setProduct } from '../../features/products/productDetailSlice'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
const ProductSlider = ({products, category}) => { | ||
const [isMobile, setIsMobile] = useState(false) | ||
const dispatch = useDispatch() | ||
|
||
useEffect(() => { | ||
function handleResize() { | ||
if (window.innerWidth <= 768) { | ||
setIsMobile(true); | ||
} else { | ||
setIsMobile(false); | ||
} | ||
} | ||
|
||
window.addEventListener('resize', handleResize); | ||
|
||
return () => { | ||
window.removeEventListener('resize', handleResize); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
|
||
<div className='relative py-[2rem] bg-white drop-shadow-2xl container swiper'> | ||
<div className='px-[1rem] lg:px-[2rem] pb-[2rem] flex gap-[0.5rem] lg:gap-[0.8rem] items-center'> | ||
<span className='h-[2.2rem] lg:h-[2rem] w-[5px] bg-[#febd69]'></span> | ||
<h3 className='font-semibold text-[1rem] lg:text-[1.2rem]'> | ||
{category} | ||
</h3> | ||
</div> | ||
<Swiper | ||
// install Swiper modules | ||
modules={[Navigation, Pagination, Scrollbar, A11y, Autoplay]} | ||
spaceBetween={0} | ||
slidesPerView={ isMobile ? 3 : 5} | ||
navigation={{ | ||
prevEl: '.swiper-button-prev', | ||
nextEl: '.swiper-button-next', | ||
}} | ||
autoplay={{ | ||
delay: 4000, | ||
disableOnInteraction: false, | ||
}} | ||
scrollbar={{ draggable: true }} | ||
className='static' | ||
> | ||
{products.map(({title, id, image, category, price, description, rating: {rate, count}}) => ( | ||
<SwiperSlide className='px-[1rem] cursor-pointer' key={id}> | ||
<Link to={`/products/${id}`} onClick={() => dispatch(setProduct({title, id, image, category, price, description, rating: {rate, count}}))}> | ||
<img src={image} alt="" className="w-fit lg:w-fit mx-auto h-[7rem] lg:h-[12rem] mb-[0.5rem]"/> | ||
|
||
<div className='flex gap-[0.5rem] lg:gap-[0.7rem] items-center py-[0.5rem]'> | ||
<small className='rounded-sm bg-red-700 py-[2px] lg:py-[4px] px-[6px] lg:px-[8px] text-white text-[0.55rem] lg:text-[0.7rem]'>40% off</small> | ||
<small className='text-red-700 text-[0.6rem] lg:text-[0.8rem] font-semibold'>Deal</small> | ||
</div> | ||
<div> | ||
<p className="text-[0.7rem] lg:text-[1rem] rounded-full font-semibold">${price}</p> | ||
<p className='text-[0.7rem] lg:text-[1rem]'> | ||
<small className='text-gray-400 font-normal'>List Price: </small> | ||
<small className='line-through text-gray-400 font-normal'>${price+200}</small> | ||
</p> | ||
</div> | ||
|
||
<h3 className="text-[0.8rem] lg:text-[0.9rem] truncate pr-[1rem]">{description}</h3> | ||
</Link> | ||
|
||
</SwiperSlide> | ||
))} | ||
|
||
</Swiper> | ||
<div className="hidden lg:flex justify-center items-center absolute top-[40%] lg:left-[1rem] translate-y-[-50%] z-50"> | ||
<div className="swiper-button-prev text-gray-500 rounded-md px-[1.5rem] py-[3rem] drop-shadow-md bg-[#f5f5f5de]"></div> | ||
</div> | ||
<div className="hidden lg:flex justify-center items-center absolute top-[40%] translate-y-[-50%] z-50 lg:right-[1rem]"> | ||
<div className="swiper-button-next text-gray-500 rounded-md px-[1.5rem] py-[3rem] drop-shadow-md bg-[#f5f5f5de]"></div> | ||
</div> | ||
<div className=".swiper-scrollbar transition-all duration-500"></div> | ||
{/* <div className=".swiper-scrollbar-drag"></div> */} | ||
</div> | ||
) | ||
} | ||
|
||
export default ProductSlider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Change font size for both previous and next buttons */ | ||
.swiper-button-prev:after, | ||
.swiper-button-next:after{ | ||
font-size: 1.8rem !important; | ||
font-weight: bold !important; | ||
transition: 0.3s !important; | ||
} | ||
.swiper-button-prev, | ||
.swiper-button-next{ | ||
display: none; | ||
} | ||
.swiper:hover .swiper-button-prev, | ||
.swiper:hover .swiper-button-next{ | ||
display: flex; | ||
} | ||
.swiper-scrollbar{ | ||
opacity: 1; | ||
height: 6px !important; | ||
border-radius: 4px; | ||
position: absolute !important; | ||
bottom: 0.8rem !important; | ||
transition: all 0.3s ease !important; | ||
display: none; | ||
} | ||
|
||
.swiper-scrollbar-drag { | ||
background-color: gray !important; | ||
opacity: 1; | ||
border-radius: 4px; | ||
width: 50%; | ||
height: 6px !important; | ||
} | ||
.swiper:hover .swiper-scrollbar{ | ||
display: flex; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.swiper-button-prev:after, | ||
.swiper-button-next:after{ | ||
font-size: 1rem !important; /* Adjust the font size as needed */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.