import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import ExternalLink from 'boost/components/ExternalLink' import { setSearchFilter, clearSearch, toggleTutorial } from 'boost/actions' const BRAND_COLOR = '#18AF90' const searchTutorialElement = ( ) export default class ArticleTopBar extends React.Component { constructor (props) { super(props) this.state = { isTooltipHidden: true, isLinksDropdownOpen: false } } componentDidMount () { this.searchInput = ReactDOM.findDOMNode(this.refs.searchInput) this.linksButton = ReactDOM.findDOMNode(this.refs.links) this.showLinksDropdown = e => { e.preventDefault() e.stopPropagation() if (!this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: true}) } } this.linksButton.addEventListener('click', this.showLinksDropdown) this.hideLinksDropdown = e => { if (this.state.isLinksDropdownOpen) { this.setState({isLinksDropdownOpen: false}) } } document.addEventListener('click', this.hideLinksDropdown) } componentWillUnmount () { document.removeEventListener('click', this.hideLinksDropdown) this.linksButton.removeEventListener('click', this.showLinksDropdown()) } handleTooltipRequest (e) { if (this.searchInput.value.length === 0 && (document.activeElement === this.searchInput)) { this.setState({isTooltipHidden: false}) } else { this.setState({isTooltipHidden: true}) } } isInputFocused () { return document.activeElement === ReactDOM.findDOMNode(this.refs.searchInput) } escape () { let { status, dispatch } = this.props if (status.search.length > 0) { dispatch(clearSearch()) return } this.blurInput() } focusInput () { this.searchInput.focus() } blurInput () { this.searchInput.blur() } handleSearchChange (e) { let { dispatch } = this.props dispatch(setSearchFilter(e.target.value)) this.handleTooltipRequest() } handleSearchClearButton (e) { this.searchInput.value = '' this.focusInput() } handleTutorialButtonClick (e) { let { dispatch } = this.props dispatch(toggleTutorial()) } render () { let { status } = this.props return (