Skip to content

Commit 42d9679

Browse files
committed
chore(refactor): move portal component to shared package
1 parent dba57a7 commit 42d9679

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

apps/web/src/components/Modals/ModalBase/Overlay.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ import { cn } from "@mav/shared/utils"
44
import dynamic from "next/dynamic"
55
import { useEffect } from "react"
66

7-
const Portal = dynamic(() => import("./Portal"), { ssr: false })
7+
const Portal = dynamic(
8+
() => import("@mav/ui/components/layouts").then((c) => c.Portal),
9+
{
10+
ssr: false
11+
}
12+
)
13+
14+
interface OverlayProps {
15+
state?: unknown
16+
toggler?: React.Dispatch<React.SetStateAction<boolean>>
17+
}
818

919
export default function Overlay({
1020
children,
1121
state,
1222
toggler
13-
}: {
14-
children?: React.ReactNode
15-
state?: unknown
16-
toggler?: React.Dispatch<React.SetStateAction<boolean>>
17-
}) {
23+
}: React.PropsWithChildren<OverlayProps>) {
1824
useEffect(() => {
1925
const bodyStyle = document.body.style
2026

@@ -29,7 +35,7 @@ export default function Overlay({
2935
return (
3036
<Portal>
3137
<div
32-
onClick={toggler as () => any}
38+
onClick={toggler as () => void}
3339
className={cn(
3440
"fixed inset-0 z-[99] bg-black/60 transition-all duration-[350ms]",
3541
state ? "opacity-100" : "pointer-events-none opacity-0"

apps/web/src/components/Modals/ModalBase/Portal.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createPortal } from "react-dom"
2+
3+
interface PortalProps {
4+
style?: React.CSSProperties
5+
}
6+
7+
export function Portal(props: React.PropsWithChildren<PortalProps>) {
8+
return createPortal(
9+
<div data-mav-portal="" style={props.style ?? undefined}>
10+
{props.children}
11+
</div>,
12+
document.body
13+
)
14+
}

packages/ui/components/layouts/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ export * from "./Group/Group"
44
export * from "./Group/GroupContainer"
55
export * from "./MarginGutter"
66

7+
export * from "./Portal"
8+
79
export type * from "./Masthead/Masthead.types"

0 commit comments

Comments
 (0)