-
Notifications
You must be signed in to change notification settings - Fork 0
feat : 공통 컴포넌트 BottomSheet 추가 #50
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
39beb3a
feat : 공통 컴포넌트: BottomSheet 추가
kim3360 f63b178
Merge branch 'develop' into feat/8-Component-BottomSheet
kim3360 b655dc9
chore : vaul 라이브러리 추가
kim3360 dcec5ed
style : SortTabs 컴포넌트 스타일 수정
kim3360 a48d2c9
rename : PinCard 컴포넌트로 수정
kim3360 f0598b1
feat : 하트, 북마크 아이콘 추가
kim3360 2316193
style : 아이콘 & 크기 변경
kim3360 e8086c9
feat : 노래 리스트 바텀시트 추가
kim3360 bc44101
fix : 코드레빗 제안 수정
kim3360 6e379e4
feat : BottomSheetTitle 추가
kim3360 e64de07
Merge branch 'develop' into feat/8-Component-BottomSheet
kim3360 e0f89cf
style : Topbar 컴포넌트 여백 수정
kim3360 1b3a53a
fix : 바텀시트 Topbar 컴포넌트 추가
kim3360 a053aee
style : Topbar 컴포넌트 재수정
kim3360 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
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 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,193 @@ | ||
| import * as React from 'react'; | ||
| import { Drawer as DrawerPrimitive } from 'vaul'; | ||
| import { TopBar } from '@/components/ui/TopBar'; | ||
|
|
||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| type SnapPoint = number | string; | ||
|
|
||
| const DEFAULT_SNAP_POINTS: SnapPoint[] = [0.5, 1]; | ||
|
|
||
| /** Vaul Drawer 루트. 시트 열림/닫힘·스냅 포인트 상태를 관리한다. */ | ||
| function SheetRoot({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) { | ||
| return <DrawerPrimitive.Root data-slot="bottom-sheet" {...props} />; | ||
| } | ||
|
|
||
| /** 시트를 document body 포털로 렌더링한다. */ | ||
| function SheetPortal({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Portal>) { | ||
| return <DrawerPrimitive.Portal data-slot="bottom-sheet-portal" {...props} />; | ||
| } | ||
|
|
||
| type SheetContentProps = React.ComponentProps<typeof DrawerPrimitive.Content>; | ||
|
|
||
| /** 화면 하단에 고정되는 시트 패널. 기본 레이아웃·스타일을 적용한다. */ | ||
| function SheetContent({ className, children, ...props }: SheetContentProps) { | ||
| return ( | ||
| <SheetPortal> | ||
| <DrawerPrimitive.Content | ||
| data-slot="bottom-sheet-content" | ||
| className={cn( | ||
| 'fixed inset-x-0 bottom-0 z-50 mx-auto flex w-full max-w-[402px] flex-col overflow-hidden', | ||
| 'rounded-t-[20px] bg-pli-black-100 pb-[env(safe-area-inset-bottom)] outline-none', | ||
| className, | ||
| )} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </DrawerPrimitive.Content> | ||
| </SheetPortal> | ||
| ); | ||
| } | ||
|
|
||
| /** 상단 드래그 핸들. 사용자가 시트 높이를 조절할 때 잡는 영역이다. */ | ||
| function SheetHandle({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Handle>) { | ||
| return ( | ||
| <DrawerPrimitive.Handle | ||
| data-slot="bottom-sheet-handle" | ||
| className="mx-auto mt-[10px] !h-1 !w-[41px] !rounded-[2px] !bg-[#8A8A8A]" // Vaul이 주입하는 [data-vaul-handle] 기본 스타일이 Tailwind보다 늦게 적용되어 !로 덮어쓴다. | ||
|
|
||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| type BottomSheetContextValue = { | ||
| isFullPage: boolean; | ||
| onClose: () => void; | ||
| /** 풀페이지 → 이전 스냅(절반)으로 내리기 */ | ||
| collapse: () => void; | ||
| }; | ||
|
|
||
| const BottomSheetContext = React.createContext<BottomSheetContextValue | null>(null); | ||
|
|
||
| /** BottomSheet 하위 컴포넌트에서 풀페이지 여부·닫기·접기 상태에 접근하는 훅. */ | ||
| function useBottomSheet() { | ||
| const context = React.useContext(BottomSheetContext); | ||
| if (!context) { | ||
| throw new Error('useBottomSheet must be used within BottomSheet'); | ||
| } | ||
| return context; | ||
| } | ||
|
|
||
| type BottomSheetProps = { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| children: React.ReactNode; | ||
| /** drag handle 표시 여부 */ | ||
| showHandle?: boolean; | ||
| /** 오버레이 클릭·드래그로 닫기 */ | ||
| dismissible?: boolean; | ||
| /** | ||
| * 스냅 지점(높이 단계). 기본 [0.5, 1] = 절반 → 전체. | ||
| * 마지막 지점(끝까지 올림)에 도달하면 페이지 형식으로 전환된다. | ||
| */ | ||
| snapPoints?: SnapPoint[]; | ||
| className?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * 바텀시트 메인 컴포넌트. | ||
| * 스냅 포인트(기본 절반 → 전체)를 제어하고, 마지막 스냅에 도달하면 풀페이지 UI로 전환한다. | ||
| */ | ||
| function BottomSheet({ | ||
| open, | ||
| onClose, | ||
| children, | ||
| showHandle = true, | ||
| dismissible = true, | ||
| snapPoints = DEFAULT_SNAP_POINTS, | ||
| className, | ||
| }: BottomSheetProps) { | ||
| const firstSnap = snapPoints[0] ?? null; | ||
| const lastSnap = snapPoints[snapPoints.length - 1]; | ||
| const [activeSnap, setActiveSnap] = React.useState<SnapPoint | null>(firstSnap); | ||
| const [prevOpen, setPrevOpen] = React.useState(open); | ||
|
|
||
| if (open !== prevOpen) { | ||
| setPrevOpen(open); | ||
| if (open) { | ||
| setActiveSnap(firstSnap); | ||
| } | ||
| } | ||
|
|
||
| const isFullPage = activeSnap === lastSnap; | ||
|
|
||
| const collapse = React.useCallback(() => { | ||
| setActiveSnap(firstSnap); | ||
| }, [firstSnap]); | ||
|
|
||
| return ( | ||
| <BottomSheetContext.Provider value={{ isFullPage, onClose, collapse }}> | ||
| <SheetRoot | ||
| open={open} | ||
| dismissible={dismissible} | ||
| shouldScaleBackground={false} | ||
| snapPoints={snapPoints} | ||
| fadeFromIndex={0} | ||
| activeSnapPoint={activeSnap} | ||
| setActiveSnapPoint={setActiveSnap} | ||
| onOpenChange={(isOpen) => { | ||
| if (!isOpen) { | ||
| onClose(); | ||
| } | ||
| }} | ||
| > | ||
| <SheetContent | ||
| data-full-page={isFullPage ? '' : undefined} | ||
| className={cn( | ||
| 'h-full max-h-full transition-[border-radius,background-color] duration-200', | ||
| isFullPage | ||
| ? 'rounded-none bg-pli-black-100 pt-[env(safe-area-inset-top)]' | ||
| : 'rounded-t-2xl', | ||
| className, | ||
| )} | ||
| > | ||
| {showHandle && !isFullPage ? <SheetHandle /> : null} | ||
| <div className="flex min-h-0 flex-1 flex-col">{children}</div> | ||
| </SheetContent> | ||
| </SheetRoot> | ||
| </BottomSheetContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| type SectionProps = React.ComponentProps<'div'>; | ||
|
|
||
| type TitleProps = React.ComponentProps<typeof DrawerPrimitive.Title>; | ||
|
|
||
| /** 시트 상단 고정 영역. 제목·검색창 등 스크롤되지 않는 헤더에 사용한다. */ | ||
| function BottomSheetHeader({ className, ...props }: SectionProps) { | ||
| return <div className={className} {...props} />; | ||
| } | ||
|
|
||
| /** 시트 접근성 제목. Header 안의 h2를 이 컴포넌트로 감싼다. */ | ||
| function BottomSheetTitle({ className, ...props }: TitleProps) { | ||
| return <DrawerPrimitive.Title data-slot="bottom-sheet-title" className={className} {...props} />; | ||
| } | ||
|
|
||
| /** 시트 본문 스크롤 영역. 리스트·카드 등 긴 콘텐츠를 담는다. */ | ||
| function BottomSheetContent({ className, ...props }: SectionProps) { | ||
| return ( | ||
| <div | ||
| className={cn('min-h-0 flex-1 overflow-y-auto overscroll-contain px-5', className)} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| type FullPageNavProps = React.ComponentProps<typeof TopBar>; | ||
|
|
||
| /** 풀페이지 모드에서만 표시되는 상단 네비. 뒤로(접기)·닫기 버튼을 제공한다. */ | ||
| function BottomSheetFullPageNav(props: FullPageNavProps) { | ||
| const { isFullPage, collapse, onClose } = useBottomSheet(); | ||
|
|
||
| if (!isFullPage) return null; | ||
|
|
||
| return <TopBar {...props} onBack={collapse} onClose={onClose} />; | ||
| } | ||
|
|
||
| BottomSheet.Header = BottomSheetHeader; | ||
| BottomSheet.Title = BottomSheetTitle; | ||
| BottomSheet.Content = BottomSheetContent; | ||
| BottomSheet.FullPageNav = BottomSheetFullPageNav; | ||
|
|
||
| export { BottomSheet, useBottomSheet }; | ||
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,46 @@ | ||
| import { cn } from '@/lib/utils'; | ||
| import type { Pin } from '@/types/pin'; | ||
|
|
||
| import NextIcon from '@/assets/icons/next.svg?react'; | ||
| import HeartIcon from '@/assets/icons/heart.svg?react'; | ||
|
|
||
| type PingCardProps = { | ||
| pin: Pin; | ||
| onClick?: () => void; | ||
| }; | ||
|
|
||
| export function PinCard({ pin, onClick }: PingCardProps) { | ||
| const { title, artist, pinCount, likeCount, liked } = pin; | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={onClick} | ||
| className="flex w-full rounded-xl bg-pli-black-85 p-4.5 justify-between" | ||
|
kim3360 marked this conversation as resolved.
|
||
| > | ||
| <div className="flex flex-col gap-4"> | ||
| <div className="flex gap-4"> | ||
| <div className="size-13 rounded-lg bg-grayscale-0" /> | ||
|
|
||
| <div className="flex flex-col gap-[3px] items-start"> | ||
| <p className="truncate body-17-m text-grayscale-100">{title}</p> | ||
| <p className="truncate etc-15-r text-grayscale-400">{artist}</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex items-center gap-1 body-15-r text-grayscale-400"> | ||
| <HeartIcon | ||
| className={cn('size-4', liked ? 'fill-red text-red' : 'text-grayscale-400')} | ||
| aria-hidden | ||
| /> | ||
| {likeCount} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex items-center gap-1 etc-13-r text-grayscale-400"> | ||
| {pinCount}명이 PIN | ||
| <NextIcon className="size-4" aria-hidden /> | ||
| </div> | ||
| </button> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.