-
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.
- Loading branch information
Showing
14 changed files
with
111 additions
and
98 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
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { Modal } from '@/shared/ui' | ||
|
||
export function SignInModal() { | ||
return ( | ||
<Modal> | ||
<Modal.Content></Modal.Content> | ||
</Modal> | ||
) | ||
return <Modal></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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { Modal } from '@/shared/ui' | ||
|
||
export function SignUpModal() { | ||
return ( | ||
<Modal> | ||
<Modal.Content></Modal.Content> | ||
</Modal> | ||
) | ||
return <Modal></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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export { useBlockScroll } from './use-block-scroll' | ||
export { useDragHandler } from './use-drag-handler' | ||
export { useHistoryBack } from './use-history-back' |
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,3 +1,5 @@ | ||
'use client' | ||
|
||
import { useEffect } from 'react' | ||
|
||
export function useBlockScroll() { | ||
|
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 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
import { SITE_PATH } from '@/shared/constants' | ||
|
||
export function useHistoryBack() { | ||
const router = useRouter() | ||
const history = typeof window !== 'undefined' ? window.history : [] | ||
|
||
const onClickBack = () => { | ||
if (history.length) { | ||
router.back() | ||
} else { | ||
router.push(SITE_PATH.home, { scroll: true }) | ||
} | ||
} | ||
|
||
return { onClickBack } | ||
} |
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 @@ | ||
'use client' | ||
|
||
import Image from 'next/image' | ||
|
||
import { useHistoryBack } from '@/shared/hook' | ||
import styles from '@/shared/ui/close-button.module.scss' | ||
|
||
export function CloseButton() { | ||
const { onClickBack } = useHistoryBack() | ||
return ( | ||
<Image | ||
onClick={onClickBack} | ||
className={styles.closeButton} | ||
width={50} | ||
height={50} | ||
src="/svg/close.svg" | ||
alt="닫기 버튼" | ||
/> | ||
) | ||
} |
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,60 +1,23 @@ | ||
'use client' | ||
import { PropsWithChildren } from 'react' | ||
|
||
import Image from 'next/image' | ||
import { useRouter } from 'next/navigation' | ||
import { PropsWithChildren, useEffect } from 'react' | ||
|
||
import { SITE_PATH } from '@/shared/constants' | ||
import RQProvider from '@/shared/lib/react-query/RQProvider' | ||
import { getScrollbarWidth } from '@/shared/lib/util' | ||
import { CloseButton } from '@/shared/ui/CloseButton' | ||
import { ModalBackGround } from '@/shared/ui/ModalBackGround' | ||
|
||
import styles from './modal.module.scss' | ||
|
||
function Content({ children }: PropsWithChildren) { | ||
const onInnerClick = (e: React.MouseEvent) => { | ||
e.stopPropagation() | ||
} | ||
|
||
return ( | ||
<div onClick={onInnerClick} className={styles.modalContent}> | ||
{children} | ||
</div> | ||
) | ||
type Props = { | ||
isClose?: boolean | ||
} | ||
|
||
function ModalBackGround({ children }: Readonly<PropsWithChildren>) { | ||
const router = useRouter() | ||
const history = typeof window !== 'undefined' ? window.history : [] | ||
|
||
useEffect(() => { | ||
const width = getScrollbarWidth() | ||
|
||
if (Object.is(width, undefined)) return | ||
|
||
document.body.style.overflow = 'hidden' | ||
document.body.style.marginRight = `${width}px` | ||
return () => { | ||
document.body.style.overflow = 'auto' | ||
document.body.style.marginRight = '0px' | ||
} | ||
}, []) | ||
|
||
const onClickBack = () => { | ||
if (history.length) { | ||
router.back() | ||
} else { | ||
router.push(SITE_PATH.home, { scroll: true }) | ||
} | ||
} | ||
|
||
export function Modal({ children, isClose = false }: Readonly<PropsWithChildren<Props>>) { | ||
return ( | ||
<RQProvider> | ||
<button className={styles.container} onClick={onClickBack}> | ||
<Image className={styles.closeButton} src="/public/svg/close.svg" alt="닫기 버튼" /> | ||
{children} | ||
</button> | ||
</RQProvider> | ||
<section className={styles.container}> | ||
<ModalBackGround /> | ||
{isClose && <CloseButton />} | ||
<RQProvider> | ||
<div className={styles.content}>{children}</div> | ||
</RQProvider> | ||
</section> | ||
) | ||
} | ||
|
||
export const Modal = Object.assign(ModalBackGround, { Content }) |
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,11 @@ | ||
'use client' | ||
|
||
import { useBlockScroll, useHistoryBack } from '@/shared/hook' | ||
import styles from '@/shared/ui/modal.module.scss' | ||
|
||
export function ModalBackGround() { | ||
useBlockScroll() | ||
const { onClickBack } = useHistoryBack() | ||
|
||
return <div onClick={onClickBack} className={styles.background} /> | ||
} |
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 @@ | ||
.closeButton { | ||
cursor: pointer; | ||
z-index: 9990; | ||
width: 80px; | ||
height: 80px; | ||
position: absolute; | ||
top: 5%; | ||
right: 5%; | ||
} |
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,32 +1,34 @@ | ||
.container { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
z-index: 9990; | ||
width: 100%; | ||
height: 100dvh; | ||
} | ||
|
||
.background { | ||
cursor: pointer; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
z-index: 9999; | ||
z-index: 9000; | ||
background: rgba(0, 0, 0, 0.5); | ||
width: 100%; | ||
height: 100dvh; | ||
} | ||
|
||
.modalContent { | ||
.content { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -60%); | ||
z-index: 9991; | ||
transform: translate(-50%, -50%); | ||
width: 700px; | ||
height: 400px; | ||
height: fit-content; | ||
min-height: 400px; | ||
border-radius: 20px; | ||
border: 2px solid #fffffe; | ||
padding: 20px; | ||
background: #101820; | ||
} | ||
|
||
.closeButton { | ||
z-index: 9990; | ||
width: 80px; | ||
height: 80px; | ||
position: absolute; | ||
top: 5%; | ||
right: 5%; | ||
} | ||
} |
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