File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import cx from 'classnames' ;
4
+ import Checkbox from '../checkbox' ;
5
+
6
+ import styles from './theme.scss' ;
7
+
8
+ class CheckboxGroup extends React . Component {
9
+ constructor ( props ) {
10
+ super ( props ) ;
11
+
12
+ this . state = {
13
+ isChecked : props . options . reduce ( ( accumulator , { label, value } ) => {
14
+ accumulator [ label ] = false ;
15
+ return accumulator ;
16
+ } , { } ) ,
17
+ }
18
+ }
19
+
20
+ handleCheckListChange = ( label ) => {
21
+ const isChecked = this . state . isChecked ;
22
+ isChecked [ label ] = ! isChecked [ label ] ;
23
+ this . setState ( {
24
+ isChecked,
25
+ } ) ;
26
+ }
27
+
28
+ render ( ) {
29
+ const {
30
+ options,
31
+ inline,
32
+ theme,
33
+ } = this . props ;
34
+
35
+ const classNames = cx ( styles [ 'radio-group' ] ) ;
36
+ return options . map ( option => (
37
+ < React . Fragment key = { option . label } >
38
+ < div className = { classNames } >
39
+ < div className = { cx ( styles [ 'each-check' ] , { inline } ) } >
40
+ < input type = "radio" />
41
+ < label className = { styles [ 'each-label' ] } >
42
+ { option . label }
43
+ </ label >
44
+ </ div >
45
+ </ div >
46
+ < div className = "clearfix" />
47
+ </ React . Fragment >
48
+ ) ) ;
49
+ }
50
+ }
51
+
52
+ CheckboxGroup . propTypes = {
53
+ options : PropTypes . array . isRequired ,
54
+ inline : PropTypes . bool ,
55
+ } ;
56
+
57
+ CheckboxGroup . defaultProps = {
58
+ inline : false ,
59
+ } ;
60
+
61
+ export default CheckboxGroup ;
You can’t perform that action at this time.
0 commit comments