-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[S4] 딤 모달 내 스와이퍼 기능 작업중
- Loading branch information
Showing
12 changed files
with
135 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useDimSwiperStore } from '@store/useDimSwiper'; | ||
import { Dispatch, ReactNode, SetStateAction, useEffect, useState } from 'react'; | ||
import { Navigation, Pagination, Virtual } from 'swiper/modules'; | ||
import { Swiper, SwiperClass } from 'swiper/react'; | ||
import { IPortfolio } from 'types/types'; | ||
|
||
import 'swiper/css'; | ||
import 'swiper/css/pagination'; | ||
|
||
interface IDimSwiper { | ||
children: ReactNode; | ||
data: IPortfolio[]; | ||
setSlideSet: Dispatch<SetStateAction<IPortfolio[]>>; | ||
} | ||
|
||
const DimSwiper = ({ children, data, setSlideSet }: IDimSwiper) => { | ||
const [swiperRef, setSwiperRef] = useState<SwiperClass>(); | ||
const { selectedId, setSelectedId } = useDimSwiperStore(); | ||
const isFirstSlide = data[0].id === selectedId; | ||
|
||
const getNewSlideSet = (clickedId: number) => { | ||
return data.filter(({ id }: { id: number }) => id === clickedId || id === clickedId - 1 || id === clickedId + 1); | ||
}; | ||
|
||
const handleChange = () => { | ||
if (!swiperRef) return null; | ||
|
||
const direction = swiperRef.swipeDirection === 'next' ? 1 : -1; | ||
setSelectedId(selectedId, direction); | ||
swiperRef.slideTo(isFirstSlide ? 0 : 1, 0, false); | ||
}; | ||
|
||
const swiperOption = { | ||
modules: [Virtual, Pagination, Navigation], | ||
onSwiper: (e: SwiperClass) => setSwiperRef(e), | ||
onTransitionEnd: handleChange, | ||
slidesPerView: 1, | ||
initialSlide: isFirstSlide ? 0 : 1, | ||
pagination: { | ||
type: 'fraction' as 'fraction', | ||
}, | ||
centeredSlides: true, | ||
}; | ||
|
||
useEffect(() => { | ||
// console.log(isFirstSlide); | ||
setSlideSet(getNewSlideSet(selectedId)); | ||
}, [selectedId]); | ||
|
||
return <Swiper {...swiperOption}>{children}</Swiper>; | ||
}; | ||
|
||
export default DimSwiper; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { useModalStore } from '@store/useModalStore'; | ||
|
||
const useModal = (modalId = 1) => { | ||
const { modals, setOpen } = useModalStore((state) => state); | ||
const isOpen = modals[modalId] || false; | ||
const setOpen = useModalStore((state) => state.setOpen); | ||
const open = () => setOpen(modalId, true); | ||
const close = () => setOpen(modalId, false); | ||
|
||
return { isOpen, open, close }; | ||
return { open, close }; | ||
}; | ||
|
||
export default useModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
|
||
import DimSwiper from '@components/Swiper/DimSwiper'; | ||
import { TypoBodyMdR } from '@styles/Common'; | ||
import { useState } from 'react'; | ||
import { SwiperSlide } from 'swiper/react'; | ||
import { IPortfolio } from 'types/types'; | ||
|
||
const PortfolioSwiper = ({ data, studioName }: { data: IPortfolio[]; studioName: string }) => { | ||
const [slideSet, setSlideSet] = useState<IPortfolio[]>([]); | ||
|
||
return ( | ||
<DimSwiper data={data} setSlideSet={setSlideSet}> | ||
{slideSet && | ||
slideSet.map(({ id, url, description }) => ( | ||
<SwiperSlide key={id} virtualIndex={id}> | ||
<img src={url} alt={`${studioName}-${id}`} /> | ||
<p css={TypoBodyMdR}>{description}</p> | ||
</SwiperSlide> | ||
))} | ||
</DimSwiper> | ||
); | ||
}; | ||
|
||
export default PortfolioSwiper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { create } from 'zustand'; | ||
|
||
interface DimSwiperState { | ||
selectedId: number; | ||
setSelectedId: (id: number, direction?: number) => void; | ||
} | ||
|
||
export const useDimSwiperStore = create<DimSwiperState>((set) => ({ | ||
selectedId: 0, | ||
setSelectedId: (id, direction) => set((state) => ({ selectedId: (id || state.selectedId) + (direction || 1) })), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters