-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…eet-content [FE][Feat] #14 : bottomsheet 관련 로그인, 회원가입
- Loading branch information
Showing
7 changed files
with
191 additions
and
85 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
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,53 +1,86 @@ | ||
import React from 'react'; | ||
import { useBottomSheet } from '@/hooks/useBottomSheet'; | ||
import React, { useState, useRef } from 'react'; | ||
|
||
interface IBottomSheetProps { | ||
minHeight: number; | ||
maxHeight: number; | ||
backgroundColor: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
/** | ||
* `BottomSheet` 컴포넌트는 하단에서 올라오는 시트 형태의 UI를 제공합니다. | ||
* | ||
* @param {IBottomSheetProps} props - `children`을 포함한 컴포넌트 속성 | ||
* @param {number} props.minHeight - Bottom Sheet의 최소 높이를 화면 비율로 나타냅니다 (0.0 - 1.0). | ||
* @param {number} props.maxHeight - Bottom Sheet의 최대 높이를 화면 비율로 나타냅니다 (0.0 - 1.0). | ||
* @param {ReactNode} props.children - Bottom Sheet 내부에 렌더링할 콘텐츠입니다. | ||
* @returns {ReactNode} - 하단 시트를 렌더링합니다. | ||
* | ||
* @remarks | ||
* - 드래그 동작을 통해 시트를 열고 닫을 수 있습니다. | ||
* - `useBottomSheet` 훅을 사용하여 위치 및 드래그 동작을 관리합니다. | ||
* - `minHeight`는 Bottom Sheet가 닫힌 상태의 높이 비율을 나타냅니다. | ||
* - `maxHeight`는 Bottom Sheet가 열린 상태의 최대 높이 비율을 나타냅니다. | ||
* | ||
* @example | ||
* ```tsx | ||
* <BottomSheet minHeight={0.5} maxHeight={0.85}> | ||
* <div className="p-4"> | ||
* <h2>예시 콘텐츠</h2> | ||
* <p>BottomSheet의 children</p> | ||
* </div> | ||
* </BottomSheet> | ||
* ``` | ||
*/ | ||
|
||
export const BottomSheet = (props: IBottomSheetProps) => { | ||
const { sheet } = useBottomSheet({ minHeight: props.minHeight, maxHeight: props.maxHeight }); | ||
export const BottomSheet = ({ | ||
minHeight, | ||
maxHeight, | ||
backgroundColor, | ||
children, | ||
}: IBottomSheetProps) => { | ||
const [sheetHeight, setSheetHeight] = useState(minHeight); | ||
const startY = useRef(0); | ||
const startHeight = useRef(minHeight); | ||
|
||
const handleStart = (y: number) => { | ||
startY.current = y; | ||
startHeight.current = sheetHeight; | ||
}; | ||
|
||
const handleMove = (y: number) => { | ||
const deltaY = startY.current - y; | ||
const newHeight = startHeight.current + deltaY / window.innerHeight; | ||
setSheetHeight(Math.max(minHeight, Math.min(maxHeight, newHeight))); | ||
}; | ||
|
||
const handleTouchStart = (e: React.TouchEvent) => { | ||
handleStart(e.touches[0].clientY); | ||
}; | ||
|
||
const handleTouchMove = (e: React.TouchEvent) => { | ||
handleMove(e.touches[0].clientY); | ||
}; | ||
|
||
const handleMouseMove = (e: MouseEvent) => { | ||
handleMove(e.clientY); | ||
}; | ||
|
||
const handleMouseUp = () => { | ||
window.removeEventListener('mousemove', handleMouseMove); | ||
window.removeEventListener('mouseup', handleMouseUp); | ||
}; | ||
|
||
const handleMouseDown = (e: React.MouseEvent) => { | ||
handleStart(e.clientY); | ||
window.addEventListener('mousemove', handleMouseMove); | ||
window.addEventListener('mouseup', handleMouseUp); | ||
}; | ||
|
||
const handleClose = () => { | ||
setSheetHeight(minHeight); | ||
}; | ||
|
||
return ( | ||
<div | ||
ref={sheet} | ||
className="bg-grayscale-25 shadow-dark fixed left-0 right-0 z-[1000] flex h-full flex-col rounded-t-lg transition-transform duration-700" | ||
className="fixed bottom-0 left-0 right-0 z-50 rounded-t-2xl bg-white shadow-lg transition-transform duration-700 ease-out" | ||
style={{ | ||
top: `calc(100% - ${props.minHeight * 100}%)`, | ||
backgroundColor: `${backgroundColor}`, | ||
height: `${sheetHeight * 100}vh`, | ||
transform: `translateY(${(1 - sheetHeight) * 100}%)`, | ||
}} | ||
onTouchStart={handleTouchStart} | ||
onTouchMove={handleTouchMove} | ||
onMouseDown={handleMouseDown} | ||
> | ||
<div className="flex items-center justify-center pb-1 pt-2"> | ||
<div className="h-1.5 w-12 rounded-full bg-gray-300" /> | ||
</div> | ||
{props.children} | ||
<div className="flex items-center justify-end pb-1 pr-5 pt-2"> | ||
<button | ||
type="button" | ||
className="bg-grayscale-180 h-[30px] w-[30px] rounded-full text-lg font-semibold text-gray-500" | ||
onClick={handleClose} | ||
> | ||
<p className="text-grayscale-850">✕</p> | ||
</button> | ||
</div> | ||
|
||
<div className="h-full overflow-auto">{children}</div> | ||
</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
Oops, something went wrong.