-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a component example that renders a live preview
- v1.97.5
- v1.97.4
- v1.97.3
- v1.97.2
- v1.97.1
- v1.97.0
- v1.96.6
- v1.96.5
- v1.96.4
- v1.96.3
- v1.96.2
- v1.96.1
- v1.96.0
- v1.95.2
- v1.95.1
- v1.95.0
- v1.94.0
- v1.93.3
- v1.93.2
- v1.93.1
- v1.93.0
- v1.92.3
- v1.92.2
- v1.92.1
- v1.92.0
- v1.91.2
- v1.91.1
- v1.91.0
- v1.90.0
- v1.89.3
- v1.89.2
- v1.89.1
- v1.89.0
- v1.88.5
- v1.88.4
- v1.88.3
- v1.88.2
- v1.88.1
- v1.88.0
- v1.87.2
- v1.87.1
- v1.87.0
- v1.86.2
- v1.86.1
- v1.86.0
- v1.85.0
- v1.84.1
- v1.84.0
- v1.83.0
- v1.82.3
- v1.82.2
- v1.82.1
- v1.82.0
- v1.81.3
- v1.81.2
- v1.81.1
- v1.81.0
- v1.80.0
- v1.79.0
- v1.78.0
- v1.77.0
- v1.76.3
- v1.76.2
- v1.76.1
- v1.76.0
- v1.75.0
- v1.74.0
- v1.73.0
- v1.72.1
- v1.72.0
- v1.71.2
- v1.71.1
- v1.71.0
- v1.70.0
- v1.69.2
- v1.69.1
- v1.69.0
- v1.68.3
- v1.68.2
- v1.68.1
- v1.68.0
- v1.67.5
- v1.67.4
- v1.67.3
- v1.67.2
- v1.67.1
- v1.67.0
- v1.66.1
- v1.66.0
- v1.65.0
- v1.64.0
- v1.63.0
- v1.62.0
- v1.61.0
- v1.60.0
- v1.59.2
- v1.59.1
- v1.59.0
- v1.58.0
- v1.57.2
- v1.57.1
- v1.57.0
- v1.56.0
- v1.55.0
- v1.54.0
- v1.53.1
- v1.53.0
- v1.52.3
- v1.52.2
- v1.52.1
- v1.52.0
- v1.51.0
- v1.50.2
- v1.50.1
- v1.50.0
- v1.49.0
- v1.48.1
- v1.48.0
- v1.47.3
- v1.47.2
- v1.47.1
- v1.47.0
- v1.46.0
- v1.45.0
- v1.44.3
- v1.44.2
- v1.44.1
- v1.44.0
- v1.43.0
- v1.42.3
- v1.42.2
- v1.42.1
- v1.42.0
- v1.41.0
- v1.40.2
- v1.40.1
- v1.40.0
- v1.39.0
- v1.38.0
- v1.37.0
- v1.36.0
- v1.35.7
- v1.35.6
- v1.35.5
- v1.35.4
- v1.35.3
- v1.35.2
- v1.35.1
- v1.35.0
- v1.34.0
- v1.33.0
- v1.32.1
- v1.32.0
- v1.31.8
- v1.31.7
- v1.31.6
- v1.31.5
- v1.31.4
- v1.31.3
- v1.31.2
- v1.31.1
- v1.31.0
- v1.30.1
- v1.30.0
- v1.29.1
- v1.29.0
- v1.28.1
- v1.28.0
- v1.27.1
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.0
- v1.23.0
- v1.22.0
- v1.21.2
- v1.21.1
- v1.21.0
- v1.20.5
- v1.20.4
- v1.20.3
- v1.20.2
- v1.20.1
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.1
- v1.17.0
- v1.16.0
- v1.15.3
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.2
- v1.14.1
- v1.14.0
- v1.13.11
- v1.13.10
- v1.13.9
- v1.13.8
- v1.13.7
- v1.13.6
- v1.13.5
- v1.13.4
- v1.13.3
- v1.13.2
- v1.13.1
- v1.13.0
- v1.12.5
- v1.12.4
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.6
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
1 parent
e190181
commit 7178aa5
Showing
3 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import formatCode from '../utils/formatCode'; | ||
import github from 'prism-react-renderer/themes/github'; | ||
import { LiveEditor, LiveError, LiveProvider, LivePreview } from 'react-live'; | ||
|
||
const TRAILING_SEMI = /;\s*$/; | ||
|
||
const ComponentExample = ({ className, example }) => ( | ||
<div className={className}> | ||
<h3>{example.label}</h3> | ||
<LiveProvider | ||
scope={window.__NR1_SDK__.default} | ||
code={formatCode(example.sourceCode).replace(TRAILING_SEMI, '')} | ||
theme={github} | ||
> | ||
<LivePreview /> | ||
<LiveEditor /> | ||
<LiveError /> | ||
</LiveProvider> | ||
</div> | ||
); | ||
|
||
ComponentExample.propTypes = { | ||
className: PropTypes.string, | ||
example: PropTypes.shape({ | ||
label: PropTypes.string.isRequired, | ||
sourceCode: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default ComponentExample; |
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,15 @@ | ||
import prettier from 'prettier/standalone'; | ||
import parserBabel from 'prettier/parser-babel'; | ||
|
||
const formatCode = (code, formatOptions = {}) => | ||
prettier.format(code, { | ||
trailingComma: 'es5', | ||
printWidth: 80, | ||
tabWidth: 2, | ||
semi: true, | ||
singleQuote: true, | ||
...formatOptions, | ||
plugins: [parserBabel], | ||
}); | ||
|
||
export default formatCode; |