mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
33 lines
679 B
TypeScript
33 lines
679 B
TypeScript
import * as React from "react";
|
|
|
|
import * as PortalPrimitive from "@radix-ui/react-portal";
|
|
|
|
const Portal = ({
|
|
containerId,
|
|
className,
|
|
children,
|
|
}: {
|
|
containerId?: string | null;
|
|
children: React.ReactElement;
|
|
className?: string;
|
|
}) => {
|
|
const [mounted, setMounted] = React.useState(false);
|
|
React.useEffect(() => setMounted(true), []);
|
|
|
|
return (
|
|
<PortalPrimitive.Root
|
|
className={className}
|
|
container={
|
|
containerId && mounted
|
|
? document.getElementById(containerId)
|
|
: undefined
|
|
}
|
|
>
|
|
{children}
|
|
</PortalPrimitive.Root>
|
|
);
|
|
};
|
|
Portal.displayName = PortalPrimitive.Root.displayName;
|
|
|
|
export { Portal };
|