import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import { defineMessages, injectIntl } from 'react-intl'; import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input'; import Icon from 'soapbox/components/icon'; const messages = defineMessages({ placeholder: { id: 'account_search.placeholder', defaultMessage: 'Search for an account' }, }); export default @injectIntl class AccountSearch extends React.PureComponent { static propTypes = { intl: PropTypes.object.isRequired, onSelected: PropTypes.func.isRequired, }; state = { value: '', } isEmpty = () => { const { value } = this.state; return !(value.length > 0); } clearState = () => { this.setState({ value: '' }); } handleChange = ({ target }) => { this.setState({ value: target.value }); } handleSelected = accountId => { this.clearState(); this.props.onSelected(accountId); } handleClear = e => { e.preventDefault(); if (!this.isEmpty()) { this.setState({ value: '' }); } } handleKeyDown = e => { if (e.key === 'Escape') { document.querySelector('.ui').parentElement.focus(); } } render() { const { intl, onSelected, ...rest } = this.props; const { value } = this.state; const isEmpty = this.isEmpty(); return (
); } }