Skip to content

Commit

Permalink
Merge pull request #13904 from ethereum/slider-swiper
Browse files Browse the repository at this point in the history
Migrate Slider usage to new Swiper
  • Loading branch information
corwintines authored Sep 19, 2024
2 parents 79ea516 + e480d23 commit 9225662
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 353 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"embla-carousel-react": "^7.0.0",
"ethereum-blockies-base64": "^1.0.2",
"framer-motion": "^10.13.0",
"gray-matter": "^4.0.3",
Expand Down
109 changes: 0 additions & 109 deletions src/components/Slider/Slider.stories.tsx

This file was deleted.

151 changes: 0 additions & 151 deletions src/components/Slider/index.tsx

This file was deleted.

30 changes: 18 additions & 12 deletions src/components/Swiper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useTranslation } from "next-i18next"
import { EffectCards, Keyboard, Navigation, Pagination } from "swiper/modules"
import { Swiper as SwiperParent, SwiperSlide } from "swiper/react"
import type { SwiperOptions } from "swiper/types"
import {
Swiper as SwiperParent,
type SwiperProps as SwiperParentProps,
SwiperSlide,
} from "swiper/react"

import { ChevronNext, ChevronPrev } from "@/components/Chevron"

Expand All @@ -12,23 +15,27 @@ import "swiper/css/navigation"
import "swiper/css/pagination"
import "swiper/css/effect-cards"

type SwiperProps = {
type SwiperProps = SwiperParentProps & {
children: React.ReactNode[]
options?: SwiperOptions
className?: string
swiperClass?: string
/**
* Additional class names for the container element.
*/
containerClassName?: string
/**
* Additional class names for the slider element.
*/
sliderClass?: string
}

const Swiper = ({
children,
className,
swiperClass,
containerClassName,
sliderClass,
options,
...props
}: SwiperProps) => {
const { t } = useTranslation("common")
return (
<div className={cn("h-fit", className)}>
<div className={cn("h-fit", containerClassName)}>
<SwiperParent
navigation={{
nextEl: ".swiper-button-next",
Expand All @@ -43,8 +50,7 @@ const Swiper = ({
modules={[Navigation, Pagination, Keyboard, EffectCards]}
slidesPerView={1}
slidesPerGroup={1}
className={swiperClass}
{...options}
{...props}
>
{children.map((child, index) => (
<SwiperSlide className={sliderClass} key={index}>
Expand Down
26 changes: 12 additions & 14 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ const HomePage = ({

{/* Mobile */}
<Swiper
options={{ effect: "cards" }}
className={cn(
effect="cards"
containerClassName={cn(
"lg:hidden", // Mobile only
"[&_.swiper-slide]:overflow-visible [&_.swiper-slide]:rounded-2xl [&_.swiper-slide]:shadow-card-hover",
"[&_.swiper]:mx-auto [&_.swiper]:mt-4 [&_.swiper]:!flex [&_.swiper]:h-fit [&_.swiper]:max-w-128 [&_.swiper]:flex-col [&_.swiper]:items-center"
Expand Down Expand Up @@ -582,18 +582,16 @@ const HomePage = ({
<p>{t("page-index:page-index-posts-subtitle")}</p>

<Swiper
className="mt-4 md:mt-16"
options={{
spaceBetween: 32,
breakpoints: {
[breakpointAsNumber.sm]: {
slidesPerView: 2,
slidesPerGroup: 2,
},
[breakpointAsNumber.lg]: {
slidesPerView: 3,
slidesPerGroup: 3,
},
containerClassName="mt-4 md:mt-16"
spaceBetween={32}
breakpoints={{
[breakpointAsNumber.sm]: {
slidesPerView: 2,
slidesPerGroup: 2,
},
[breakpointAsNumber.lg]: {
slidesPerView: 3,
slidesPerGroup: 3,
},
}}
>
Expand Down
Loading

0 comments on commit 9225662

Please sign in to comment.