import classNames from 'classnames'; import Overlay from 'react-overlays/lib/Overlay'; import Icon from '../icon'; import SearchPopout from '../search_popout'; import './search.scss'; export default class Search extends PureComponent { static contextTypes = { router: PropTypes.object.isRequired, }; static propTypes = { value: PropTypes.string.isRequired, submitted: PropTypes.bool, onShow: PropTypes.func.isRequired, openInRoute: PropTypes.bool, placeholder: PropTypes.string.isRequired, className: PropTypes.string, searchTitle: PropTypes.string, onChange: PropTypes.func.isRequired, onKeyUp: PropTypes.func.isRequired, handleSubmit: PropTypes.func, withOverlay: PropTypes.bool, handleClear: PropTypes.func.isRequired, }; state = { expanded: false, }; handleFocus = () => { this.setState({ expanded: true }); this.props.onShow(); } handleBlur = () => { this.setState({ expanded: false }); } render() { const { value, submitted, placeholder, className, searchTitle, onKeyUp, handleClear, handleSubmit, withOverlay, onChange } = this.props; const { expanded } = this.state; const hasValue = value.length > 0 || submitted; const classes = classNames('search', className); const iconClass = hasValue ? 'active' : ''; return (
{ withOverlay && } { (searchTitle && handleSubmit) && }
); } }