-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-theme-docz): add optional iframe for preview and ed… (#1305)
* feat(gatsby-theme-docz): add optional iframe for preview and editor * feat(gatsby-theme-docz): add useScopingInPlayground in theme config * docs: add example with styled components and scoping (#1306) - @lkuechler
- Loading branch information
1 parent
8d1ae9e
commit 9c5082e
Showing
15 changed files
with
449 additions
and
41 deletions.
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.