-
Notifications
You must be signed in to change notification settings - Fork 3
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#17 modal #18
Merged
Merged
Feat#17 modal #18
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40dcafe
Feat: useOutsideClick훅(지정 영역 이외 클릭시 onClick함수 실행)
zoonyoung dd41766
Feat: 스크롤 방지를 위한 함수 구현
zoonyoung e8a772b
Refactor: modal 포탈틀 위한 div생성(id='modal')
zoonyoung 63431d3
Feat: Exclamation 아이콘 추가
zoonyoung 75513f1
Refactor: box-sizing: border-box, padding, margin:0 설정
zoonyoung 719c86a
Refactor: 파일명 변경(_variables to _color)
zoonyoung c33d017
Feat: color-box추가
zoonyoung 7313bd6
Feat: Modal컴포넌트 추가
zoonyoung 8ca14fb
Refactor: export default 선언 위치 변경
zoonyoung 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
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
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,27 @@ | ||
@import '@/styles/_index.scss'; | ||
|
||
.layout { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: 1000; | ||
background: rgba(0, 0, 0, 0.8); | ||
} | ||
|
||
.box { | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 2rem; | ||
width: 28rem; | ||
padding: 3rem; | ||
background: $white; | ||
@include rounded-sm; | ||
} |
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,42 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import useOutsideClick from '@/hooks/useOutsideClick'; | ||
import { allowScroll, preventScroll } from '@/utils/modal'; | ||
import styles from './Modal.module.scss'; | ||
|
||
type ModalProps = { | ||
children: React.ReactNode; | ||
onClose: () => void; | ||
}; | ||
|
||
function ModalPortal({ children }: { children: React.ReactNode }) { | ||
const [isRendering, setIsRendering] = useState(true); | ||
|
||
useEffect(() => { | ||
setIsRendering(false); | ||
}, []); | ||
|
||
if (isRendering) return null; | ||
return ReactDOM.createPortal(children, document.getElementById('modal') as HTMLElement) as JSX.Element; | ||
} | ||
|
||
export default function Modal({ children, onClose }: ModalProps) { | ||
const modalRef = useRef<HTMLDivElement>(null); | ||
useOutsideClick(modalRef, onClose); | ||
useEffect(() => { | ||
const prevScrollY = preventScroll(); | ||
return () => { | ||
allowScroll(prevScrollY); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<ModalPortal> | ||
<section className={styles.layout}> | ||
<div className={styles.box} ref={modalRef}> | ||
{children} | ||
</div> | ||
</section> | ||
</ModalPortal> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/components/common/Modal/RegistrationModal/RegistrationModal.module.scss
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,9 @@ | ||
@import '@/styles/_index'; | ||
|
||
.text { | ||
@include font-normal; | ||
} | ||
|
||
.button { | ||
@include color-box; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/components/common/Modal/RegistrationModal/RegistrationModal.tsx
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,20 @@ | ||
import Image from 'next/image'; | ||
import { EXCLAMATION } from '@/utils/constants'; | ||
import Modal from '../Modal'; | ||
import styles from './RegistrationModal.module.scss'; | ||
|
||
export default function RegistrationModal({ isModal, onClose }: { isModal: boolean; onClose: () => void }) { | ||
return ( | ||
<div> | ||
{isModal && ( | ||
<Modal onClose={onClose}> | ||
<Image src={EXCLAMATION} alt="check" width={25} height={25} /> | ||
<h2 className={styles.text}>가게 정보를 먼저 등록해 주세요. </h2> | ||
<button className={styles.button} type="button" onClick={onClose}> | ||
확인 | ||
</button> | ||
</Modal> | ||
)} | ||
</div> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/components/common/Modal/RejectionModal/RejectionModal.module.scss
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,20 @@ | ||
@import '@/styles/_index'; | ||
|
||
.text { | ||
@include font-normal; | ||
} | ||
|
||
.selectionBox { | ||
display: flex; | ||
justify-content: center; | ||
width: 100%; | ||
gap: 2rem; | ||
} | ||
|
||
.negativeButton { | ||
@include color-box; | ||
} | ||
|
||
.positiveButton { | ||
@include color-box(fill); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/components/common/Modal/RejectionModal/RejectionModal.tsx
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,25 @@ | ||
import Image from 'next/image'; | ||
import { CHECK } from '@/utils/constants'; | ||
import Modal from '../Modal'; | ||
import styles from './RejectionModal.module.scss'; | ||
|
||
export default function RejectionModal({ isModal, onClose }: { isModal: boolean; onClose: () => void }) { | ||
return ( | ||
<div> | ||
{isModal && ( | ||
<Modal onClose={onClose}> | ||
<Image src={CHECK} alt="check" width={25} height={25} /> | ||
<h2 className={styles.text}>신청을 거절하시겠어요?</h2> | ||
<div className={styles.selectionBox}> | ||
<button className={styles.negativeButton} type="button" onClick={onClose}> | ||
아니요 | ||
</button> | ||
<button className={styles.positiveButton} type="button" onClick={onClose}> | ||
예 | ||
</button> | ||
</div> | ||
</Modal> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RefObject, useEffect } from 'react'; | ||
|
||
const useOutsideClick = (ref: RefObject<HTMLElement>, callback: () => void) => { | ||
useEffect(() => { | ||
const handleOutSectionClick = (event: MouseEvent) => { | ||
const { target } = event; | ||
if (ref.current && !ref.current.contains(target as Node)) callback(); | ||
}; | ||
document.addEventListener('click', handleOutSectionClick); | ||
return () => document.removeEventListener('click', handleOutSectionClick); | ||
}, [ref, callback]); | ||
}; | ||
|
||
export default useOutsideClick; |
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,2 +1,8 @@ | ||
@import './_mixins'; | ||
@import './_color'; | ||
|
||
* { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
} |
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,2 +1,2 @@ | ||
@import './_mixins'; | ||
@import './_variables'; | ||
@import './_color'; |
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,16 @@ | ||
export const preventScroll = () => { | ||
const currentScrollY = window.scrollY; | ||
document.body.style.position = 'fixed'; | ||
document.body.style.width = '100%'; | ||
document.body.style.top = `-${currentScrollY}px`; | ||
document.body.style.overflowY = 'scroll'; | ||
return currentScrollY; | ||
}; | ||
|
||
export const allowScroll = (prevScrollY: number) => { | ||
document.body.style.position = ''; | ||
document.body.style.width = ''; | ||
document.body.style.top = ''; | ||
document.body.style.overflowY = ''; | ||
window.scrollTo(0, prevScrollY); | ||
}; |
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.
괄호로 감싸주시면 좋을 것 같습니다
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.
앗 {} 하기로했었쪄? 수정 하도록 하겠슴다.