Skip to content

Commit cafac5e

Browse files
committed
Add example for one-row-layout
1 parent 6548c1a commit cafac5e

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const customExamplesSchema = [
22
{
33
component: 'sample-example',
44
linkText: 'Sample example'
5+
},
6+
{
7+
component: 'one-row-layout',
8+
linkText: 'One row layout'
59
}
610
];
711

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import FormRenderer from '@data-driven-forms/react-form-renderer/form-renderer';
3+
import componentTypes from '@data-driven-forms/react-form-renderer/component-types';
4+
import FormTemplate from '@data-driven-forms/mui-component-mapper/form-template';
5+
import TextField from '@data-driven-forms/mui-component-mapper/text-field';
6+
7+
const schema = {
8+
fields: [
9+
{
10+
name: 'first-name',
11+
label: 'First name',
12+
component: componentTypes.TEXT_FIELD,
13+
FormFieldGridProps: { xs: 6 },
14+
},
15+
{
16+
name: 'last-name',
17+
label: 'Last name',
18+
component: componentTypes.TEXT_FIELD,
19+
FormFieldGridProps: { xs: 6 },
20+
},
21+
]
22+
};
23+
24+
const componentMapper = {
25+
[componentTypes.TEXT_FIELD]: TextField
26+
};
27+
28+
const OneRowLayout = () =>
29+
<FormRenderer
30+
FormTemplate={FormTemplate}
31+
componentMapper={componentMapper}
32+
schema={schema}
33+
onSubmit={console.log}
34+
/>;
35+
36+
export default OneRowLayout;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import DocPage from '@docs/doc-page';
2+
import CodeExample from '@docs/code-example';
3+
4+
<DocPage>
5+
6+
# One row layout
7+
8+
This example show how to place two fields in the same row. **Only for MUI mapper**.
9+
Other mappers can have similar solutions.
10+
11+
---
12+
13+
Each MUI component mapper component is wrapped in [Grid](https://material-ui.com/components/grid/#grid) component by default and this component is configurable via `FormFieldGridProps` object you can pass via schema - this object is of the same shape as props for the Grid component.
14+
15+
```jsx
16+
{
17+
name: "first-name",
18+
label: "First name",
19+
component: componentTypes.TEXT_FIELD,
20+
FormFieldGridProps: { xs: 6 },
21+
isRequired: true,
22+
validate: [
23+
{
24+
type: validatorTypes.REQUIRED
25+
}
26+
]
27+
}
28+
```
29+
30+
Please, don't forget that `<Grid item/>` has to rendered inside `<Grid container/>`. Components that contain nested fields in the MUI mapper are all using the Container component by default.
31+
32+
## Preview
33+
34+
<CodeExample source="components/examples/one-row-layout" mode="preview" />
35+
36+
</DocPage>

packages/react-renderer-demo/src/pages/schema/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Other attribues, such as title or description, can be used in [form templates](/
4444

4545
*string*
4646

47-
`component` is a string value representing used component. Available options depends on the component mapper. Data Driven Forms automatically checks if the component is available, if not, it shows an error message. You use [componentTypes](/schema/constants#componenttypes) to prevent typos.
47+
`component` is a string value representing used component. Available options depends on the component mapper. Data Driven Forms automatically checks if the component is available, if not, it shows an error message. You can use [componentTypes](/schema/constants#componenttypes) to prevent typos. This attribute is not required for fields of these components: `wizard`, `field-array` and `tabs` as these fields include only special components with no implementation.
4848

4949
---
5050

0 commit comments

Comments
 (0)