-
Notifications
You must be signed in to change notification settings - Fork 0
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(web-domains): 공통 모달 컴포넌트 #71
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { FirstDomainExampleScreen } from '@sambad/web-domains/first-domain'; | ||
|
||
export default FirstDomainExampleScreen; | ||
export default function Second() { | ||
return <div></div>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
import { SecondDomainExampleScreen } from '@sambad/web-domains/second-domain'; | ||
|
||
import styles from '../page.module.css'; | ||
|
||
export default function Second() { | ||
return ( | ||
<main className={styles.main}> | ||
<SecondDomainExampleScreen /> | ||
</main> | ||
); | ||
return <main className={styles.main}></main>; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use client'; | ||
|
||
import { borderRadiusVariants, colors } from '@sambad/sds/theme'; | ||
import { HTMLAttributes, PropsWithChildren, ReactNode, useEffect, useState } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
export interface ModalProps extends HTMLAttributes<HTMLDivElement> { | ||
isOpen: boolean; | ||
width?: number; | ||
footer?: ReactNode; | ||
onClose?: () => void; | ||
} | ||
|
||
export const Modal = ({ isOpen, width, onClose, children, footer, ...rest }: PropsWithChildren<ModalProps>) => { | ||
const [modalState, setIsModalState] = useState<boolean>(isOpen); | ||
const [element, setElement] = useState<HTMLElement | null>(null); | ||
|
||
const modalWidth = width ? `${width}px` : '100%'; | ||
|
||
const handleClose = () => { | ||
setIsModalState(false); | ||
onClose?.(); | ||
}; | ||
|
||
useEffect(() => { | ||
setElement(document.body); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (modalState) { | ||
document.body.style.overflow = 'hidden'; | ||
} else { | ||
document.body.style.overflow = 'auto'; | ||
} | ||
|
||
return () => { | ||
document.body.style.overflow = 'auto'; | ||
}; | ||
}, [modalState]); | ||
|
||
if (typeof window === 'undefined') { | ||
return <></>; | ||
} | ||
|
||
if (!element) { | ||
return <></>; | ||
} | ||
|
||
if (!modalState) { | ||
return null; | ||
} | ||
|
||
return createPortal( | ||
<div | ||
css={{ width: '100%', height: '100%', background: '#00000066', position: 'fixed', top: 0 }} | ||
onClick={handleClose} | ||
> | ||
<div | ||
id="modal" | ||
css={{ | ||
padding: '20px', | ||
width: modalWidth, | ||
maxWidth: '335px', | ||
position: 'fixed', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
backgroundColor: colors.white, | ||
borderRadius: borderRadiusVariants.medium, | ||
zIndex: '10000', | ||
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. 음 createPortal 사용하면 zIndex 필요 없지 않나요? 🤔 |
||
}} | ||
{...rest} | ||
> | ||
{children} | ||
<div id="modal-footer">{footer}</div> | ||
</div> | ||
</div>, | ||
element, | ||
); | ||
}; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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에서 width 제거하고, 내부에서는 제일 많이 사용하는 너비로 width 고정적으로 스타일링하는 것 어떠신가용 ? (maxWidth === 기본 width로..?)
진짜 만약 필요하면 사용처에서 스타일 오버라이드 하라고 하죠 ~!