Skip to content

Commit dd01422

Browse files
authored
Merge pull request #905 from data-driven-forms/add-docs-custom-examples-section
Add custom components docs section.
2 parents 028a625 + 61d9ed0 commit dd01422

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const customExamplesSchema = [
2+
{
3+
component: 'sample-example',
4+
linkText: 'Sample example'
5+
}
6+
];
7+
8+
export default customExamplesSchema;

packages/react-renderer-demo/src/components/navigation/schemas/schema.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import schemaRenderer from './renderer.schema';
33
import schemaNav from './schema.schema';
44
import schemaHooks from './hooks.schema';
55
import mappersSchema from './mappers.schema';
6+
import customExamplesSchema from './custom-examples.schema';
67

78
const schema = [
89
{
@@ -57,6 +58,12 @@ const schema = [
5758
linkText: 'Optimization',
5859
link: 'optimization'
5960
},
61+
{
62+
title: 'Examples',
63+
link: 'examples',
64+
noRoute: true,
65+
fields: customExamplesSchema
66+
},
6067
{
6168
linkText: 'Releases',
6269
link: 'releases'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import FormRenderer from '@data-driven-forms/react-form-renderer/dist/cjs/form-renderer';
3+
import useFieldApi from '@data-driven-forms/react-form-renderer/dist/cjs/use-field-api';
4+
import validatorTypes from '@data-driven-forms/react-form-renderer/dist/cjs/validator-types';
5+
6+
import FormTemplate from '@data-driven-forms/mui-component-mapper/dist/cjs/form-template';
7+
8+
const CustomComponent = (props) => {
9+
const { input, meta, label, ...rest } = useFieldApi(props);
10+
return (
11+
<div style={{ display: 'flex', flexDirection: 'column', padding: 8 }}>
12+
<label style={{ marginBottom: 6 }} htmlFor={input.name}>
13+
{label}
14+
</label>
15+
<input {...input} {...rest} />
16+
{meta.error && <p>{meta.error}</p>}
17+
</div>
18+
);
19+
};
20+
21+
const schema = {
22+
fields: [
23+
{
24+
component: 'custom-component',
25+
name: 'some-name',
26+
label: 'Custom component prop',
27+
validate: [{ type: validatorTypes.REQUIRED, message: 'I am a required field' }]
28+
}
29+
]
30+
};
31+
32+
const SampleExample = () => {
33+
return (
34+
<FormRenderer schema={schema} componentMapper={{ 'custom-component': CustomComponent }} FormTemplate={FormTemplate} onSubmit={console.log} />
35+
);
36+
};
37+
38+
SampleExample.displayName = 'SampleExample';
39+
40+
export default SampleExample;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import DocPage from '@docs/doc-page';
2+
import CodeExample from '@docs/code-example';
3+
4+
<DocPage>
5+
6+
7+
# Sample example
8+
9+
## Use markdown syntax to write text
10+
11+
## What to include?
12+
- description of the component
13+
- what issue it can help solve
14+
- include component preview in a form
15+
16+
## Preview
17+
18+
<CodeExample source="components/examples/sample-example" mode="preview" />
19+
20+
</DocPage>

0 commit comments

Comments
 (0)