-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(Examples): use React Source Render
- Loading branch information
1 parent
07c7143
commit 21ad4f7
Showing
6 changed files
with
100 additions
and
149 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
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
64 changes: 64 additions & 0 deletions
64
docs/src/components/ComponentDoc/ComponentExample/ComponentExampleRenderSource.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,64 @@ | ||
import faker from 'faker' | ||
import _ from 'lodash' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import SourceRender from 'react-source-render' | ||
import * as SUIR from 'semantic-ui-react' | ||
|
||
import { updateForKeys } from 'docs/src/hoc' | ||
|
||
const babelConfig = { | ||
presets: [ | ||
[ | ||
'env', | ||
{ | ||
targets: { | ||
browsers: ['last 4 versions', 'not dead'], | ||
}, | ||
}, | ||
], | ||
['stage-1', { decoratorsLegacy: true }], | ||
], | ||
} | ||
|
||
// if (module === 'COMMON') { | ||
// const componentPath = examplePath | ||
// .split(__PATH_SEP__) | ||
// .splice(0, 2) | ||
// .join(__PATH_SEP__) | ||
// COMMON = require(`docs/src/examples/${componentPath}/common`) | ||
// } else if (module === 'WIREFRAME') { | ||
// WIREFRAME = require('docs/src/examples/behaviors/Visibility/Wireframe').default | ||
|
||
const externals = { | ||
faker, | ||
lodash: _, | ||
react: React, | ||
'semantic-ui-react': SUIR, | ||
} | ||
|
||
const resolver = (importPath, { examplePath }) => { | ||
if (externals[importPath]) return externals[importPath] | ||
|
||
throw new Error('UNHANDLED IMPORT') | ||
} | ||
|
||
const ComponentExampleRenderSource = ({ examplePath, onError, onSuccess, sourceCode }) => ( | ||
<SourceRender | ||
babelConfig={babelConfig} | ||
examplePath={examplePath} | ||
onError={onError} | ||
onSuccess={onSuccess} | ||
resolver={resolver} | ||
source={sourceCode} | ||
/> | ||
) | ||
|
||
ComponentExampleRenderSource.propTypes = { | ||
examplePath: PropTypes.string.isRequired, | ||
onError: PropTypes.func.isRequired, | ||
onSuccess: PropTypes.func.isRequired, | ||
sourceCode: PropTypes.string.isRequired, | ||
} | ||
|
||
export default updateForKeys(['sourceCode'])(ComponentExampleRenderSource) |
113 changes: 0 additions & 113 deletions
113
docs/src/components/ComponentDoc/ComponentExample/renderExampleSourceCode.js
This file was deleted.
Oops, something went wrong.
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