forked from doczjs/docz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby-theme-docz): clean playground style (doczjs#1397)
* chore: clean playground style * Update index.js
1 parent
ab384ee
commit 251a1a5
Showing
4 changed files
with
88 additions
and
62 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
core/gatsby-theme-docz/src/components/Playground/IframeWrapper.js
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
core/gatsby-theme-docz/src/components/Playground/Wrapper.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** @jsx jsx */ | ||
import { useState } from 'react' | ||
import { jsx } from 'theme-ui' | ||
import { useConfig } from 'docz' | ||
import Iframe from 'react-frame-component' | ||
import ReactResizeDetector from 'react-resize-detector' | ||
|
||
import * as styles from './styles' | ||
|
||
const CLEAR_PADDING = `<style> body { padding: 0; margin: 0; } </style>` | ||
const INITIAL_IFRAME_CONTENT = `<!DOCTYPE html><html><head> ${CLEAR_PADDING} </head><body><div></div></body></html>` | ||
|
||
const IframeWrapper = ({ children, style }) => { | ||
const [containerHeight, setHeight] = useState() | ||
return ( | ||
<Iframe | ||
initialContent={INITIAL_IFRAME_CONTENT} | ||
sx={{ | ||
...styles.wrapper(), | ||
style, | ||
height: containerHeight, | ||
}} | ||
> | ||
{children} | ||
<ReactResizeDetector | ||
handleHeight | ||
onResize={({ height }) => { | ||
setHeight(height) | ||
}} | ||
/> | ||
</Iframe> | ||
) | ||
} | ||
|
||
const NormalWrapper = ({ children, style }) => { | ||
return ( | ||
<div | ||
sx={{ | ||
...styles.wrapper(), | ||
...style, | ||
}} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
export const Wrapper = ({ children, content, useScoping, showingCode }) => { | ||
const { | ||
themeConfig: { useScopingInPlayground }, | ||
} = useConfig() | ||
|
||
const Element = | ||
useScoping || useScopingInPlayground ? IframeWrapper : NormalWrapper | ||
|
||
return ( | ||
<Element style={styles.wrapperBorder(content, showingCode)}> | ||
{children} | ||
</Element> | ||
) | ||
} |
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
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