Skip to content

Commit 7e8a096

Browse files
committed
Updated docs example for component mapping.
1 parent d0ff088 commit 7e8a096

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

packages/react-renderer-demo/src/app/pages/renderer/component-mapping.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import RawComponent from '@docs/raw-component';
1+
import CodeExample from '../../src/components/code-example'
22
import Grid from '@material-ui/core/Grid'
33

4-
import '@docs/doc-components/component-mapper/form-fields-mapper-docs.css';
4+
import '@docs/examples/components/component-mapper/form-fields-mapper-docs.css';
55
import ListOfContents from '../../src/helpers/list-of-contents';
66

77
<Grid container item>
@@ -75,7 +75,12 @@ Below, you can see an basic implementation of custom component mapper:
7575
<br />
7676

7777

78-
<RawComponent source="component-mapper/form-fields-mapper" />
78+
<CodeExample
79+
source="components/component-mapper/form-fields-mapper"
80+
mode="preview"
81+
additionalSources="components/component-mapper/form-fields-mapper-docs.css"
82+
/>
83+
7984
</Grid>
8085
<Grid item xs={false} md={2}>
8186
<ListOfContents file="renderer/component-mapping" />

packages/react-renderer-demo/src/app/src/components/code-example.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,17 @@ const CodeExample = ({ source, mode, mapper, additionalSources }) => {
148148
let Component;
149149
if (mode === 'preview') {
150150
Component = req(`./${source}.js`).default;
151-
const sourceFiles = additionalSources.split(',').reduce(
152-
(acc, curr) => ({
153-
...acc,
154-
[`src/${curr.split('/').pop()}`]: {
155-
content: curr.match(/\.css$/) ? reqCss(`./${curr}`).default : reqSource(`./${curr}`).default
156-
}
157-
}),
158-
{}
159-
);
151+
const sourceFiles = additionalSources
152+
? additionalSources.split(',').reduce(
153+
(acc, curr) => ({
154+
...acc,
155+
[`src/${curr.split('/').pop()}`]: {
156+
content: curr.match(/\.css$/) ? reqCss(`./${curr}`).default : reqSource(`./${curr}`).default
157+
}
158+
}),
159+
{}
160+
)
161+
: {};
160162

161163
return (
162164
<Grid container spacing={0} className="DocRawComponent">
@@ -181,13 +183,12 @@ const CodeExample = ({ source, mode, mapper, additionalSources }) => {
181183
<form action="https://codesandbox.io/api/v1/sandboxes/define" method="POST" target="_blank">
182184
<input type="hidden" name="parameters" value={getPayload(mapper, codeSource, sourceFiles)} />
183185
<Tooltip title="Edit in codesandbox">
184-
<IconButton disableFocusRipple type="submit">
186+
<IconButton disableFocusRipple type="submit" onClick={(event) => event.stopPropagation()}>
185187
<CodesandboxIcon />
186188
</IconButton>
187189
</Tooltip>
188190
</form>
189191
<Link
190-
component="button"
191192
href={`https://github.com/data-driven-forms/react-forms/tree/master/packages/react-renderer-demo/src/app/examples/${source}.js`}
192193
target="_blank"
193194
rel="noopener noreferrer"
@@ -248,8 +249,7 @@ CodeExample.propTypes = {
248249

249250
CodeExample.defaultProps = {
250251
mode: 'code',
251-
mapper: 'pf4',
252-
additionalSources: ''
252+
mapper: 'pf4'
253253
};
254254

255255
export default CodeExample;

0 commit comments

Comments
 (0)