|
1 | | -import { type ReactNode } from "react"; |
2 | | -import { type DialogProps,Drawer } from "vaul"; |
3 | | - |
4 | | -import * as styles from "./BottomSheet.css"; |
5 | | - |
6 | | -export type BottomSheetProps = { |
7 | | - title: string; |
8 | | - trigger?: ReactNode; |
9 | | - footer?: ReactNode; |
10 | | - content?: ReactNode; |
11 | | -} & DialogProps; |
12 | | - |
13 | | -export const BottomSheet = ({ |
14 | | - title, |
15 | | - trigger, |
16 | | - footer, |
17 | | - content, |
18 | | - ...props |
19 | | -}: BottomSheetProps) => { |
20 | | - return ( |
21 | | - <Drawer.Root {...props}> |
22 | | - {trigger && <Drawer.Trigger asChild>{trigger}</Drawer.Trigger>} |
23 | | - <Drawer.Portal> |
24 | | - <Drawer.Overlay className={styles.overlay} /> |
25 | | - <Drawer.Content className={styles.content}> |
26 | | - <section className={styles.innerContent}> |
27 | | - <div className={styles.handleContainer}> |
28 | | - <div className={styles.handle} /> |
29 | | - </div> |
30 | | - <Drawer.Title className={styles.title}>{title}</Drawer.Title> |
31 | | - <div className={styles.sheetBody}>{content}</div> |
32 | | - {footer && <div className={styles.buttonContainer}>{footer}</div>} |
33 | | - </section> |
34 | | - </Drawer.Content> |
35 | | - </Drawer.Portal> |
36 | | - </Drawer.Root> |
37 | | - ); |
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { BottomSheetBody } from "./BottomSheetBody"; |
| 4 | +import { BottomSheetContent } from "./BottomSheetContent"; |
| 5 | +import { BottomSheetFooter } from "./BottomSheetFooter"; |
| 6 | +import { BottomSheetRoot } from "./BottomSheetRoot"; |
| 7 | +import { BottomSheetTitle } from "./BottomSheetTitle"; |
| 8 | +import { BottomSheetTrigger } from "./BottomSheetTrigger"; |
| 9 | + |
| 10 | +type BottomSheetComposition = { |
| 11 | + /** |
| 12 | + * 바텀시트의 상태 및 컨텍스트를 관리하는 최상위 컴포넌트 (`vaul`의 Drawer.Root 래핑) |
| 13 | + */ |
| 14 | + Root: typeof BottomSheetRoot; |
| 15 | + |
| 16 | + /** |
| 17 | + * 바텀시트를 열기 위한 트리거 (버튼 등) |
| 18 | + * `asChild`로 감싸면 외부 요소를 그대로 트리거로 사용할 수 있음 |
| 19 | + */ |
| 20 | + Trigger: typeof BottomSheetTrigger; |
| 21 | + |
| 22 | + /** |
| 23 | + * 바텀시트의 콘텐츠를 감싸는 영역. Portal을 통해 렌더링되며 Overlay와 Content를 포함 |
| 24 | + */ |
| 25 | + Content: typeof BottomSheetContent; |
| 26 | + |
| 27 | + /** |
| 28 | + * 바텀시트의 제목 영역. 상단 핸들바와 함께 사용 |
| 29 | + */ |
| 30 | + Title: typeof BottomSheetTitle; |
| 31 | + |
| 32 | + /** |
| 33 | + * 바텀시트의 메인 콘텐츠 영역 |
| 34 | + */ |
| 35 | + Body: typeof BottomSheetBody; |
| 36 | + |
| 37 | + /** |
| 38 | + * 바텀시트의 하단 영역. 주로 버튼/액션을 배치하는 데 사용 |
| 39 | + */ |
| 40 | + Footer: typeof BottomSheetFooter; |
| 41 | +}; |
| 42 | + |
| 43 | +/** |
| 44 | + * BottomSheet 컴포넌트 |
| 45 | + * @description Compound Component Pattern을 사용하여 화면 하단에서 나타나는 패널을 구현한 컴포넌트입니다. |
| 46 | + * |
| 47 | + * @see vaul 라이브러리를 기반으로 구현되었습니다. {@link https://vaul.emilkowal.ski/} |
| 48 | + * |
| 49 | + * @example |
| 50 | + * ```tsx |
| 51 | + * <BottomSheet.Root> |
| 52 | + * <BottomSheet.Trigger asChild> |
| 53 | + * <Button>바텀시트 열기</Button> |
| 54 | + * </BottomSheet.Trigger> |
| 55 | + * |
| 56 | + * <BottomSheet.Content> |
| 57 | + * <BottomSheet.Title> |
| 58 | + * 제목 |
| 59 | + * </BottomSheet.Title> |
| 60 | + * |
| 61 | + * <BottomSheet.Body> |
| 62 | + * <p>여기에 컨텐츠가 들어갑니다.</p> |
| 63 | + * </BottomSheet.Body> |
| 64 | + * |
| 65 | + * <BottomSheet.Footer> |
| 66 | + * <Button size="fullWidth">확인</Button> |
| 67 | + * </BottomSheet.Footer> |
| 68 | + * </BottomSheet.Content> |
| 69 | + * </BottomSheet.Root> |
| 70 | + * ``` |
| 71 | + */ |
| 72 | +export const BottomSheet: BottomSheetComposition = { |
| 73 | + Root: BottomSheetRoot, |
| 74 | + Title: BottomSheetTitle, |
| 75 | + Trigger: BottomSheetTrigger, |
| 76 | + Content: BottomSheetContent, |
| 77 | + Body: BottomSheetBody, |
| 78 | + Footer: BottomSheetFooter, |
38 | 79 | }; |
0 commit comments