-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 모달 기본 UI 구현 * feat: 라우팅으로 모달을 열고 닫기 위한 로직 추가 * feat: modal 병렬 라우팅 레이아웃 추가 및 JotaiProvider 삭제 * fix: Modal 닫기 버튼 onClick 함수 변경 및 title 정렬 * feat: Modal ui 패키지로 이동, hook 분리 * fix: 타입 경고 해결 * fix: hook 내보내기 위치 변경 * feat: ui style 재생성 * feat: 라우팅 활용 모달 예시 추가 * feat: jsdoc 추가 및 태그 수정 * fix: JotaiProvider 원복 * fix: title prop 삭제 * fix: open 함수 네이밍 변경 * fix: title 삭제에 따른 예시 prop 삭제 * feat: close 아이콘 적용 * refactor: PropsWithChildren 타입 사용 * feat: useClickOutside 훅 분리 * fix: 불필요한 코드 삭제 및 스토리북 수정 * fix: closeModal props 이름 변경 * refactor: any 타입 좁히기 * feat: setIsOpen 내보내기 추가 * fix: 빌드 에러 해결
- Loading branch information
Showing
14 changed files
with
1,318 additions
and
1,269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
|
||
import { Flex } from "@styled-system/jsx"; | ||
import { Modal } from "@wow-class/ui"; | ||
import { useModalRoute } from "@wow-class/ui/hooks"; | ||
import Button from "wowds-ui/Button"; | ||
|
||
const TestModal = () => { | ||
const { closeModal } = useModalRoute(); | ||
return ( | ||
<Modal onClose={closeModal}> | ||
<Flex gap="sm" width="21rem"> | ||
<Button variant="outline" onClick={closeModal}> | ||
취소 | ||
</Button> | ||
<Button>저장하기</Button> | ||
</Flex> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default TestModal; |
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,5 @@ | ||
const Default = () => { | ||
return null; | ||
}; | ||
|
||
export default Default; |
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
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 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,64 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { useModalState } from "src/hooks"; | ||
|
||
import Text from "../Text"; | ||
import Modal from "."; | ||
|
||
const meta = { | ||
title: "Shared/Modal", | ||
component: Modal, | ||
tags: ["autodocs"], | ||
parameters: { | ||
componentSubtitle: "Modal 컴포넌트", | ||
}, | ||
argTypes: { | ||
onClose: { | ||
description: "Modal 컴포넌트를 닫을 수 있는 함수를 나타냅니다.", | ||
table: { | ||
type: { summary: "function" }, | ||
control: false, | ||
}, | ||
}, | ||
children: { | ||
description: "Modal 컴포넌트의 자식 컴포넌트를 나타냅니다.", | ||
table: { | ||
type: { summary: "ReactNode" }, | ||
control: false, | ||
}, | ||
}, | ||
}, | ||
} satisfies Meta<typeof Modal>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: ( | ||
<Text as="h1" typo="h1"> | ||
상세 정보가 등록되었어요. | ||
</Text> | ||
), | ||
onClose: () => { | ||
console.log("모달 닫기"); | ||
}, | ||
}, | ||
}; | ||
|
||
export const StateModal = () => { | ||
const { isOpen, openModal, closeModal } = useModalState(); | ||
|
||
return ( | ||
<> | ||
<button onClick={openModal}>모달 열기</button> | ||
{isOpen && ( | ||
<Modal onClose={closeModal}> | ||
<Text as="h1" typo="h1"> | ||
상세 정보가 등록되었어요. | ||
</Text> | ||
</Modal> | ||
)} | ||
</> | ||
); | ||
}; |
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,74 @@ | ||
"use client"; | ||
|
||
import { css } from "@styled-system/css"; | ||
import { Flex, styled } from "@styled-system/jsx"; | ||
import Image from "next/image"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
import closeUrl from "../../assets/images/close.svg"; | ||
import { useClickOutside } from "../../hooks"; | ||
|
||
/** | ||
* @description 모달 컴포넌트입니다. | ||
* | ||
* @param {() => void} onClose - 모달 컴포넌트를 닫기 위한 함수. | ||
* @param {ReactNode} [children] - 모달 컴포넌트에 들어갈 자식 요소. | ||
*/ | ||
|
||
export interface ModalProps extends PropsWithChildren { | ||
onClose: () => void; | ||
} | ||
|
||
const Modal = ({ children, onClose }: ModalProps) => { | ||
const modal = useClickOutside<HTMLDialogElement>(onClose); | ||
|
||
return ( | ||
<Flex alignItems="center" className={backDropStyle} justifyContent="center"> | ||
<styled.dialog className={dialogStyle} ref={modal}> | ||
<Image | ||
alt="close-icon" | ||
className={closeButtonStyle} | ||
height={24} | ||
src={closeUrl} | ||
width={24} | ||
onClick={onClose} | ||
/> | ||
{children} | ||
</styled.dialog> | ||
</Flex> | ||
); | ||
}; | ||
|
||
const dialogStyle = css({ | ||
width: "40.75rem", | ||
height: "28.125rem", | ||
|
||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
|
||
position: "relative", | ||
|
||
borderRadius: "md", | ||
shadow: "mono", | ||
}); | ||
|
||
const backDropStyle = css({ | ||
width: "100vw", | ||
height: "100vh", | ||
|
||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
|
||
background: "backgroundDimmer", | ||
}); | ||
|
||
const closeButtonStyle = css({ | ||
position: "absolute", | ||
top: "xl", | ||
right: "xl", | ||
cursor: "pointer", | ||
}); | ||
|
||
export default Modal; |
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,3 @@ | ||
export { default as useClickOutside } from "./useClickOutside"; | ||
export { default as useModalRoute } from "./useModalRoute"; | ||
export { default as useModalState } from "./useModalState"; |
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,28 @@ | ||
import type { RefObject } from "react"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
const useClickOutside = <T extends HTMLElement>( | ||
onClickOutside: (event: MouseEvent) => void | ||
) => { | ||
const notClickableRef: RefObject<T> = useRef<T>(null); | ||
|
||
useEffect(() => { | ||
const handleClickOutside = (e: MouseEvent) => { | ||
const target = e.target as Node; | ||
const isOutside = | ||
notClickableRef.current && !notClickableRef.current.contains(target); | ||
if (!isOutside) return; | ||
|
||
onClickOutside(e); | ||
}; | ||
|
||
document.addEventListener("click", handleClickOutside, true); | ||
return () => { | ||
document.removeEventListener("click", handleClickOutside, true); | ||
}; | ||
}, [notClickableRef, onClickOutside]); | ||
|
||
return notClickableRef; | ||
}; | ||
|
||
export default useClickOutside; |
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,14 @@ | ||
import { useRouter } from "next/navigation"; | ||
import { useCallback } from "react"; | ||
|
||
const useModalRoute = () => { | ||
const router = useRouter(); | ||
|
||
const closeModal = useCallback(() => { | ||
router.back(); | ||
}, [router]); | ||
|
||
return { closeModal }; | ||
}; | ||
|
||
export default useModalRoute; |
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,17 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
const useModalState = () => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
const openModal = useCallback(() => setIsOpen(() => true), []); | ||
const closeModal = useCallback(() => setIsOpen(() => false), []); | ||
|
||
return { | ||
isOpen, | ||
setIsOpen, | ||
openModal, | ||
closeModal, | ||
}; | ||
}; | ||
|
||
export default useModalState; |
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.