Skip to content

Commit ee6a1c7

Browse files
committed
Added sub-form.js
1 parent a88bdf5 commit ee6a1c7

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

packages/ant-component-mapper/src/files/component-mapper.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { componentTypes } from '@data-driven-forms/react-form-renderer';
32
import Tabs from './tabs';
43
import PlainText from './plain-text';
@@ -10,14 +9,26 @@ import TimePicker from './time-picker';
109
import Radio from './radio';
1110
import Switch from './switch';
1211
import Select from './select';
13-
export const components = {};
12+
import SubForm from './sub-form.js';
13+
export const components = {
14+
TextField,
15+
TextArea,
16+
Select,
17+
Checkbox,
18+
Radio,
19+
Switch,
20+
DatePicker,
21+
TimePicker,
22+
PlainText,
23+
SubForm
24+
};
1425

1526
const componentMapper = {
1627
[componentTypes.TEXT_FIELD]: TextField,
1728
[componentTypes.TEXTAREA]: TextArea,
1829
[componentTypes.SELECT]: Select,
1930
[componentTypes.CHECKBOX]: Checkbox,
20-
[componentTypes.SUB_FORM]: () => <div>sub form</div>,
31+
[componentTypes.SUB_FORM]: SubForm,
2132
[componentTypes.RADIO]: Radio,
2233
[componentTypes.TABS]: Tabs,
2334
[componentTypes.DATE_PICKER]: DatePicker,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Typography, Row, Col } from 'antd';
4+
5+
import { useFormApi } from '@data-driven-forms/react-form-renderer';
6+
7+
const { Title, Paragraph } = Typography;
8+
const SubForm = ({ fields, title, description, FormSpyProvider: _FormSpyProvider, validate: _validate, ...rest }) => {
9+
const { renderForm } = useFormApi();
10+
return (
11+
<div>
12+
{title && (
13+
<Row>
14+
<Col span={24}>
15+
<Title>{title}</Title>
16+
</Col>
17+
</Row>
18+
)}
19+
{description && (
20+
<Row>
21+
<Col span={24}>
22+
<Paragraph>{description}</Paragraph>
23+
</Col>
24+
</Row>
25+
)}
26+
<Row>
27+
<Col span={24}>{renderForm(fields)}</Col>
28+
</Row>
29+
</div>
30+
);
31+
};
32+
33+
SubForm.propTypes = {
34+
fields: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
35+
title: PropTypes.string,
36+
description: PropTypes.string,
37+
FormSpyProvider: PropTypes.any,
38+
validate: PropTypes.any
39+
};
40+
41+
export default SubForm;

0 commit comments

Comments
 (0)