Skip to content

Commit 2fb2885

Browse files
committed
fix(suir): added sub components customization API
1 parent b3e54d0 commit 2fb2885

File tree

16 files changed

+438
-138
lines changed

16 files changed

+438
-138
lines changed

packages/suir-component-mapper/demo/index.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import fieldArraySchema from './demo-schemas/field-array-schema';
88

99
import wizardSchema from './demo-schemas/wizard-schema';
1010
import { Button } from 'semantic-ui-react';
11-
import validatorTypes from '@data-driven-forms/react-form-renderer/dist/cjs/validator-types';
1211

1312
const compositeMapper = {
1413
...componentMapper,
@@ -17,40 +16,6 @@ const compositeMapper = {
1716
}
1817
};
1918

20-
const dualSchema = {
21-
fields: [
22-
{
23-
component: componentTypes.DUAL_LIST_SELECT,
24-
name: 'dual-list',
25-
label: 'Dual list',
26-
isRquired: true,
27-
validate: [{ type: validatorTypes.REQUIRED }],
28-
options: [
29-
{
30-
value: 'cats',
31-
label: 'cats'
32-
},
33-
{
34-
value: 'cats_1',
35-
label: 'cats_1'
36-
},
37-
{
38-
value: 'cats_2',
39-
label: 'cats_2'
40-
},
41-
{
42-
value: 'zebras',
43-
label: 'zebras'
44-
},
45-
{
46-
value: 'pigeons',
47-
label: 'pigeons'
48-
}
49-
]
50-
}
51-
]
52-
};
53-
5419
const App = () => {
5520
const [, setSchema] = useState(wizardSchema);
5621

@@ -70,7 +35,7 @@ const App = () => {
7035
onSubmit={console.log}
7136
componentMapper={compositeMapper}
7237
FormTemplate={(props) => <FormTemplate {...props} showFormControls={true} />}
73-
schema={dualSchema}
38+
schema={fieldArraySchema}
7439
onCancel={() => console.log('canceling')}
7540
/>
7641
</div>

packages/suir-component-mapper/src/common/form-field-grid.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ const useStyles = createUseStyles({
1111
}
1212
});
1313

14-
const FormFieldGrid = ({ className, children, helperText }) => {
14+
const FormFieldGrid = ({ className, children, helperText, HelperTextProps }) => {
1515
const classes = useStyles();
1616
return (
1717
<div className={clsx(classes.root, className)}>
1818
{children}
19-
{helperText && <HelperText>{helperText}</HelperText>}
19+
{helperText && <HelperText {...HelperTextProps}>{helperText}</HelperText>}
2020
</div>
2121
);
2222
};
2323

2424
FormFieldGrid.propTypes = {
2525
className: PropTypes.string,
2626
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
27-
helperText: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)])
27+
helperText: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
28+
HelperTextProps: PropTypes.object
2829
};
2930

3031
export default FormFieldGrid;

packages/suir-component-mapper/src/common/multiple-choice-list.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,35 @@ FinalCheckbox.propTypes = {
4646
const Wrapper = ({ label, isRequired, children, meta, validateOnMount, helperText }) => {
4747
const invalid = validationError(meta, validateOnMount);
4848
const classes = useStyles();
49+
const {
50+
FormFieldGridProps,
51+
FormFieldProps,
52+
HelperTextProps,
53+
OptionsListProps: { className: optionsClassName, ...OptionsListProps },
54+
HeaderProps: { className: headerClassname, ...HeaderProps }
55+
} = useContext(CheckboxContext);
4956
return (
50-
<FormFieldGrid helperText={helperText}>
57+
<FormFieldGrid helperText={helperText} HelperTextProps={HelperTextProps} {...FormFieldGridProps}>
5158
<FormField
59+
{...FormFieldProps}
5260
{...(invalid && {
5361
error: {
5462
content: meta.error,
5563
pointing: 'left'
5664
}
5765
})}
58-
label={<Header className={clsx({ [classes.header]: true, [classes.error]: invalid, [classes.required]: isRequired })}>{label}</Header>}
66+
label={
67+
<Header
68+
{...HeaderProps}
69+
className={clsx(headerClassname, { [classes.header]: true, [classes.error]: invalid, [classes.required]: isRequired })}
70+
>
71+
{label}
72+
</Header>
73+
}
5974
/>
60-
<div className={classes.items}>{children}</div>
75+
<div {...OptionsListProps} className={clsx(classes.items, optionsClassName)}>
76+
{children}
77+
</div>
6178
</FormFieldGrid>
6279
);
6380
};
@@ -66,10 +83,26 @@ Wrapper.propTypes = {
6683
...wrapperProps
6784
};
6885

69-
const MultipleChoiceList = (props) => (
70-
<CheckboxContext.Provider value={{ props }}>
86+
const MultipleChoiceList = ({ FormFieldGridProps, FormFieldProps, HeaderProps, OptionsListProps, HelperTextProps, ...props }) => (
87+
<CheckboxContext.Provider value={{ props, FormFieldGridProps, FormFieldProps, HeaderProps, OptionsListProps, HelperTextProps }}>
7188
<MultipleChoiceListCommon {...props} Wrapper={Wrapper} Checkbox={FinalCheckbox} />
7289
</CheckboxContext.Provider>
7390
);
7491

92+
MultipleChoiceList.propTypes = {
93+
FormFieldGridProps: PropTypes.object,
94+
FormFieldProps: PropTypes.object,
95+
HeaderProps: PropTypes.object,
96+
OptionsListProps: PropTypes.object,
97+
HelperTextProps: PropTypes.object
98+
};
99+
100+
MultipleChoiceList.defaultProps = {
101+
FormFieldGridProps: {},
102+
FormFieldProps: {},
103+
HeaderProps: {},
104+
OptionsListProps: {},
105+
HelperTextProps: {}
106+
};
107+
75108
export default MultipleChoiceList;

packages/suir-component-mapper/src/files/checkbox.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,27 @@ import MultipleChoiceList from '../common/multiple-choice-list';
99
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
1010

1111
export const SingleCheckbox = (props) => {
12-
const { input, isReadOnly, isDisabled, isRequired, label, helperText, description, validateOnMount, meta, ...rest } = useFieldApi({
12+
const {
13+
input,
14+
isReadOnly,
15+
isDisabled,
16+
isRequired,
17+
label,
18+
helperText,
19+
description,
20+
validateOnMount,
21+
meta,
22+
FormFieldGridProps,
23+
HelperTextProps,
24+
...rest
25+
} = useFieldApi({
1326
...props,
1427
type: 'checkbox'
1528
});
1629
const invalid = validationError(meta, validateOnMount);
1730

1831
return (
19-
<FormFieldGrid helperText={helperText}>
32+
<FormFieldGrid helperText={helperText} HelperTextProps={HelperTextProps} {...FormFieldGridProps}>
2033
<FormCheckbox
2134
{...input}
2235
required={isRequired}
@@ -46,13 +59,30 @@ SingleCheckbox.propTypes = {
4659
label: PropTypes.node,
4760
helperText: PropTypes.node,
4861
description: PropTypes.node,
49-
validateOnMount: PropTypes.bool
62+
validateOnMount: PropTypes.bool,
63+
/** Sub components customization API */
64+
FormFieldGridProps: PropTypes.object,
65+
HelperTextProps: PropTypes.object
5066
};
5167

5268
const Checkbox = ({ options, ...props }) => (options ? <MultipleChoiceList options={options} {...props} /> : <SingleCheckbox {...props} />);
5369

5470
Checkbox.propTypes = {
55-
options: PropTypes.array
71+
options: PropTypes.array,
72+
/** Sub components customization API */
73+
FormFieldGridProps: PropTypes.object,
74+
FormFieldProps: PropTypes.object,
75+
HeaderProps: PropTypes.object,
76+
OptionsListProps: PropTypes.object,
77+
HelperTextProps: PropTypes.object
78+
};
79+
80+
Checkbox.defaultProps = {
81+
FormFieldGridProps: {},
82+
FormFieldProps: {},
83+
HeaderProps: {},
84+
OptionsListProps: {},
85+
HelperTextProps: {}
5686
};
5787

5888
export default Checkbox;

packages/suir-component-mapper/src/files/date-picker.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ import { useFieldApi } from '@data-driven-forms/react-form-renderer';
88
import FormField from '../common/form-field';
99

1010
const DatePicker = (props) => {
11-
const { input, isReadOnly, isDisabled, placeholder, isRequired, label, helperText, validateOnMount, meta } = useFieldApi(props);
11+
const {
12+
input,
13+
isReadOnly,
14+
isDisabled,
15+
placeholder,
16+
isRequired,
17+
label,
18+
helperText,
19+
validateOnMount,
20+
meta,
21+
FormFieldGridProps,
22+
HelperTextProps,
23+
...rest
24+
} = useFieldApi(props);
1225
const invalid = validationError(meta, validateOnMount);
1326

1427
return (
15-
<FormFieldGrid helperText={helperText}>
28+
<FormFieldGrid helperText={helperText} HelperTextProps={HelperTextProps} {...FormFieldGridProps}>
1629
<FormField
1730
label={label}
1831
{...input}
@@ -23,6 +36,7 @@ const DatePicker = (props) => {
2336
content: meta.error
2437
}
2538
}
39+
{...rest}
2640
control={(props) => <input {...props} readOnly={isReadOnly} disabled={isDisabled} placeholder={placeholder} />}
2741
/>
2842
</FormFieldGrid>
@@ -40,7 +54,15 @@ DatePicker.propTypes = {
4054
helperText: PropTypes.node,
4155
validateOnMount: PropTypes.bool,
4256
locale: PropTypes.string,
43-
description: PropTypes.node
57+
description: PropTypes.node,
58+
/** Sub components customization API */
59+
FormFieldGridProps: PropTypes.object,
60+
HelperTextProps: PropTypes.object
61+
};
62+
63+
DatePicker.defaultProps = {
64+
FormFieldGridProps: {},
65+
HelperTextProps: {}
4466
};
4567

4668
export default DatePicker;

0 commit comments

Comments
 (0)