Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SP2] 프로젝트 탭 캐러셀 블러 스타일 수정 #266

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/components/common/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { S } from './style';

interface CarouselProps {
itemWidth: number;
gapWidth: number;
stride?: number;
leftArrowType?: CarouselArrowType;
rightArrowType?: CarouselArrowType;
Expand All @@ -15,6 +16,7 @@ const SWIPE_THRESHOLD = 50;

export default function Carousel({
itemWidth,
gapWidth,
stride = 1,
leftArrowType = CarouselArrowType.External,
rightArrowType = CarouselArrowType.External,
Expand All @@ -24,17 +26,26 @@ export default function Carousel({
const [currentIndex, setCurrentIndex] = useState(0);
const [startX, setStartX] = useState(0);
const wrapperRef = useRef<HTMLDivElement>(null);
const [isSliding, setIsSliding] = useState(false);
const lastIndex = currentIndex === children.length - 1;

useEffect(() => {
setCurrentIndex(0);
}, [stride, itemWidth]);

const handleSlideStatus = () => {
setIsSliding(true);
setTimeout(() => setIsSliding(false), 300);
};

const handlePrev = () => {
setCurrentIndex(Math.max(0, currentIndex - stride));
handleSlideStatus();
};

const handleNext = () => {
setCurrentIndex(Math.min(children.length - 1, currentIndex + stride));
handleSlideStatus();
};

const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
Expand All @@ -52,10 +63,10 @@ export default function Carousel({
}
};

const translateX = -currentIndex * itemWidth;
const translateX = -currentIndex * (itemWidth + gapWidth);

return (
<S.Wrapper ref={wrapperRef}>
<S.Wrapper ref={wrapperRef} isSliding={isSliding} lastIndex={lastIndex}>
{overflowType === CarouselOverflowType.Blur && (
<>
<S.LeftBlur />
Expand All @@ -68,6 +79,7 @@ export default function Carousel({
translateX={translateX}
itemWidth={itemWidth}
itemCount={children.length}
gapWidth={gapWidth}
onTouchStart={handleTouchStart}
onTouchEnd={handleTouchEnd}
>
Expand Down
48 changes: 41 additions & 7 deletions src/components/common/Carousel/style.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import { css } from '@emotion/react';
import arrowLeft from '@src/assets/icons/arrow_left_28x28.svg';
import arrowRight from '@src/assets/icons/arrow_right_28x28.svg';
import { HideScrollbar } from '@src/lib/styles/scrollbar';
import { CarouselArrowType } from '@src/lib/types/universal';

const Wrapper = styled(HideScrollbar)`
const Wrapper = styled(HideScrollbar)<{ isSliding: boolean; lastIndex: boolean }>`
width: 100%;
position: relative;

::before,
::after {
content: '';
position: absolute;
top: 0;
z-index: 5;

width: 70px;
height: 164px;
}

::before {
left: 0;
background: linear-gradient(270deg, transparent 0%, ${colors.gray950} 100%);

opacity: ${({ isSliding }) => (isSliding ? '1' : '0')};
transition: opacity 0.3s ease-out;
}

::after {
right: -1px;
Comment on lines +32 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right를 -1px로 준 이유는 0으로 주면 크롬 개발자 도구 반응형으로 봤을 때 끝 부분까지 덮이지 않는 것처럼 보이기 때문입니다.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호... 왜 안덮히는 걸까요...? 신기하네요..!

background: linear-gradient(270deg, ${colors.gray950} 0%, transparent 100%);

opacity: 0;
${({ isSliding }) =>
isSliding &&
css`
opacity: 1;
transition: opacity 0.3s ease-out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transition 속성은 조건문을 걸지 않아도 괜찮지 않나요 ..?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

화면 사이즈가 변동 되었을 때는 transition이 없었으면 해서 슬라이드 넘길 때만 적용했습니다!

`};

@media (max-width: 1279px) {
opacity: ${({ lastIndex }) => (lastIndex ? 0 : 1)};
}
}
`;

const Arrow = styled.div<{ type: CarouselArrowType }>`
Expand Down Expand Up @@ -40,12 +77,14 @@ const CarouselWrapper = styled.div<{
translateX: number;
itemWidth: number;
itemCount: number;
gapWidth: number;
}>`
width: ${({ itemWidth, itemCount }) => itemWidth * itemCount}px;
display: grid;
grid-template-columns: ${({ itemWidth, itemCount }) => `repeat(${itemCount}, ${itemWidth}px)`};
transition: transform 0.5s ease-in-out;
transform: ${({ translateX }) => `translateX(${translateX}px)`};
gap: ${({ gapWidth }) => `${gapWidth}px`};
`;

const CarouselViewport = styled.div`
Expand All @@ -58,12 +97,7 @@ const Blur = styled.div`
height: 100%;
width: calc(50vw - 50%);
top: 0;
background: linear-gradient(
to right,
transparent 10px,
${colors.background} 50px,
${colors.background}
);
background: ${colors.background};
`;

const LeftBlur = styled(Blur)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default function RecentProjectListCarousel({ children }: { children: JSX.
return (
<Carousel
stride={isDesktopSize ? 2 : 1}
itemWidth={isMobileSize ? 345 : 544}
itemWidth={isMobileSize ? 320 : 544}
gapWidth={isMobileSize ? 14 : 24}
leftArrowType={arrowType}
rightArrowType={arrowType}
overflowType={overflowType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import icArrowStickRight from '@src/assets/icons/ic_arrow_stick_right.svg';
import { textSingularLineEllipsis } from '@src/lib/styles/textEllipsis';

const GridWrapper = styled.div`
width: 524px;
width: 544px;
display: grid;
grid-template-areas: 'img detail' 'img footer';
grid-template-columns: 116px auto;
column-gap: 16px;
background-color: ${colors.gray900};
border-radius: 12px;
padding: 24px;
margin-right: 20px;

/* 모바일 뷰 */
@media (max-width: 899px) {
width: 325px;
width: 320px;
grid-template-areas:
'img detail'
'footer footer';
Expand Down
Loading