summaryrefslogtreecommitdiff
path: root/src/lib/home/components/HeroBanner.jsx
blob: 95f590fc6f55ade05c69319b703eae7c140a2465 (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
43
44
45
46
47
48
49
50
51
52
import ImageSkeleton from '@/core/components/elements/Skeleton/ImageSkeleton'
import useHeroBanner from '../hooks/useHeroBanner'
import Image from '@/core/components/elements/Image/Image'

// Swiper
import { Swiper, SwiperSlide } from 'swiper/react'
import { Pagination, Autoplay } from 'swiper'
import 'swiper/css'
import 'swiper/css/pagination'
import 'swiper/css/autoplay'
import useDevice from '@/core/hooks/useDevice'

const HeroBanner = () => {
  const { isMobile } = useDevice()
  const { heroBanners } = useHeroBanner()

  const swiperBanner = {
    pagination: { dynamicBullets: isMobile ? true : false, clickable: true },
    autoplay: {
      delay: 6000,
      disableOnInteraction: false
    },
    modules: [Pagination, Autoplay]
  }

  return (
    <div className='min-h-[200px]'>
      {heroBanners.isLoading && <ImageSkeleton />}
      {!heroBanners.isLoading && (
        <Swiper
          slidesPerView={1}
          pagination={swiperBanner.pagination}
          modules={swiperBanner.modules}
          autoplay={swiperBanner.autoplay}
          className='border border-gray_r-6'
        >
          {heroBanners.data?.map((banner, index) => (
            <SwiperSlide key={index}>
              <Image
                src={banner.image}
                alt={banner.name}
                className='w-full h-auto'
              />
            </SwiperSlide>
          ))}
        </Swiper>
      )}
    </div>
  )
}

export default HeroBanner