-
Notifications
You must be signed in to change notification settings - Fork 7
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
구경가기 상단 캐러셀 구현 #849
Merged
Merged
구경가기 상단 캐러셀 구현 #849
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
269adbc
feat(src): Carousel, HotTopicCarousel, useHotTopic 생성 및 TemplateExplo…
Hain-tain 6dc3ba8
feat(Footer): 문의 이메일 직접 표기
Hain-tain 8668aa0
refactor(src): 템플릿 카드, 템플릿 상세 페이지에서 작성자, 시간 색상 primary => secondary로 변경
Hain-tain dfa8c13
feat(TemplateExplorePage): 구경가기 템플릿 리스트 로딩 처리
Hain-tain c2b7c8a
design(TemplateCard): 작성자 이름 색상 primary 로 변경
Hain-tain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 +1,4 @@ | ||
import { ContactUs, Text } from '@/components'; | ||
import { Text } from '@/components'; | ||
import { useAuth } from '@/hooks/authentication'; | ||
|
||
import * as S from './Footer.style'; | ||
|
@@ -20,7 +20,7 @@ const Footer = () => { | |
© All rights reserved. | ||
</Text.Small> | ||
<S.ContactEmail> | ||
<ContactUs /> | ||
<Text.Small color='inherit'>문의: [email protected]</Text.Small> | ||
</S.ContactEmail> | ||
</S.FooterContainer> | ||
); | ||
|
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
Empty file.
62 changes: 62 additions & 0 deletions
62
frontend/src/pages/TemplateExplorePage/components/Carousel/Carousel.style.ts
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,62 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { ChevronIcon } from '@/assets/images'; | ||
import { theme } from '@/style/theme'; | ||
|
||
export const CarouselContainer = styled.div` | ||
display: flex; | ||
gap: 1rem; | ||
align-items: center; | ||
|
||
width: 100%; | ||
padding: 1rem; | ||
`; | ||
|
||
export const CarouselViewport = styled.div` | ||
position: relative; | ||
overflow: hidden; | ||
width: 100%; | ||
`; | ||
|
||
export const CarouselList = styled.ul<{ translateX: number; transitioning: boolean }>` | ||
transform: translateX(${(props) => props.translateX}px); | ||
display: flex; | ||
gap: 1rem; | ||
transition: ${(props) => (props.transitioning ? 'transform 0.3s ease-in-out' : 'none')}; | ||
`; | ||
|
||
export const CarouselItem = styled.li` | ||
display: flex; | ||
flex-shrink: 0; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
width: 18rem; | ||
height: 9rem; | ||
|
||
@media (max-width: 768px) { | ||
width: 9rem; | ||
} | ||
`; | ||
|
||
export const CarouselButton = styled.button` | ||
cursor: pointer; | ||
|
||
padding: 1rem; | ||
|
||
background-color: white; | ||
border: 1px solid ${theme.color.light.secondary_300}; | ||
border-radius: 8px; | ||
|
||
&:hover { | ||
background-color: ${theme.color.light.secondary_50}; | ||
} | ||
`; | ||
|
||
export const PrevIcon = styled(ChevronIcon)` | ||
transform: rotate(90deg); | ||
`; | ||
|
||
export const NextIcon = styled(ChevronIcon)` | ||
transform: rotate(270deg); | ||
`; |
101 changes: 101 additions & 0 deletions
101
frontend/src/pages/TemplateExplorePage/components/Carousel/Carousel.tsx
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,101 @@ | ||
import { useState, useCallback, useEffect, useRef } from 'react'; | ||
|
||
import { useWindowWidth } from '@/hooks'; | ||
import { BREAKING_POINT } from '@/style/styleConstants'; | ||
|
||
import * as S from './Carousel.style'; | ||
|
||
interface CarouselItem { | ||
id: number; | ||
content: React.ReactNode; | ||
} | ||
|
||
interface Props { | ||
items: CarouselItem[]; | ||
} | ||
|
||
const Carousel = ({ items }: Props) => { | ||
const windowWidth = useWindowWidth(); | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
const [isTransitioning, setIsTransitioning] = useState(false); | ||
const transitionTimer = useRef<NodeJS.Timeout | null>(null); | ||
|
||
const displayItems = [...items, ...items, ...items]; | ||
|
||
const ITEM_WIDTH = windowWidth < BREAKING_POINT.MOBILE ? 144 : 288; // CarouselItem 넓이 | ||
const ITEM_GAP = 16; // 1rem | ||
const MOVE_DISTANCE = ITEM_WIDTH + ITEM_GAP; | ||
const originalLength = items.length; | ||
|
||
const translateX = -(currentIndex * MOVE_DISTANCE + originalLength * MOVE_DISTANCE); | ||
|
||
const moveCarousel = useCallback( | ||
(direction: 'prev' | 'next') => { | ||
const newIndex = direction === 'next' ? currentIndex + 1 : currentIndex - 1; | ||
|
||
setIsTransitioning(true); | ||
setCurrentIndex(newIndex); | ||
}, | ||
[currentIndex], | ||
); | ||
|
||
const needsReposition = useCallback( | ||
(index: number) => { | ||
const threshold = originalLength; | ||
|
||
return index <= -threshold || index >= threshold; | ||
}, | ||
[originalLength], | ||
); | ||
|
||
const resetPosition = useCallback(() => { | ||
setIsTransitioning(false); | ||
|
||
setCurrentIndex(currentIndex % originalLength); | ||
|
||
requestAnimationFrame(() => { | ||
requestAnimationFrame(() => { | ||
setIsTransitioning(true); | ||
}); | ||
}); | ||
}, [currentIndex, originalLength]); | ||
|
||
useEffect(() => { | ||
if (needsReposition(currentIndex)) { | ||
if (transitionTimer.current) { | ||
clearTimeout(transitionTimer.current); | ||
} | ||
|
||
transitionTimer.current = setTimeout(() => { | ||
resetPosition(); | ||
setIsTransitioning(false); | ||
}, 300); // transition: transform 0.3s 이기 때문 | ||
} | ||
|
||
return () => { | ||
if (transitionTimer.current) { | ||
clearTimeout(transitionTimer.current); | ||
} | ||
}; | ||
}, [currentIndex, needsReposition, resetPosition]); | ||
|
||
return ( | ||
<S.CarouselContainer> | ||
<S.CarouselButton onClick={() => moveCarousel('prev')}> | ||
<S.PrevIcon /> | ||
</S.CarouselButton> | ||
<S.CarouselViewport> | ||
<S.CarouselList translateX={translateX} transitioning={isTransitioning}> | ||
{displayItems.map((item) => ( | ||
<S.CarouselItem key={item.id}>{item.content}</S.CarouselItem> | ||
))} | ||
</S.CarouselList> | ||
</S.CarouselViewport> | ||
<S.CarouselButton onClick={() => moveCarousel('next')}> | ||
<S.NextIcon /> | ||
</S.CarouselButton> | ||
</S.CarouselContainer> | ||
); | ||
}; | ||
|
||
export default Carousel; |
16 changes: 16 additions & 0 deletions
16
frontend/src/pages/TemplateExplorePage/components/HotTopicCarousel/HotTopicCarousel.style.ts
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,16 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const Topic = styled.button<{ background: string; border: string; isSelected: boolean }>` | ||
cursor: pointer; /* 커서 스타일 추가 */ | ||
|
||
width: 100%; | ||
height: 100%; | ||
|
||
background-color: ${({ background }) => background}; | ||
border: ${({ isSelected, border }) => (isSelected ? `2px solid ${border}` : 'none')}; | ||
border-radius: 12px; | ||
|
||
&:hover { | ||
border: 2px solid ${({ border }) => border}; | ||
} | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 스타일의 크기와 밀접한 관련이 있기 때문에 상수 처리를 해주거나, 해당 스타일과 묶어주고 싶었으나 현재 좋은 방법이 떠오르지 않아 일단 매직넘버로 처리하고 주석 달아두었습니다.