-
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.
[AUD-82] AppPortal 유틸 공용 컴포넌트 제작 (#48)
* ✨ AppPortal 공용 유틸 컴포넌트 제작 * ✨ AppPortal Z-Index 상수 추가 * ✨ AppPortal Provider 적용
- Loading branch information
Showing
5 changed files
with
73 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { style } from "@vanilla-extract/css"; | ||
import { sprinkles } from "@/styles/sprinkle.css"; | ||
|
||
export const Wrapper = style([ | ||
sprinkles({ zIndex: 'appPortal' }), | ||
{ | ||
position: 'absolute', | ||
left: 0, | ||
top: 0, | ||
|
||
width: '100%', | ||
}]) |
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,45 @@ | ||
import { | ||
type PropsWithChildren, | ||
createContext, | ||
useContext, | ||
useState, | ||
} from 'react'; | ||
|
||
import { createPortal } from 'react-dom'; | ||
|
||
import * as S from './AppPortal.css'; | ||
|
||
interface PropsType extends PropsWithChildren { | ||
portalName?: string | undefined; | ||
} | ||
|
||
const PortalContext = createContext<HTMLDivElement | null>(null); | ||
|
||
const PortalProvider = ({ children }: PropsType) => { | ||
const [portalContainer, setPortalContainer] = | ||
useState<HTMLDivElement | null>(null); | ||
|
||
return ( | ||
<PortalContext.Provider value={portalContainer}> | ||
<div | ||
className={S.Wrapper} | ||
id="app-portal" | ||
ref={(element) => { | ||
if (element && !portalContainer) | ||
setPortalContainer(element); | ||
}} | ||
/> | ||
{children} | ||
</PortalContext.Provider> | ||
); | ||
}; | ||
|
||
const PortalWrapper = ({ children }: PropsType) => { | ||
const portalContainer = useContext(PortalContext); | ||
return portalContainer ? createPortal(children, portalContainer) : null; | ||
}; | ||
|
||
export const AppPortal = { | ||
Provider: PortalProvider, | ||
Wrapper: PortalWrapper, | ||
}; |
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,3 @@ | ||
import { AppPortal } from "./AppPortal"; | ||
|
||
export default AppPortal; |
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,4 +1,5 @@ | ||
export const Z_INDEX = { | ||
appPortal: 9999, | ||
globalNavigation: 999, | ||
mapFloatMenu: 9, | ||
pathPopover: 10, | ||
|