aboutsummaryrefslogtreecommitdiff
path: root/src/client/react
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react')
-rw-r--r--src/client/react/actions/search.js5
-rw-r--r--src/client/react/components/container/Search.js9
-rw-r--r--src/client/react/components/presentational/Search.jsx35
-rw-r--r--src/client/react/reducers/search.js6
4 files changed, 45 insertions, 10 deletions
diff --git a/src/client/react/actions/search.js b/src/client/react/actions/search.js
index e50d851..53993d3 100644
--- a/src/client/react/actions/search.js
+++ b/src/client/react/actions/search.js
@@ -3,3 +3,8 @@ export const inputChange = typedValue => ({
type: 'SEARCH/INPUT_CHANGE',
typedValue,
});
+
+export const focusChange = hasFocus => ({
+ type: 'SEARCH/FOCUS_CHANGE',
+ hasFocus,
+});
diff --git a/src/client/react/components/container/Search.js b/src/client/react/components/container/Search.js
index 2489084..206a6a1 100644
--- a/src/client/react/components/container/Search.js
+++ b/src/client/react/components/container/Search.js
@@ -1,16 +1,23 @@
import { connect } from 'react-redux';
-import { inputChange } from '../../actions/search';
+import { inputChange, focusChange } from '../../actions/search';
import PresentationalSearch from '../presentational/Search';
const mapStateToProps = state => ({
results: state.search.searchResults,
value: state.search.searchInput,
+ hasFocus: state.search.hasFocus,
});
const mapDispatchToProps = dispatch => ({
onInputChange: (event) => {
dispatch(inputChange(event.target.value));
},
+ onFocus: () => {
+ dispatch(focusChange(true));
+ },
+ onBlur: () => {
+ dispatch(focusChange(false));
+ },
});
const Search = connect(
diff --git a/src/client/react/components/presentational/Search.jsx b/src/client/react/components/presentational/Search.jsx
index a713db4..01c6f7d 100644
--- a/src/client/react/components/presentational/Search.jsx
+++ b/src/client/react/components/presentational/Search.jsx
@@ -1,13 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
+import classnames from 'classnames';
+import SearchIcon from 'react-icons/lib/md/search';
-const Search = ({ onInputChange, value, results }) => (
- <div>
- <input
- onChange={onInputChange}
- value={value}
- placeholder="Zoeken"
- />
+const Search = ({
+ onInputChange,
+ onFocus,
+ onBlur,
+ hasFocus,
+ value,
+ results,
+}) => (
+ <div className={classnames('search', { focus: hasFocus })}>
+ <div className="search__input-wrapper">
+ <div className="search__icon-wrapper"><SearchIcon /></div>
+ <input
+ onChange={onInputChange}
+ value={value}
+ placeholder="Zoeken"
+ onFocus={onFocus}
+ onBlur={onBlur}
+ />
+ </div>
<ul>
{results.map(result => <li key={result.name}>{result.name}</li>)}
</ul>
@@ -16,10 +30,13 @@ const Search = ({ onInputChange, value, results }) => (
Search.propTypes = {
onInputChange: PropTypes.func.isRequired,
+ onFocus: PropTypes.func.isRequired,
+ onBlur: PropTypes.func.isRequired,
+ hasFocus: PropTypes.bool.isRequired,
value: PropTypes.string.isRequired,
results: PropTypes.arrayOf(PropTypes.shape({
- name: PropTypes.string.require,
- type: PropTypes.string.require,
+ name: PropTypes.string.isRequired,
+ type: PropTypes.string.isRequired,
})).isRequired,
};
diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js
index 08be519..a695184 100644
--- a/src/client/react/reducers/search.js
+++ b/src/client/react/reducers/search.js
@@ -1,6 +1,7 @@
const DEFAULT_STATE = {
searchInput: '',
searchResults: [],
+ hasFocus: false,
};
const search = (state = DEFAULT_STATE, action) => {
@@ -13,6 +14,11 @@ const search = (state = DEFAULT_STATE, action) => {
{ type: 's', name: '18561' },
],
};
+ case 'SEARCH/FOCUS_CHANGE':
+ return {
+ ...state,
+ hasFocus: action.hasFocus,
+ };
default:
return state;
}