Fix(map): update map filter components and esc key event
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import PureComponent from 'react-pure-render/component';
|
import PureComponent from 'react-pure-render/component';
|
||||||
import { Input, Button, Row } from 'react-bootstrap';
|
import { InputGroup, FormControl, Button, Row } from 'react-bootstrap';
|
||||||
|
|
||||||
import SuperBlock from './Super-Block.jsx';
|
import SuperBlock from './Super-Block.jsx';
|
||||||
import FullStack from './Full-Stack.jsx';
|
import FullStack from './Full-Stack.jsx';
|
||||||
@ -9,7 +9,12 @@ import CodingPrep from './Coding-Prep.jsx';
|
|||||||
|
|
||||||
const clearIcon = <i className='fa fa-times' />;
|
const clearIcon = <i className='fa fa-times' />;
|
||||||
const searchIcon = <i className='fa fa-search' />;
|
const searchIcon = <i className='fa fa-search' />;
|
||||||
|
const ESC = 27;
|
||||||
export default class ShowMap extends PureComponent {
|
export default class ShowMap extends PureComponent {
|
||||||
|
constructor(...props) {
|
||||||
|
super(...props);
|
||||||
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
||||||
|
}
|
||||||
static displayName = 'Map';
|
static displayName = 'Map';
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
clearFilter: PropTypes.func,
|
clearFilter: PropTypes.func,
|
||||||
@ -18,6 +23,12 @@ export default class ShowMap extends PureComponent {
|
|||||||
updateFilter: PropTypes.func
|
updateFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleKeyDown(e) {
|
||||||
|
if (e.keyCode === ESC) {
|
||||||
|
this.props.clearFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderSuperBlocks(superBlocks, updateCurrentChallenge) {
|
renderSuperBlocks(superBlocks, updateCurrentChallenge) {
|
||||||
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
||||||
return <div>No Super Blocks</div>;
|
return <div>No Super Blocks</div>;
|
||||||
@ -33,6 +44,13 @@ export default class ShowMap extends PureComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderSearchAddon(filter, clearFilter) {
|
||||||
|
if (!filter) {
|
||||||
|
return searchIcon;
|
||||||
|
}
|
||||||
|
return <span onClick={ clearFilter }>{ clearIcon }</span>;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
updateCurrentChallenge,
|
updateCurrentChallenge,
|
||||||
@ -41,9 +59,6 @@ export default class ShowMap extends PureComponent {
|
|||||||
clearFilter,
|
clearFilter,
|
||||||
filter
|
filter
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const inputIcon = !filter ?
|
|
||||||
searchIcon :
|
|
||||||
<span onClick={ clearFilter }>{ clearIcon }</span>;
|
|
||||||
const inputClass = classnames({
|
const inputClass = classnames({
|
||||||
'map-filter': true,
|
'map-filter': true,
|
||||||
filled: !!filter
|
filled: !!filter
|
||||||
@ -66,15 +81,20 @@ export default class ShowMap extends PureComponent {
|
|||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
<Row className='map-buttons'>
|
<Row className='map-buttons'>
|
||||||
<Input
|
<InputGroup>
|
||||||
addonAfter={ inputIcon }
|
<FormControl
|
||||||
autocompleted='off'
|
autocompleted='off'
|
||||||
className={ inputClass }
|
className={ inputClass }
|
||||||
onChange={ updateFilter }
|
onChange={ updateFilter }
|
||||||
placeholder='Type a challenge name'
|
onKeyDown={ this.handleKeyDown }
|
||||||
type='text'
|
placeholder='Type a challenge name'
|
||||||
value={ filter }
|
type='text'
|
||||||
/>
|
value={ filter }
|
||||||
|
/>
|
||||||
|
<InputGroup.Addon>
|
||||||
|
{ this.renderSearchAddon(filter, clearFilter) }
|
||||||
|
</InputGroup.Addon>
|
||||||
|
</InputGroup>
|
||||||
</Row>
|
</Row>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user