Created
October 4, 2019 14:30
-
-
Save lmosele/bf77242c0f69e5fd8b90e17f347dab66 to your computer and use it in GitHub Desktop.
Styled Components with React Frame
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"; // "react": "^16.8.6", | |
import Frame, { FrameContextConsumer } from "react-frame-component"; // "react-frame-component": "^4.1.0", | |
import { StyleSheetManager, withTheme, ThemeProvider } from "styled-components"; // "styled-components": "^3.3.3", | |
export default withTheme(props => { | |
const { theme, style = {}, children, ...rest } = props; | |
return ( | |
<Frame | |
style={{ | |
display: "block", | |
overflow: "scroll", | |
border: 0, | |
...style | |
}} | |
{...rest} | |
> | |
<FrameContextConsumer> | |
{frameContext => ( | |
<StyleSheetManager target={frameContext.document.head}> | |
{theme ? ( | |
<ThemeProvider theme={theme}>{children}</ThemeProvider> | |
) : ( | |
children | |
)} | |
</StyleSheetManager> | |
)} | |
</FrameContextConsumer> | |
</Frame> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment