File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,13 +77,15 @@ class TextWidget extends React.Component {
7777class ListItem extends React . Component {
7878 render ( ) {
7979 return ( < li > < input type = 'checkbox'
80- checked = { this . props . isChecked } /> { this . props . caption } </ li > ) ;
80+ checked = { this . props . isChecked }
81+ onChange = { this . props . onChangeChecked } /> { this . props . caption } </ li > ) ;
8182 }
8283}
8384
8485ListItem . propTypes = {
8586 caption : PropTypes . string . isRequired ,
86- isChecked : PropTypes . bool . isRequired
87+ isChecked : PropTypes . bool . isRequired ,
88+ onChangeChecked : PropTypes . func . isRequired
8789 } ;
8890
8991class ListWidget extends React . Component {
@@ -103,6 +105,17 @@ class ListWidget extends React.Component {
103105 total_added : state . total_added + 1
104106 } ) ;
105107
108+ this . _mutateStateToUpdateItemChecked = ( state , id , isChecked ) => ( {
109+ ...state ,
110+ items : state . items . map ( objItem => (
111+ objItem . id === id ? {
112+ ...objItem ,
113+ is_checked : isChecked
114+ }
115+ : objItem
116+ ) )
117+ } ) ;
118+
106119 const objStateEmpty = {
107120 items : [ ] ,
108121 total_added : 0
@@ -126,6 +139,13 @@ class ListWidget extends React.Component {
126139 < ListItem key = { objItem . id }
127140 caption = { objItem . caption }
128141 isChecked = { objItem . is_checked }
142+ onChangeChecked = { ( ) => {
143+ this . setState (
144+ this . _mutateStateToUpdateItemChecked (
145+ this . state ,
146+ objItem . id ,
147+ ! objItem . is_checked ) ) ;
148+ } }
129149 />
130150 ) ) }
131151 </ ul >
You can’t perform that action at this time.
0 commit comments