BrandProducts.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // components
  2. import Spring from '@components/Spring';
  3. import {Swiper, SwiperSlide} from 'swiper/react';
  4. import {Autoplay, Navigation} from 'swiper';
  5. import ProductColumnCard from '@components/ProductColumnCard';
  6. import SwiperControls from '@ui/SwiperControls';
  7. // hooks
  8. import {useEffect, useState} from 'react';
  9. import {useThemeProvider} from '@contexts/themeContext';
  10. // data placeholder
  11. import brand_products from '@db/brand_products';
  12. const BrandProducts = () => {
  13. const {direction} = useThemeProvider();
  14. const [swiper, setSwiper] = useState(null);
  15. useEffect(() => {
  16. if (swiper) {
  17. swiper.changeLanguageDirection(direction);
  18. swiper.update();
  19. }
  20. }, [swiper, direction]);
  21. return (
  22. <Spring className="h-2 h-100 p-relative">
  23. <Swiper
  24. className="h-100"
  25. spaceBetween={24}
  26. slidesPerView={1}
  27. onSwiper={setSwiper}
  28. dir={direction}
  29. modules={[Autoplay, Navigation]}
  30. speed={1200}
  31. autoplay={{
  32. delay: 2000,
  33. disableOnInteraction: false,
  34. pauseOnMouseEnter: true
  35. }}
  36. loop
  37. breakpoints={{
  38. 767: {
  39. slidesPerView: 2,
  40. },
  41. 1279: {
  42. slidesPerView: 1,
  43. },
  44. 1499: {
  45. slidesPerView: 3,
  46. }
  47. }}
  48. >
  49. {
  50. brand_products.map((product, index) => (
  51. <SwiperSlide key={index}
  52. style={{margin: direction === 'ltr' ? '0 24px 0 0' : '0 0 0 24px'}}>
  53. <ProductColumnCard product={product}/>
  54. </SwiperSlide>
  55. ))
  56. }
  57. </Swiper>
  58. <SwiperControls swiper={swiper}/>
  59. </Spring>
  60. )
  61. }
  62. export default BrandProducts