|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import config from '@automattic/calypso-config'; |
|
|
import { useLayoutEffect, useState } from 'react'; |
|
|
import ReactDOM from 'react-dom'; |
|
|
import useWPAdminTheme from 'calypso/my-sites/stats/hooks/use-wp-admin-theme'; |
|
|
import { isJetpackSite } from 'calypso/state/sites/selectors'; |
|
|
import type { FunctionComponent, ReactNode } from 'react'; |
|
|
|
|
|
|
|
|
const RootChild: FunctionComponent< { children: ReactNode } > = ( { children } ) => { |
|
|
const [ containerEl, setContainerEl ] = useState< HTMLDivElement | null >( null ); |
|
|
|
|
|
const state = config( 'intial_state' ); |
|
|
const siteId = config( 'blog_id' ) as number; |
|
|
const isSiteJetpack = isJetpackSite( state, siteId, { treatAtomicAsJetpackSite: true } ); |
|
|
const customTheme = useWPAdminTheme( isSiteJetpack ); |
|
|
|
|
|
useLayoutEffect( () => { |
|
|
const element = document.createElement( 'div' ); |
|
|
|
|
|
element.className = `color-scheme ${ customTheme }`; |
|
|
document.body.appendChild( element ); |
|
|
setContainerEl( element ); |
|
|
|
|
|
return () => { |
|
|
document.body.removeChild( element ); |
|
|
}; |
|
|
}, [ customTheme ] ); |
|
|
|
|
|
if ( ! containerEl ) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
return ReactDOM.createPortal( children, containerEl ); |
|
|
}; |
|
|
|
|
|
export default RootChild; |
|
|
|