import * as React from 'react';
import {useContext} from 'react';
import {createPortal} from 'react-dom';
import ErrorBoundary from './ErrorBoundary';
import {StoreContext} from './context';
import ThemeProvider from './ThemeProvider';
export type Props = {portalContainer?: Element, ...};
export default function portaledContent(
Component: component(...props: any),
): component(...props: any) {
return function PortaledContent({portalContainer, ...rest}: Props) {
const store = useContext(StoreContext);
let children = (
<ErrorBoundary store={store}>
<Component {...rest} />
</ErrorBoundary>
);
if (portalContainer != null) {
children = (
<ThemeProvider>
<div
data-react-devtools-portal-root={true}
style={{
width: '100vw',
height: '100vh',
containerName: 'devtools',
containerType: 'inline-size',
}}>
{children}
</div>
</ThemeProvider>
);
}
return portalContainer != null
? createPortal(children, portalContainer)
: children;
};
}