Forked from mizchi/chakra-ui-under-shadow-root.ts
Last active
October 23, 2022 16:55
-
-
Save shunkakinoki/e7268b1be97d3ce837311fb6c46cdc2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import { ChakraProvider, DarkMode, Button, LightMode } from "@chakra-ui/react"; | |
import type { ApplicationProps } from "../../shell/src/types"; | |
import { CacheProvider } from "@emotion/react"; | |
import createCache from "@emotion/cache"; | |
function Root(props: ApplicationProps) { | |
return ( | |
<> | |
<LightMode> | |
<Button>In Light Mode</Button> | |
</LightMode> | |
<DarkMode> | |
<Button>In Dark Mode(Broken)</Button> | |
</DarkMode> | |
</> | |
); | |
} | |
const run = (props: ApplicationProps) => { | |
const root = props.getRoot(); | |
const shadowRoot = root.attachShadow({ mode: "open" }); | |
const myCache = createCache({ | |
// @ts-ignore | |
container: shadowRoot, | |
key: "c", | |
}); | |
const rootElement = document.createElement("main"); | |
shadowRoot.appendChild(rootElement); | |
ReactDOM.render( | |
<React.StrictMode> | |
<CacheProvider value={myCache}> | |
<ChakraProvider> | |
<DarkMode> | |
<Root {...props} /> | |
</DarkMode> | |
</ChakraProvider> | |
</CacheProvider> | |
</React.StrictMode>, | |
rootElement | |
); | |
return () => { | |
ReactDOM.unmountComponentAtNode(root); | |
}; | |
}; | |
export default run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment