Skip to content

Commit eef0e0c

Browse files
authored
Merge pull request #833 from rvsia/muiSubformCustomization
fix(mui): allow to customize subform
2 parents 2009ae9 + 436e229 commit eef0e0c

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

packages/mui-component-mapper/src/files/sub-form.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { Field } from "@data-driven-forms/react-form-renderer";
2+
import { GridProps, TypographyProps } from "@material-ui/core";
23
import { ReactNode } from "react";
34

45
export interface SubFormProps {
56
fields: Field[] | Field;
6-
title: ReactNode;
7-
description: ReactNode;
7+
title?: ReactNode;
8+
description?: ReactNode;
9+
TitleGridProps?: GridProps;
10+
TitleProps?: TypographyProps;
11+
DescriptionProps?: TypographyProps;
12+
DescriptionGridProps?: GridProps;
13+
ItemsGridProps?: GridProps;
814
}
915

1016
declare const SubForm: React.ComponentType<SubFormProps>;

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,38 @@ const useStyles = makeStyles(() => ({
1212
}
1313
}));
1414

15-
const SubForm = ({ fields, title, description, component, ...rest }) => {
15+
const SubForm = ({
16+
fields,
17+
title,
18+
description,
19+
component,
20+
TitleGridProps,
21+
TitleProps,
22+
DescriptionProps,
23+
DescriptionGridProps,
24+
ItemsGridProps,
25+
...rest
26+
}) => {
1627
const { renderForm } = useFormApi();
1728
const classes = useStyles();
1829

1930
return (
2031
<Grid item xs={12} container className={classes.grid} {...rest}>
2132
{title && (
22-
<Grid item xs={12}>
23-
<Typography variant="h5">{title}</Typography>
33+
<Grid item xs={12} {...TitleGridProps}>
34+
<Typography variant="h5" {...TitleProps}>
35+
{title}
36+
</Typography>
2437
</Grid>
2538
)}
2639
{description && (
27-
<Grid item xs={12}>
28-
<Typography paragraph>{description}</Typography>
40+
<Grid item xs={12} {...DescriptionGridProps}>
41+
<Typography paragraph {...DescriptionProps}>
42+
{description}
43+
</Typography>
2944
</Grid>
3045
)}
31-
<Grid item xs={12} container>
46+
<Grid item xs={12} container {...ItemsGridProps}>
3247
{renderForm(fields)}
3348
</Grid>
3449
</Grid>
@@ -39,7 +54,12 @@ SubForm.propTypes = {
3954
fields: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
4055
title: PropTypes.node,
4156
description: PropTypes.node,
42-
component: PropTypes.any
57+
component: PropTypes.any,
58+
TitleGridProps: PropTypes.object,
59+
TitleProps: PropTypes.object,
60+
DescriptionProps: PropTypes.object,
61+
DescriptionGridProps: PropTypes.object,
62+
ItemsGridProps: PropTypes.object
4363
};
4464

4565
export default SubForm;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Common from './common.md';
2+
3+
<Common />
4+
5+
### Composite props
6+
|name|type|default|target component|
7+
|----|----|-------|----------------|
8+
|TitleProps|object|`{}`|[Grid](https://material-ui.com/api/typography/)|
9+
|TitleGridProps|object|`{}`|[Grid](https://material-ui.com/api/grid/)|
10+
|DescriptionProps|object|`{}`|[Grid](https://material-ui.com/api/typography/)|
11+
|DescriptionGridProps|object|`{}`|[Grid](https://material-ui.com/api/grid/)|
12+
|ItemsGridProps|object|`{}`|[Grid](https://material-ui.com/api/grid/)|

packages/react-renderer-demo/src/doc-components/sub-form.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import SuirSubForm from './examples-texts/suir/suir-sub-form.md';
44
import CarbonSubForm from './examples-texts/carbon/carbon-sub-form.md';
5+
import MuiSubForm from './examples-texts/mui/mui-sub-form.md';
6+
57
import GenericMuiComponent from '../helpers/generic-mui-component';
68

79
const SubForm = ({ activeMapper }) => {
@@ -13,6 +15,10 @@ const SubForm = ({ activeMapper }) => {
1315
return <CarbonSubForm />;
1416
}
1517

18+
if (activeMapper === 'mui') {
19+
return <MuiSubForm />;
20+
}
21+
1622
return <GenericMuiComponent activeMapper={activeMapper} component="sub-form" />;
1723
};
1824

0 commit comments

Comments
 (0)