File tree Expand file tree Collapse file tree 3 files changed +17
-14
lines changed
Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,11 @@ export default observer(class App extends Component {
2121 return (
2222 < MuiThemeProvider >
2323 < div >
24- < SearchInput colors = { this . props . colors } />
25- < SearchResults colors = { this . props . colors } />
24+ < SearchInput query = { this . props . colors . query }
25+ onQueryUpdate = { value => this . props . colors . updateQuery ( value ) }
26+ onSubmit = { ( ) => this . props . colors . search ( ) }
27+ />
28+ < SearchResults colors = { this . props . colors . results . slice ( ) } />
2629 </ div >
2730 </ MuiThemeProvider >
2831 ) ;
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import { TextField } from 'material-ui' ;
3- import { observer } from 'mobx-react' ;
43
5- export default observer ( class SearchInput extends Component {
4+ export default class SearchInput extends Component {
65 static propTypes = {
7- colors : React . PropTypes . object . isRequired
6+ query : React . PropTypes . string . isRequired ,
7+ onSubmit : React . PropTypes . func . isRequired ,
8+ onQueryUpdate : React . PropTypes . func . isRequired
89 } ;
910
1011 handleKeyDown = ( event ) => {
1112 const ENTER_KEY = 13 ;
1213 if ( event . keyCode === ENTER_KEY ) {
1314 event . preventDefault ( ) ;
14- this . props . colors . search ( ) ;
15+ this . props . onSubmit ( ) ;
1516 }
1617 } ;
1718
@@ -20,9 +21,9 @@ export default observer(class SearchInput extends Component {
2021 < TextField hintText = "Search..."
2122 floatingLabelFixed = { true }
2223 fullWidth = { true }
23- value = { this . props . colors . query }
24- onChange = { ( event , value ) => this . props . colors . updateQuery ( value ) }
24+ value = { this . props . query }
25+ onChange = { ( event , value ) => this . props . onQueryUpdate ( value ) }
2526 onKeyDown = { this . handleKeyDown } />
2627 )
2728 }
28- } ) ;
29+ }
Original file line number Diff line number Diff line change 11import React , { Component } from 'react' ;
22import { List , ListItem , Divider } from 'material-ui'
3- import { observer } from 'mobx-react' ;
43
5- export default observer ( class SearchResults extends Component {
4+ export default class SearchResults extends Component {
65 static propTypes = {
7- colors : React . PropTypes . object . isRequired
6+ colors : React . PropTypes . array . isRequired
87 } ;
98
109 render ( ) {
11- const listItems = this . props . colors . results . map ( ( color , index ) => {
10+ const listItems = this . props . colors . map ( ( color , index ) => {
1211 return (
1312 < div key = { `color-div-${ index } ` } >
1413 < ListItem key = { `color-${ index } ` } primaryText = { color . name } style = { { backgroundColor : color . hex } } />
@@ -23,4 +22,4 @@ export default observer(class SearchResults extends Component {
2322 ) ;
2423 }
2524
26- } ) ;
25+ }
You can’t perform that action at this time.
0 commit comments