Skip to content

Commit 56cfef8

Browse files
authored
Merge pull request #157 from rvsia/subform-additionalprops
fix(subform): allow to receive other props
2 parents 6320e3c + afc6c93 commit 56cfef8

File tree

5 files changed

+87
-41
lines changed

5 files changed

+87
-41
lines changed

packages/mui-component-mapper/src/form-fields/sub-form.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ const SubForm = ({
88
fields,
99
title,
1010
description,
11+
FieldProvider: _FieldProvider,
12+
validate: _validate,
13+
...rest
1114
}) => (
12-
<Grid item xs={ 12 } container style={{ paddingRight: 0, paddingLeft: 0 }}>
15+
<Grid item xs={ 12 } container style={{ paddingRight: 0, paddingLeft: 0 }} { ...rest }>
1316
{ title && <Grid item xs={ 12 }><Typography variant="h5">{ title }</Typography></Grid> }
1417
{ description && <Grid item xs={ 12 }><Typography paragraph>{ description }</Typography></Grid> }
1518
<Grid item xs={ 12 } container>
@@ -26,6 +29,8 @@ SubForm.propTypes = {
2629
]).isRequired,
2730
title: PropTypes.string,
2831
description: PropTypes.string,
32+
FieldProvider: PropTypes.any,
33+
validate: PropTypes.any,
2934
};
3035

3136
export default SubForm;
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import React, { Fragment } from 'react';
1+
import React from 'react';
22
import PropTypes from 'prop-types';
33

44
const SubForm = ({
55
formOptions,
66
fields,
77
title,
88
description,
9+
FieldProvider: _FieldProvider,
10+
validate: _validate,
11+
...rest
912
}) => (
10-
<Fragment>
13+
<div { ...rest }>
1114
{ title && <h3>{ title }</h3> }
1215
{ description && <p>{ description }</p> }
1316
{ formOptions.renderForm(fields, formOptions) }
14-
</Fragment>
17+
</div>
1518
);
1619

1720
SubForm.propTypes = {
@@ -22,6 +25,8 @@ SubForm.propTypes = {
2225
]).isRequired,
2326
title: PropTypes.string,
2427
description: PropTypes.string,
28+
FieldProvider: PropTypes.any,
29+
validate: PropTypes.any,
2530
};
2631

2732
export default SubForm;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`<SubForm /> should render sub form with description 1`] = `
4-
<Fragment>
4+
<div>
55
<p>
66
Bar
77
</p>
88
<div>
99
Form item
1010
</div>
11-
</Fragment>
11+
</div>
1212
`;
1313

1414
exports[`<SubForm /> should render sub form with title 1`] = `
15-
<Fragment>
15+
<div>
1616
<h3>
1717
Foo
1818
</h3>
1919
<div>
2020
Form item
2121
</div>
22-
</Fragment>
22+
</div>
2323
`;
2424

2525
exports[`<SubForm /> should render sub form with title and description 1`] = `
26-
<Fragment>
26+
<div>
2727
<h3>
2828
Foo
2929
</h3>
@@ -33,5 +33,5 @@ exports[`<SubForm /> should render sub form with title and description 1`] = `
3333
<div>
3434
Form item
3535
</div>
36-
</Fragment>
36+
</div>
3737
`;
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { Title } from '@patternfly/react-core';
4-
import { TextContent, Text, TextVariants } from '@patternfly/react-core';
4+
import { TextContent, Text, TextVariants, Grid, GridItem } from '@patternfly/react-core';
55

6-
const SubForm = ({ fields, title, description, formOptions }) => (
7-
<React.Fragment>
8-
{ title && <Title size="xl">{ title }</Title> }
9-
{ description && <TextContent><Text component={ TextVariants.small } style={{ marginBottom: 0 }}>{ description }</Text></TextContent> }
6+
const SubForm = ({
7+
fields,
8+
title,
9+
description,
10+
formOptions,
11+
FieldProvider: _FieldProvider,
12+
validate: _validate,
13+
...rest
14+
}) => (
15+
<Grid gutter="md" { ...rest }>
16+
{ title && <GridItem sm={ 12 }><Title size="xl">{ title }</Title></GridItem> }
17+
{ description && <GridItem sm={ 12 }>
18+
<TextContent>
19+
<Text component={ TextVariants.small } style={{ marginBottom: 0 }}>{ description }
20+
</Text>
21+
</TextContent>
22+
</GridItem> }
1023
{ formOptions.renderForm(fields, formOptions) }
11-
</React.Fragment>
24+
</Grid>
1225
);
1326

1427
SubForm.propTypes = {
@@ -19,6 +32,8 @@ SubForm.propTypes = {
1932
name: PropTypes.string,
2033
title: PropTypes.string,
2134
description: PropTypes.string,
35+
FieldProvider: PropTypes.any,
36+
validate: PropTypes.any,
2237
};
2338

2439
export default SubForm;
Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,68 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`SubForm component should render SubForm correctly 1`] = `
4-
<Fragment>
5-
<Title
6-
size="xl"
4+
<Grid
5+
gutter="md"
6+
name="cosiName"
7+
>
8+
<GridItem
9+
sm={12}
710
>
8-
cosiTitle
9-
</Title>
11+
<Title
12+
size="xl"
13+
>
14+
cosiTitle
15+
</Title>
16+
</GridItem>
1017
<div>
1118
Here would be form
1219
</div>
13-
</Fragment>
20+
</Grid>
1421
`;
1522

1623
exports[`SubForm component should render SubForm with description correctly 1`] = `
17-
<Fragment>
18-
<Title
19-
size="xl"
24+
<Grid
25+
gutter="md"
26+
name="cosiName"
27+
>
28+
<GridItem
29+
sm={12}
2030
>
21-
cosiTitle
22-
</Title>
23-
<TextContent>
24-
<Text
25-
component="small"
26-
style={
27-
Object {
28-
"marginBottom": 0,
29-
}
30-
}
31+
<Title
32+
size="xl"
3133
>
32-
description here!
33-
</Text>
34-
</TextContent>
34+
cosiTitle
35+
</Title>
36+
</GridItem>
37+
<GridItem
38+
sm={12}
39+
>
40+
<TextContent>
41+
<Text
42+
component="small"
43+
style={
44+
Object {
45+
"marginBottom": 0,
46+
}
47+
}
48+
>
49+
description here!
50+
</Text>
51+
</TextContent>
52+
</GridItem>
3553
<div>
3654
Here would be form
3755
</div>
38-
</Fragment>
56+
</Grid>
3957
`;
4058

4159
exports[`SubForm component should render SubForm without title correctly 1`] = `
42-
<Fragment>
60+
<Grid
61+
gutter="md"
62+
name="cosiName"
63+
>
4364
<div>
4465
Here would be form
4566
</div>
46-
</Fragment>
67+
</Grid>
4768
`;

0 commit comments

Comments
 (0)