ETHReport/components/searchBar/index.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { PropTypes } from 'prop-types';
import getConfig from 'next/config';
import './style.scss';
2018-07-11 13:53:09 +00:00
const { publicRuntimeConfig } = getConfig();
const SearchBar = props => (
2018-07-11 13:53:09 +00:00
<div className="search-bar" style={{ backgroundImage: `url(${publicRuntimeConfig.subDirPath}/static/img/header-bg.jpg)` }}>
<div className="container">
2018-07-18 08:27:36 +00:00
<h3 className="main-heading" style={{ backgroundImage: `url(${publicRuntimeConfig.subDirPath}/static/img/heading-textured-bg.jpg)` }}>
Archives
</h3>
2018-07-09 14:29:57 +00:00
<form className="search-form">
<input
className="search-input"
type="search"
2018-07-17 13:07:07 +00:00
placeholder="Search"
2018-07-09 14:29:57 +00:00
value={props.term}
onChange={props.onSearchInputChange}
/>
2018-07-17 14:23:38 +00:00
<img className="search-icon" src={`${publicRuntimeConfig.subDirPath}/static/img/search-icon.svg`} alt="Search" />
2018-07-09 14:29:57 +00:00
{ props.isSearchActive && (
2018-07-11 09:18:07 +00:00
<button
2018-07-09 14:29:57 +00:00
className="search-clear-button"
onClick={props.clearSearchInput}
>
2018-07-17 14:23:38 +00:00
<img src={`${publicRuntimeConfig.subDirPath}/static/img/clear-search-icon.svg`} alt="Clear search" />
2018-07-11 09:18:07 +00:00
</button>
2018-07-09 14:29:57 +00:00
)
}
</form>
2018-07-18 10:34:35 +00:00
{props.numResults > 0 && props.numResults[0] !== null ?
2018-07-18 10:44:44 +00:00
<p className="search-count">{ props.numMatchedTerms } search term matches | { props.numResults } interview matches</p> :
2018-07-18 10:34:35 +00:00
''}
</div>
</div>
);
SearchBar.propTypes = {
term: PropTypes.string.isRequired,
2018-07-09 14:29:57 +00:00
isSearchActive: PropTypes.bool.isRequired,
onSearchInputChange: PropTypes.func.isRequired,
clearSearchInput: PropTypes.func.isRequired,
2018-07-18 10:34:35 +00:00
numResults: PropTypes.number.isRequired,
numMatchedTerms: PropTypes.number.isRequired,
2018-07-09 14:29:57 +00:00
};
export default SearchBar;