1
1
import React from 'react' ;
2
- import { composeValidators } from '@data-driven-forms/react-form-renderer' ;
2
+ import PropTypes from 'prop-types' ;
3
+
3
4
import Grid from '@material-ui/core/Grid' ;
4
5
import Checkbox from '@material-ui/core/Checkbox' ;
5
6
import FormControlLabel from '@material-ui/core/FormControlLabel' ;
@@ -8,65 +9,47 @@ import FormGroup from '@material-ui/core/FormGroup';
8
9
import FormControl from '@material-ui/core/FormControl' ;
9
10
import FormHelperText from '@material-ui/core/FormHelperText' ;
10
11
11
- const MultipleChoiceList = ( { validate, FieldProvider, ...props } ) => (
12
- < FieldProvider { ...props } validate = { composeValidators ( props . validate || [ ] ) } >
13
- { ( {
14
- label,
15
- isRequired,
16
- helperText,
17
- meta,
18
- options,
19
- isDisabled,
20
- formOptions,
21
- componentType,
22
- ...rest
23
- } ) => {
24
- const { error, touched } = meta ;
25
- const showError = touched && error ;
26
- const groupValues = Array . isArray ( rest . input . value ) ? rest . input . value : [ ] ;
27
- return (
28
- < Grid container >
29
- < FormControl component = "fieldset" >
30
- < FormLabel > { label } </ FormLabel >
31
- < FormGroup >
32
- { options . map ( option =>
33
- ( < FieldProvider
34
- { ...rest }
35
- id = { `${ rest . id } -${ option . value } ` }
36
- key = { option . value }
37
- { ...option }
38
- name = { props . name }
39
- type = "checkbox"
40
- render = { ( { input, meta, value, formOptions, ...rest } ) => {
41
- const indexValue = groupValues . indexOf ( option . value ) ;
42
- return (
43
- < FormControlLabel
44
- control = { < Checkbox
45
- label = { rest . label }
46
- aria-label = { option [ 'aria-label' ] || option . label }
47
- { ...input }
48
- { ...rest }
49
- checked = { indexValue !== - 1 }
50
- disabled = { isDisabled }
51
- onChange = { ( ) => {
52
- return ( indexValue === - 1
53
- ? input . onChange ( [ ...groupValues , option . value ] )
54
- : input . onChange ( [ ...groupValues . slice ( 0 , indexValue ) , ...groupValues . slice ( indexValue + 1 ) ] ) ) ; } }
55
- >
56
- { option . label }
57
- </ Checkbox > }
58
- label = { option . label }
59
- />
60
- ) ;
61
- } }
62
- /> ) ) }
63
- </ FormGroup >
64
- < FormHelperText > { showError ? error : null } </ FormHelperText >
65
- </ FormControl >
66
- </ Grid >
67
- ) ;
68
- } }
69
- </ FieldProvider >
12
+ import MultipleChoiceListCommon , { wrapperProps } from '@data-driven-forms/common/src/multiple-choice-list' ;
13
+
14
+ const FinalCheckbox = ( props ) => (
15
+ < FormControlLabel
16
+ control = { < Checkbox
17
+ { ...props }
18
+ disabled = { props . isDisabled }
19
+ >
20
+ { props . label }
21
+ </ Checkbox > }
22
+ label = { props . label }
23
+ />
24
+ ) ;
25
+
26
+ FinalCheckbox . propTypes = {
27
+ isDisabled : PropTypes . bool ,
28
+ label : PropTypes . node ,
29
+ } ;
30
+
31
+ const Wrapper = ( { showError, label, error, children } ) => (
32
+ < Grid container >
33
+ < FormControl component = "fieldset" >
34
+ < FormLabel > { label } </ FormLabel >
35
+ < FormGroup >
36
+ { children }
37
+ </ FormGroup >
38
+ < FormHelperText > { showError ? error : null } </ FormHelperText >
39
+ </ FormControl >
40
+ </ Grid >
41
+ ) ;
42
+
43
+ Wrapper . propTypes = {
44
+ ...wrapperProps ,
45
+ } ;
46
+
47
+ const MultipleChoiceList = ( props ) => (
48
+ < MultipleChoiceListCommon
49
+ { ...props }
50
+ Wrapper = { Wrapper }
51
+ Checkbox = { FinalCheckbox }
52
+ />
70
53
) ;
71
54
72
55
export default MultipleChoiceList ;
0 commit comments