refactor: mobile modals (#2173)

This commit is contained in:
Aman Harwara
2023-01-24 19:26:20 +05:30
committed by GitHub
parent 6af95ddfeb
commit 42db3592b6
55 changed files with 1582 additions and 1033 deletions

View File

@@ -3,11 +3,12 @@ import { createPortal } from 'react-dom'
type Props = {
children: ReactNode
disabled?: boolean
}
const randomPortalId = () => Math.random()
const Portal = ({ children }: Props) => {
const Portal = ({ children, disabled = false }: Props) => {
const [container, setContainer] = useState<HTMLElement>()
useEffect(() => {
@@ -18,6 +19,10 @@ const Portal = ({ children }: Props) => {
return () => container.remove()
}, [])
if (disabled) {
return <>{children}</>
}
return container ? createPortal(children, container) : null
}