-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 플로팅버튼 공통 컴포넌트로 분리, 스크롤 top 기능 구현
- Loading branch information
1 parent
d6a5b3f
commit 4dfa9f6
Showing
7 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
'use client'; | ||
|
||
/** | ||
TODO | ||
- [x] 클릭 시 최상단으로 이동 구현 | ||
- [x] 스크롤에 따른 버튼 디자인 구현 | ||
- [x] 다른 페이지에서도 사용할 수 있도록 공통 컴포넌트화(리팩토링) | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
|
||
import * as styles from './FloatingContainer.css'; | ||
import ArrowUpIcon from '/public/icons/arrow_up.svg'; | ||
|
||
export default function ArrowUpFloatingButton() { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
const handleScrollToTop = () => { | ||
if (!isVisible) return; | ||
|
||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth', | ||
}); | ||
}; | ||
|
||
const visibleButton = () => { | ||
if (window.scrollY < 500) { | ||
setIsVisible(false); | ||
} else { | ||
setIsVisible(true); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('scroll', visibleButton); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', visibleButton); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={styles.arrowUpButton} | ||
onClick={handleScrollToTop} | ||
style={assignInlineVars({ | ||
[styles.opacitySize]: isVisible ? '1' : '0', | ||
[styles.cursor]: isVisible ? 'pointer' : 'default', | ||
})} | ||
> | ||
<ArrowUpIcon alt="상단으로 이동하기 버튼" className={styles.icon} /> | ||
</div> | ||
); | ||
} |
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,9 @@ | ||
import * as styles from './FloatingContainer.css'; | ||
|
||
interface FloatingButtonProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export default function FloatingContainer({ children }: FloatingButtonProps) { | ||
return <div className={styles.container}>{children}</div>; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/components/floatingButton/PlusOptionFloatingButton.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,18 @@ | ||
'use client'; | ||
|
||
/** | ||
TODO | ||
- [ ] 클릭 시 옵션 메뉴 구현 | ||
- [ ] 다른 페이지에서도 사용할 수 있도록 공통 컴포넌트화(리팩토링) | ||
*/ | ||
|
||
import * as styles from './FloatingContainer.css'; | ||
import PlusIcon from '/public/icons/plus.svg'; | ||
|
||
export default function PlusOptionFloatingButton() { | ||
return ( | ||
<div className={styles.addButton}> | ||
<PlusIcon alt="옵션 보기 버튼" className={styles.icon} /> | ||
</div> | ||
); | ||
} |