Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/mypage
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeyoung103 committed Feb 13, 2024
2 parents 72aaca6 + 4f28590 commit d0bec20
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 57 deletions.
87 changes: 87 additions & 0 deletions src/components/Home/TopicSwiper/TopicSlide.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { PropsWithChildren } from 'react';
import styled from 'styled-components';
import { SwiperSlide } from 'swiper/react';

import { colors } from '@styles/theme';

import { RightChevronIcon } from '@icons/index';

interface TopicSlideProps {
init: boolean;
swiperRef: any;
prevDisabled: any;
nextDisabled: any;
setNextDisabled: any;
setPrevDisabled: any;
}

const TopicSlide = (props: PropsWithChildren<TopicSlideProps>) => {
const {
init,
prevDisabled,
swiperRef,
setNextDisabled,
nextDisabled,
setPrevDisabled,
children,
} = props;
return (
<StyledSlide>
<PrevButton
disabled={init || prevDisabled}
onClick={() => {
swiperRef.current?.slidePrev();
setNextDisabled(false);
}}
>
<RightChevronIcon style={{ transform: 'rotate(180deg)' }} stroke={colors.white_40} />
</PrevButton>
{children}
<NextButton
disabled={nextDisabled}
onClick={() => {
swiperRef.current?.slideNext();
setPrevDisabled(false);
}}
>
<RightChevronIcon stroke={colors.white_40} />
</NextButton>
</StyledSlide>
);
};

TopicSlide.displayName = 'SwiperSlide';

const StyledSlide = styled(SwiperSlide)`
overflow-y: auto;
&::-webkit-scrollbar {
display: none;
}
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
`;

const SlideButton = styled.button<{ disabled: boolean }>`
position: absolute;
top: 63px;
z-index: 100;
width: 32px;
height: 32px;
padding: 4.8px 10.4px;
cursor: pointer;
background-color: transparent;
${(props) => props.disabled && `display: none;`}
`;

const PrevButton = styled(SlideButton)`
left: 20px;
`;

const NextButton = styled(SlideButton)`
right: 20px;
`;

export default TopicSlide;
73 changes: 16 additions & 57 deletions src/components/Home/TopicSwiper/TopicSwiper.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, { useRef, useState } from 'react';
import { styled } from 'styled-components';
import SwiperCore from 'swiper';
import { Navigation } from 'swiper/modules';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Swiper } from 'swiper/react';

import { colors } from '@styles/theme';

import { RightChevronIcon } from '@icons/index';
import TopicSlide from './TopicSlide';

SwiperCore.use([Navigation]);

Expand Down Expand Up @@ -51,62 +48,24 @@ const TopicSwiper = ({ children, fetchNextPage, hasNextPage }: TopicSwiperProps)
onReachBeginning={handleReachBeginning}
observer={true}
>
{children.map((child, index) => (
<TopicSlide key={index} style={{ overflowY: 'auto' }}>
<PrevButton
disabled={init || prevDisabled}
onClick={() => {
swiperRef.current?.slidePrev();
setNextDisabled(false);
}}
>
<RightChevronIcon style={{ transform: 'rotate(180deg)' }} stroke={colors.white_40} />
</PrevButton>
{child}
<NextButton
disabled={nextDisabled}
onClick={() => {
swiperRef.current?.slideNext();
setPrevDisabled(false);
}}
{children.map((child) => {
return (
<TopicSlide
key={child.key}
init={init}
prevDisabled={prevDisabled}
swiperRef={swiperRef}
setNextDisabled={setNextDisabled}
nextDisabled={nextDisabled}
setPrevDisabled={setPrevDisabled}
>
<RightChevronIcon stroke={colors.white_40} />
</NextButton>
</TopicSlide>
))}
{child}
</TopicSlide>
);
})}
</Swiper>
</React.Fragment>
);
};

const TopicSlide = styled(SwiperSlide)`
&::-webkit-scrollbar {
display: none;
}
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
`;

const SlideButton = styled.button<{ disabled: boolean }>`
position: absolute;
top: 63px;
z-index: 100;
width: 32px;
height: 32px;
padding: 4.8px 10.4px;
cursor: pointer;
background-color: transparent;
${(props) => props.disabled && `display: none;`}
`;

const PrevButton = styled(SlideButton)`
left: 20px;
`;

const NextButton = styled(SlideButton)`
right: 20px;
`;

export default TopicSwiper;

0 comments on commit d0bec20

Please sign in to comment.