webapp/src/components/_shared/SolidSwiper/ArticleCardSwiper.tsx

90 lines
2.9 KiB
TypeScript
Raw Normal View History

import { clsx } from 'clsx'
2023-11-13 15:35:07 +00:00
import { For, onMount, Show } from 'solid-js'
import SwiperCore, { Manipulation, Navigation, Pagination } from 'swiper'
2023-11-28 13:18:25 +00:00
import { Shout } from '../../../graphql/schema/core.gen'
import { ArticleCard } from '../../Feed/ArticleCard'
import { Icon } from '../Icon'
2023-11-13 15:46:23 +00:00
import { SwiperRef } from './swiper'
import styles from './Swiper.module.scss'
type Props = {
slides: Shout[]
title?: string
}
export const ArticleCardSwiper = (props: Props) => {
const mainSwipeRef: { current: SwiperRef } = { current: null }
2023-11-13 15:46:23 +00:00
onMount(async () => {
const { register } = await import('swiper/element/bundle')
2023-11-13 15:35:07 +00:00
register()
SwiperCore.use([Pagination, Navigation, Manipulation])
})
return (
<div class={clsx(styles.Swiper, styles.articleMode, styles.ArticleCardSwiper)}>
<Show when={props.title}>
<h2 class={styles.sliderTitle}>{props.title}</h2>
</Show>
<div class={styles.container}>
<Show when={props.slides.length > 0}>
<div class={styles.holder}>
<swiper-container
ref={(el) => (mainSwipeRef.current = el)}
centered-slides={true}
observer={true}
space-between={10}
2023-11-06 20:33:57 +00:00
breakpoints={{
2023-11-10 06:19:38 +00:00
576: { spaceBetween: 20, slidesPerView: 1.5 },
992: { spaceBetween: 52, slidesPerView: 1.5 },
2023-11-06 20:33:57 +00:00
}}
2023-11-09 22:18:30 +00:00
round-lengths={true}
loop={true}
speed={800}
autoplay={{
disableOnInteraction: false,
delay: 6000,
pauseOnMouseEnter: true,
}}
>
<For each={props.slides}>
{(slide, index) => (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
<swiper-slide virtual-index={index()}>
<ArticleCard
article={slide}
settings={{
additionalClass: 'swiper-slide',
isFloorImportant: true,
isWithCover: true,
nodate: true,
}}
desktopCoverSize="L"
/>
</swiper-slide>
)}
</For>
</swiper-container>
<div
2023-11-10 03:16:42 +00:00
class={clsx(styles.navigation, styles.prev)}
onClick={() => mainSwipeRef.current.swiper.slidePrev()}
>
<Icon name="swiper-l-arr" class={styles.icon} />
</div>
<div
2023-11-10 03:16:42 +00:00
class={clsx(styles.navigation, styles.next)}
onClick={() => mainSwipeRef.current.swiper.slideNext()}
>
<Icon name="swiper-r-arr" class={styles.icon} />
</div>
</div>
</Show>
</div>
</div>
)
}