Skip to content

Commit b566909

Browse files
committed
Add docs for renderer children prop
1 parent 2c904cb commit b566909

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const schemaRenderer = [
1212
component: 'form-template',
1313
linkText: 'Form template',
1414
},
15+
{
16+
component: 'children',
17+
linkText: 'Children',
18+
},
1519
{
1620
subHeader: true,
1721
title: 'Form components',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import DocPage from '@docs/doc-page';
2+
3+
<DocPage>
4+
5+
# Children
6+
7+
[A prop](/components/renderer#children) to customize the form layout. Children render function receives the same props as `FormTemplate`:&nbsp;`formFields` and `schema`.
8+
9+
## Props
10+
11+
### formFields
12+
13+
*node*
14+
15+
Rendered fields of the form.
16+
17+
### schema
18+
19+
*object*
20+
21+
[Schema](/components/renderer#schema) from renderer. You can use it to extract a form title, description, or whatever you need.
22+
23+
## Children node minimal example
24+
25+
Check the [Form template documentation](/components/form-template) for detailed example.
26+
27+
```jsx
28+
const CustomTemplate = ({hideButtons, formFields, schema}) => {
29+
const { handleSubmit } = useFormApi();
30+
return (
31+
<form onSubmit={handleSubmit}>
32+
{ schema.title }
33+
{ formFields }
34+
{!hideButtons && (
35+
<button type="submit">Submit</button>
36+
)}
37+
</form>
38+
)
39+
}
40+
41+
const MyForm = (props) => {
42+
return (
43+
<FormRenderer
44+
componentMapper={simpleComponentMapper}
45+
onSubmit={handleFormSubmit}
46+
schema={formSchema}
47+
subscription={{values: true}}
48+
clearOnUnmount
49+
>
50+
<CustomTemplate hideButtons />
51+
</FormRenderer>
52+
)
53+
}
54+
```
55+
56+
## Children render function
57+
58+
Check the [Form template documentation](/components/form-template) for detailed example.
59+
60+
```jsx
61+
<FormRenderer
62+
componentMapper={simpleComponentMapper}
63+
onSubmit={handleFormSubmit}
64+
schema={formSchema}
65+
subscription={{values: true}}
66+
clearOnUnmount
67+
>
68+
{({formFields, schema}) => (
69+
{/** Template implementation */}
70+
)}
71+
</FormRenderer>
72+
```
73+
74+
</DocPage>

packages/react-renderer-demo/src/pages/components/renderer.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ You can use [globally defined attributes](/mappers/global-component-props).
3535

3636
*Component*
3737

38+
**Note** You have to pass at least one of `FormTemplate` or a `children` render function to render the fields.
39+
3840
Components which defines a template of the form. This component receives two props from the renderer: `formFields` and `schema`. `formFields` is the content of the form. You should wrap this content into your `<form>` component and add form buttons.
3941

4042
[Read more](/components/form-template).
4143

4244
---
4345

46+
### children
47+
48+
**Note** You have to pass at least one of `FormTemplate` or a `children` render function to render the fields.
49+
50+
*function*
51+
52+
Children render function. It serves the same purpose as `FormTemplate` prop. [Read more](/components/children).
53+
54+
---
55+
4456
### onSubmit
4557

4658
*(values, [formApi](/hooks/use-form-api)) => void*

0 commit comments

Comments
 (0)