-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feat/11/modal component #22
Merged
donghunee
merged 15 commits into
depromeet:develop
from
donghunee:feat/11/modal-component
Jul 8, 2024
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
586fc3e
feat: #2 useModal hook ์ ์
donghunee 1e00004
feat: Modal Componet ์ถ๊ฐ
donghunee b02ecaa
์ํฌํ๋ก์ฐ ์ถ๊ฐ๋ฅผ ์ํ ๋ฉ์ธ ๋ณํฉ
klmhyeonwoo 24a52ed
Merge branch 'main' of https://github.com/depromeet/layer into feat/1โฆ
donghunee 225d4bd
chore: #11 modal-root ์ถ๊ฐ
donghunee bf9619c
fix: #11 document๋ก ์์ , ํ์์๋ ๊ธฐ๋ฅ ์ญ์
donghunee 5097629
Merge branch 'develop' of https://github.com/depromeet/layer into feaโฆ
donghunee 23b69f0
fix: #11 width, height ๋จ์ ๋ณ๊ฒฝ, memo ์ ๊ฑฐ
donghunee 1be0c7d
refactor: #11 px์์ rem์ผ๋ก ์์
donghunee c572a08
refactor: #11 interface์์ type์ผ๋ก ์์
donghunee 1fce93c
refactor: #11 PropsWithChildren type ์ ์ฉ
donghunee 02a99fd
feat: #11 modal atom, type ์ถ๊ฐ
donghunee 37c17bd
refactor: #11 modal component ๋ก์ง ๋ณ๊ฒฝ
donghunee 0883825
refactor: callback type ์์
donghunee 7069640
refactor: #11 useEffect ์์กด์ฑ ๋ฐฐ์ด ์์
donghunee 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 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,69 @@ | ||
import ModalPortal from "@/component/common/modal/ModalPortal"; | ||
import { css } from "@emotion/react"; | ||
import { PropsWithChildren, useEffect, useRef } from "react"; | ||
|
||
type Props = PropsWithChildren<{ | ||
isModalOpen: boolean; | ||
onClose: () => void; | ||
}>; | ||
|
||
function Modal({ onClose, isModalOpen, children }: Props) { | ||
const modalRef = useRef<HTMLDivElement>(null); | ||
|
||
// ๋ชจ๋ฌ ์คํ ์ ์คํฌ๋กค ๋ฐฉ์ง | ||
useEffect(() => { | ||
document.body.style.overflow = isModalOpen ? "hidden" : "auto"; | ||
}, [isModalOpen]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ๋ด์ฉ์ useModal ํ ์์์ isModalOpen ๋์ isOpen์ผ๋ก ๋์ฒดํด์ ์ฎ๊ธฐ๋ฉด ์ด๋จ๊น์ ?? |
||
|
||
// ๋ชจ๋ฌ ์์ญ ์ด์ธ ํด๋ฆญ ์ ๋ชจ๋ฌ ๋ซ๊ธฐ | ||
useEffect(() => { | ||
const listener = (e: MouseEvent) => { | ||
if (modalRef.current && !modalRef.current.contains(e.target as Node)) { | ||
onClose(); | ||
} | ||
}; | ||
document.addEventListener("mousedown", listener); | ||
return () => { | ||
document.removeEventListener("mousedown", listener); | ||
}; | ||
}, [onClose, modalRef]); | ||
|
||
if (!isModalOpen) return null; | ||
|
||
return ( | ||
// FIXME: ์ถํ ๋์์ธ ํ ํฐ ์ฐ๋ ํ ์ปฌ๋ฌ ๊ฐ ๋ณ๊ฒฝ | ||
<ModalPortal> | ||
<div | ||
css={css` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.4); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`} | ||
> | ||
<div | ||
ref={modalRef} | ||
css={css` | ||
padding: 2rem; | ||
min-width: 30rem; | ||
min-height: 10rem; | ||
background-color: #ffffff; | ||
border: 1px solid #cbcbcb; | ||
border-radius: 1rem; | ||
`} | ||
> | ||
{children} | ||
</div> | ||
</div> | ||
</ModalPortal> | ||
); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ReactNode } from "react"; | ||
import ReactDom from "react-dom"; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
const ModalPortal = ({ children }: Props) => { | ||
const el = document.getElementById("modal-root") as HTMLElement; | ||
return ReactDom.createPortal(children, el); | ||
}; | ||
|
||
export default ModalPortal; |
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,21 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
const useModal = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const open = useCallback(() => { | ||
setIsOpen(true); | ||
}, []); | ||
|
||
const close = useCallback(() => { | ||
setIsOpen(false); | ||
}, []); | ||
|
||
return { | ||
open, | ||
close, | ||
isOpen, | ||
}; | ||
}; | ||
|
||
export default useModal; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋ ๊ฒ ํ๊ณ Modal ์์์ ์คํฌ๋กค ๋ฐฉ์งํ๋ ๋ก์ง์ useModal ํ ์ผ๋ก ์ฎ๊ธฐ๋ฉด isModalOpen props๊ฐ ์์ด์ ธ๋ ๋ ๊ฒ ๊ฐ์์!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop๋ก ๋๊ธฐ๋ ๊ฒ๋ณด๋ค ๋ ๊น๋ํ ๊ฒ ๊ฐ์์~!! ๊ฐ์ฌํฉ๋๋ค:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isOpen์ ๊ณ์ ์จ์ผํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์์ ๊ฒ ๊ฐ์์ ์ฝ๋๋ฅผ ๊ฐ์ ํด๋ดค์ต๋๋ค~!!