feat: responsive popovers & menus (#1323)

This commit is contained in:
Aman Harwara
2022-07-21 02:20:14 +05:30
committed by GitHub
parent baf7fb0019
commit 2573407851
44 changed files with 1308 additions and 1415 deletions

View File

@@ -0,0 +1,24 @@
import { ReactNode, useState, useEffect } from 'react'
import { createPortal } from 'react-dom'
type Props = {
children: ReactNode
}
const randomPortalId = () => Math.random()
const Portal = ({ children }: Props) => {
const [container, setContainer] = useState<HTMLElement>()
useEffect(() => {
const container = document.createElement('div')
container.id = `react-portal-${randomPortalId()}`
document.body.append(container)
setContainer(container)
return () => container.remove()
}, [])
return container ? createPortal(children, container) : null
}
export default Portal