-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-theme-docz): add optional iframe for preview and editor #1305
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
828362f
feat(gatsby-theme-docz): add optional iframe for preview and editor
rakannimer dd4044d
chore: 0 -> false
rakannimer ebd5a52
chore(gatsby-theme-docz): remove custom font
rakannimer 0ee5167
chore: useIframe -> useScoping
rakannimer 797afe2
feat(gatsby-theme-docz): add useScopingInPlayground in theme config
rakannimer a2ab064
docs: add example with styled components and scoping (#1306)
lkuechler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
core/gatsby-theme-docz/src/components/Playground/IframeWrapper.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,23 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui' | ||
import Iframe from 'react-frame-component' | ||
|
||
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>` | ||
|
||
export const IframeWrapper = ({ children, height, style = {} }) => { | ||
return ( | ||
<Iframe | ||
initialContent={INITIAL_IFRAME_CONTENT} | ||
sx={{ | ||
...styles.previewInner(), | ||
height, | ||
...style, | ||
}} | ||
> | ||
{children} | ||
</Iframe> | ||
) | ||
} |
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
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,2 @@ | ||
.docz | ||
node_modules |
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,48 @@ | ||
# Docz Styled Components Example | ||
|
||
## Using `create-docz-app` | ||
|
||
```sh | ||
npx create-docz-app docz-app-styled-docz --example with-styled-components-and-scoping | ||
# or | ||
yarn create docz-app docz-app-styled-docz --example with-styled-components-and-scoping | ||
``` | ||
|
||
## Download manually | ||
|
||
```sh | ||
curl https://codeload.github.com/doczjs/docz/tar.gz/master | tar -xz --strip=2 docz-master/examples/with-styled-components-and-scoping | ||
mv with-styled-components-and-scoping docz-example-styled-docz | ||
``` | ||
|
||
## Setup | ||
|
||
```sh | ||
yarn # npm i | ||
``` | ||
|
||
## Run | ||
|
||
```sh | ||
yarn dev # npm run dev | ||
``` | ||
|
||
## Build | ||
|
||
```sh | ||
yarn build # npm run build | ||
``` | ||
|
||
## Serve built app | ||
|
||
```sh | ||
yarn serve # npm run serve | ||
``` | ||
|
||
## Deploy | ||
|
||
```sh | ||
yarn deploy | ||
``` | ||
|
||
Note that by default `docz` generates the output site in `.docz/public` to change that add a `dest` field to your `doczrc.js` with the path you want to generate the code in. |
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,5 @@ | ||
export default { | ||
themeConfig: { | ||
useScopingInPlayground: true, | ||
}, | ||
} |
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,22 @@ | ||
{ | ||
"private": true, | ||
"name": "docz-example-styled-components-with-scoping", | ||
"version": "2.0.0-rc.41", | ||
"license": "MIT", | ||
"files": [ | ||
"src/", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"dev": "docz dev", | ||
"build": "docz build" | ||
}, | ||
"dependencies": { | ||
"docz": "latest", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-frame-component": "^4.1.1", | ||
"styled-components": "^4.3.2" | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/with-styled-components-and-scoping/src/components/Alert.jsx
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,28 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import t from 'prop-types' | ||
|
||
const kinds = { | ||
info: '#5352ED', | ||
positive: '#2ED573', | ||
negative: '#FF4757', | ||
warning: '#FFA502', | ||
} | ||
|
||
const AlertStyled = styled('div')` | ||
padding: 15px 20px; | ||
background: white; | ||
border-radius: 3px; | ||
color: white; | ||
background: ${({ kind = 'info' }) => kinds[kind]}; | ||
` | ||
|
||
export const Alert = props => <AlertStyled {...props} /> | ||
|
||
Alert.propTypes = { | ||
kind: t.oneOf(['info', 'positive', 'negative', 'warning']), | ||
} | ||
|
||
Alert.defaultProps = { | ||
kind: 'info', | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/with-styled-components-and-scoping/src/components/Alert.mdx
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,28 @@ | ||
--- | ||
name: Alert | ||
menu: Components | ||
--- | ||
|
||
import { Playground, Props } from 'docz' | ||
import { Alert } from './Alert' | ||
|
||
# Alert | ||
|
||
## Properties | ||
|
||
<Props of={Alert} /> | ||
|
||
## Basic usage | ||
|
||
<Playground> | ||
<Alert>Some message</Alert> | ||
</Playground> | ||
|
||
## Using different kinds | ||
|
||
<Playground> | ||
<Alert kind="info">Some message</Alert> | ||
<Alert kind="positive">Some message</Alert> | ||
<Alert kind="negative">Some message</Alert> | ||
<Alert kind="warning">Some message</Alert> | ||
</Playground> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am i correct in the assumption that this was done to solve this issue #1271 ?
Because now that you are wrapping the component in a iframe the encapsulation of the editor should not be needed any more. Am i missing something? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that's exactly why ! Initially wanted to only wrap the preview.
I'm wrapping the preview and the editor each in an iframe, not wrapping the whole Playground with an iframe so it should be necessary if I'm not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue was that the css from the component inside the preview was styling the code area of the preview. This should not be possible any more after the component preview is wrapped in a iframe.