-
Notifications
You must be signed in to change notification settings - Fork 3
[feature] 스크롤 트리거 훅과 스크롤 상단 이동 버튼 추가 #800
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
Merged
seongwon030
merged 13 commits into
develop-fe
from
feature/#799-scroll-to-top-hook-and-button-MOA-297
Nov 19, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a6c5b54
feat: 스크롤 상단 이동 버튼 추가
seongwon030 013debd
style: bottom 20->80px로 변경
seongwon030 32f0805
refactor: useScrollToTop 훅에서 스크롤 임계값 상수화
seongwon030 ecf525d
feat: scroll 이벤트 리스너에 passive 옵션 추가
seongwon030 f3d4919
Merge branch 'develop-fe' into feature/#799-scroll-to-top-hook-and-bu…
seongwon030 be2c7a0
fix: 스크롤 버튼 svg 변경
seongwon030 256a956
refactor: scrollButton을 Button폴더에서 제거
seongwon030 d76aa95
feat: 스크롤 탑 버튼 컴포넌트 및 커스텀 훅 구현
seongwon030 f0c2407
refactor: scrollButton 스타일 별개의 폴더로 분리
seongwon030 9cf5cb6
refactor: ScrollButton을 독립 폴더로 분리하고 useScrollToTop 훅 적용
seongwon030 d0b081a
refactor: App.tsx에 ScrollButton 임포트 경로 변경
seongwon030 583e77d
refactor: useScrollTrigger 성능 최적화
seongwon030 7f40406
refactor: ScrollButton을 ScrollToTopButton으로 이름변경
seongwon030 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 hidden or 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.
21 changes: 21 additions & 0 deletions
21
frontend/src/components/common/ScrollToTopButton/ScrollToTopButton.styles.ts
This file contains hidden or 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,21 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| export const ScrollButton = styled.button<{ $isVisible: boolean }>` | ||
| position: fixed; | ||
| bottom: 80px; | ||
| right: 30px; | ||
| z-index: 1000; | ||
| opacity: ${({ $isVisible }) => ($isVisible ? 1 : 0)}; | ||
| visibility: ${({ $isVisible }) => ($isVisible ? 'visible' : 'hidden')}; | ||
| transition: opacity 0.3s, visibility 0.3s; | ||
| background: none; | ||
| border: none; | ||
| cursor: pointer; | ||
| padding: 0; | ||
|
|
||
| img { | ||
| width: 50px; | ||
| height: 50px; | ||
| display: block; | ||
| } | ||
| `; | ||
23 changes: 23 additions & 0 deletions
23
frontend/src/components/common/ScrollToTopButton/ScrollToTopButton.tsx
This file contains hidden or 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,23 @@ | ||
| import { useScrollTrigger } from '@/hooks/useScrollTrigger'; | ||
| import scrollButtonIcon from '@/assets/images/icons/scroll_icon.svg'; | ||
| import * as Styled from './ScrollToTopButton.styles'; | ||
|
|
||
|
|
||
| export const ScrollToTopButton = () => { | ||
| const { isTriggered } = useScrollTrigger(); | ||
|
|
||
| const handleScrollToTop = () => { | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Styled.ScrollButton | ||
| type="button" | ||
| $isVisible={isTriggered} | ||
| onClick={handleScrollToTop} | ||
| aria-label="위로 이동하기" | ||
| > | ||
| <img src={scrollButtonIcon} alt="Scroll to top" /> | ||
| </Styled.ScrollButton> | ||
| ); | ||
| }; |
This file contains hidden or 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,39 @@ | ||
| import { useEffect, useState, useCallback } from "react"; | ||
|
|
||
| interface ScrollTriggerOptions { | ||
| threshold?: number; | ||
| direction?: 'up' | 'down'; | ||
| passive?: boolean; | ||
| onChange?: (next: boolean) => void; | ||
| } | ||
|
|
||
|
|
||
| export const useScrollTrigger = ({ | ||
| threshold = 10, | ||
| direction = 'down', | ||
| passive = true, | ||
| onChange, | ||
| }: ScrollTriggerOptions = {}) => { | ||
| const [isTriggered, setIsTriggered] = useState(false); | ||
|
|
||
| const handleScroll = useCallback(() => { | ||
| const scrollY = window.scrollY; | ||
| const shouldShowButton = | ||
| direction === 'down' | ||
| ? scrollY > threshold | ||
| : scrollY < threshold; | ||
|
|
||
| setIsTriggered((prev) => { | ||
| if (shouldShowButton === prev) return prev; | ||
| onChange?.(shouldShowButton); | ||
| return shouldShowButton; | ||
| }) | ||
| }, [ direction, threshold, onChange]); | ||
seongwon030 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| window.addEventListener('scroll', handleScroll, { passive }); | ||
| return () => window.removeEventListener('scroll', handleScroll); | ||
| }, [handleScroll, passive]); | ||
|
|
||
| return { isTriggered }; | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.