summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-slider/components/ProductSlider.tsx
blob: 05f8c3225a58133d1bf872ae4ea2c3d14a1ef799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'swiper/css'

import React from 'react'
import { Swiper, SwiperSlide } from 'swiper/react'
import { FreeMode } from 'swiper'

import ProductCard from '~/modules/product-card'
import { IProduct } from '~/types/product'
import useDevice from '@/core/hooks/useDevice'

type Props = {
  products: IProduct[],
  productLayout?: 'vertical' | 'horizontal',
}

const ProductSlider = ({ products, productLayout }: Props) => {
  const { isDesktop } = useDevice()

  return (
    <div>
      <Swiper
        slidesPerView={isDesktop ? 6.7 : 2.2}
        spaceBetween={isDesktop ? 16 : 12}
        prefix='product-slider'
        modules={[FreeMode]}
        freeMode={{ enabled: true, sticky: false }}
        className='!pb-0.5'
      >
        {products.map((product) => (
          <SwiperSlide key={product.id}>
            <ProductCard
              product={product}
              layout={productLayout}
            />
          </SwiperSlide>
        ))}
      </Swiper>
    </div >
  )
}

export default ProductSlider