-
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: #24 React Portal Modal Layout UI 작업
- Loading branch information
Showing
5 changed files
with
79 additions
and
30 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
Empty file.
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,7 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
export default function ModalPortal({ children }: PropsWithChildren) { | ||
const container = document.getElementById('modal')! as HTMLDivElement; | ||
return createPortal(children, container); | ||
} |
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,23 @@ | ||
import { useEffect } from 'react'; | ||
|
||
type ModalLayoutProps = { | ||
onClose: () => void; | ||
children?: React.ReactNode | undefined; | ||
}; | ||
|
||
export default function ModalLayout({ onClose, children }: ModalLayoutProps) { | ||
const handleKeyDownClose = (event: KeyboardEvent) => { | ||
if (event.key.toLowerCase() === 'escape') onClose(); | ||
}; | ||
|
||
useEffect(() => { | ||
globalThis.addEventListener('keydown', handleKeyDownClose); | ||
return () => globalThis.removeEventListener('keydown', handleKeyDownClose); | ||
}, []); | ||
|
||
return ( | ||
<div className="absolute bottom-0 left-0 right-0 top-0 flex items-center justify-center bg-black/50" tabIndex={-1}> | ||
<div className="h-4/5 max-h-375 min-w-375 overflow-auto bg-white p-20">{children}</div> | ||
</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