-
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.
- Loading branch information
Showing
7 changed files
with
148 additions
and
23 deletions.
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
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,57 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
import { useTabContext } from '@/components/_common/Tabs/TabContext'; | ||
import { DefaultChecklistTabsNames } from '@/constants/tabs'; | ||
import { flexRow } from '@/styles/common'; | ||
import theme from '@/styles/theme'; | ||
|
||
const TAB_COUNT = DefaultChecklistTabsNames.length; | ||
interface Props { | ||
marginTop?: string; | ||
marginBottom?: string; | ||
} | ||
const MoveNextButton = ({ marginTop = '0', marginBottom = '0' }: Props) => { | ||
const { setCurrentTabId } = useTabContext(); | ||
|
||
const handleClickPrev = () => setCurrentTabId(tabId => (tabId % TAB_COUNT) - 1); | ||
const handleClickNext = () => setCurrentTabId(tabId => ((tabId + 2) % TAB_COUNT) - 1); | ||
return ( | ||
<S.ContentBox marginTop={marginTop} marginBottom={marginBottom}> | ||
<S.Button onClick={handleClickPrev}> | ||
<S.Text color={theme.palette.grey400}>{'< '}</S.Text> | ||
{'이전으로 이동'} | ||
</S.Button> | ||
<S.Button onClick={handleClickNext}> | ||
{'다음으로 이동'} | ||
<S.Text color={theme.palette.grey400}>{' >'}</S.Text> | ||
</S.Button> | ||
</S.ContentBox> | ||
); | ||
}; | ||
|
||
export default MoveNextButton; | ||
|
||
const S = { | ||
Text: styled.span<{ color: string }>` | ||
color: ${({ color }) => color}; | ||
font-weight: ${({ theme }) => theme.text.weight.bold}; | ||
`, | ||
Button: styled.button` | ||
margin: 10px 0; | ||
padding: 0 15px; | ||
background-color: ${({ theme }) => theme.palette.grey200}; | ||
font-weight: ${({ theme }) => theme.text.weight.medium}; | ||
font-size: ${({ theme }) => theme.text.size.small}; | ||
line-height: 2.5; | ||
border-radius: 10px; | ||
`, | ||
ContentBox: styled.div<{ marginTop: string; marginBottom: string }>` | ||
${flexRow} | ||
justify-content: space-around; | ||
margin-top: ${({ marginTop }) => marginTop}; | ||
margin-bottom: ${({ marginBottom }) => marginBottom}; | ||
border-radius: 0.8rem; | ||
`, | ||
}; |
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,47 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
interface MousePosition { | ||
x: number; | ||
y: number; | ||
} | ||
type Handler = (start: MousePosition, end: MousePosition) => void; | ||
|
||
const useMouseDrag = (handler: Handler) => { | ||
const [startPosition, setStartPosition] = useState<MousePosition | null>(null); | ||
|
||
useEffect(() => { | ||
const pointerdownListener = (e: MouseEvent) => { | ||
setStartPosition({ x: e.clientX, y: e.clientY }); | ||
}; | ||
const touchStartListener = (e: TouchEvent) => { | ||
setStartPosition({ x: e.changedTouches[0].clientX, y: e.changedTouches[0].clientX }); | ||
}; | ||
|
||
const pointerupListener = (e: MouseEvent) => { | ||
const endPosition = { x: e.clientX, y: e.clientY }; | ||
if (!startPosition) return; | ||
handler(startPosition, endPosition); | ||
setStartPosition(null); | ||
}; | ||
const touchEndListener = (e: TouchEvent) => { | ||
const endPosition = { x: e.changedTouches[0].clientX, y: e.changedTouches[0].clientY }; | ||
if (!startPosition) return; | ||
handler(startPosition, endPosition); | ||
setStartPosition(null); | ||
}; | ||
|
||
window.addEventListener('mousedown', pointerdownListener); | ||
window.addEventListener('touchstart', touchStartListener); | ||
window.addEventListener('mouseup', pointerupListener); | ||
window.addEventListener('touchend', touchEndListener); | ||
|
||
return () => { | ||
window.removeEventListener('mousedown', pointerdownListener); | ||
window.removeEventListener('mouseup', pointerupListener); | ||
window.removeEventListener('touchstart', touchStartListener); | ||
window.removeEventListener('touchend', touchEndListener); | ||
}; | ||
}, [startPosition, handler]); | ||
}; | ||
|
||
export default useMouseDrag; |
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