Skip to content

Commit 5e15c4d

Browse files
committed
moved to common, webpack to copy files
1 parent c62c5ae commit 5e15c4d

File tree

11 files changed

+1516
-668
lines changed

11 files changed

+1516
-668
lines changed

common/SearchBox.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, {Component} from 'react';
2+
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
3+
4+
import {observer} from 'mobx-react';
5+
6+
// (Make material-ui happy)
7+
// Needed for onTouchTap
8+
// http://stackoverflow.com/a/34015469/988941
9+
import injectTapEventPlugin from 'react-tap-event-plugin';
10+
injectTapEventPlugin();
11+
12+
import SearchInput from './SearchInput';
13+
import SearchResults from './SearchResults';
14+
15+
export default observer(class App extends Component {
16+
static propTypes = {
17+
searchStore: React.PropTypes.object.isRequired
18+
};
19+
20+
render() {
21+
return (
22+
<MuiThemeProvider>
23+
<div>
24+
<SearchInput query={this.props.searchStore.query}
25+
onQueryUpdate={value => this.props.searchStore.updateQuery(value)}
26+
onSubmit={() => this.props.searchStore.search()}
27+
/>
28+
<SearchResults results={this.props.searchStore.results.slice()}/>
29+
</div>
30+
</MuiThemeProvider>
31+
);
32+
}
33+
});
34+

common/SearchInput.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import {TextField} from 'material-ui';
3+
4+
const SearchInput = ({query, onSubmit, onQueryUpdate}) => {
5+
const handleKeyDown = (event) => {
6+
const ENTER_KEY = 13;
7+
if (event.keyCode === ENTER_KEY) {
8+
event.preventDefault();
9+
onSubmit();
10+
}
11+
};
12+
13+
return (
14+
<TextField hintText="Search..."
15+
floatingLabelFixed={true}
16+
fullWidth={true}
17+
value={query}
18+
onChange={(event, value) => onQueryUpdate(value)}
19+
onKeyDown={handleKeyDown}/>
20+
);
21+
22+
};
23+
24+
SearchInput.propTypes = {
25+
query: React.PropTypes.string.isRequired,
26+
onSubmit: React.PropTypes.func.isRequired,
27+
onQueryUpdate: React.PropTypes.func.isRequired
28+
};
29+
30+
export default SearchInput;

common/SearchResults.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import {List, ListItem, Divider} from 'material-ui'
3+
4+
const SearchResults = ({results}) => {
5+
const listItems = results.map((result, index) => {
6+
return (
7+
<div key={`result-div-${index}`}>
8+
<ListItem key={`result-${index}`} primaryText={result.name} style={{backgroundColor: result.hex} }/>
9+
<Divider key={`divider-${index}`}/>
10+
</div>
11+
);
12+
});
13+
return (
14+
<List>
15+
{listItems}
16+
</List>
17+
);
18+
};
19+
20+
SearchResults.propTypes = {
21+
results: React.PropTypes.array.isRequired
22+
};
23+
24+
export default SearchResults;

common/colors.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {extendObservable, runInAction} from 'mobx';
2+
import crayola from './crayola.json'
3+
4+
export default class Colors {
5+
constructor() {
6+
extendObservable(this, {
7+
results: [],
8+
query: ''
9+
});
10+
}
11+
12+
search() {
13+
runInAction(() => {
14+
this.results = crayola.filter(color => color.name.toLowerCase().includes(this.query.toLowerCase()));
15+
});
16+
}
17+
18+
updateQuery(value) {
19+
runInAction(() => this.query = value);
20+
}
21+
}

0 commit comments

Comments
 (0)