import classNames from 'clsx'; import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import AutosuggestAccountInput from 'soapbox/components/autosuggest-account-input'; import SvgIcon from './ui/icon/svg-icon'; const messages = defineMessages({ placeholder: { id: 'account_search.placeholder', defaultMessage: 'Search for an account' }, }); interface IAccountSearch { /** Callback when a searched account is chosen. */ onSelected: (accountId: string) => void, /** Override the default placeholder of the input. */ placeholder?: string, } /** Input to search for accounts. */ const AccountSearch: React.FC = ({ onSelected, ...rest }) => { const intl = useIntl(); const [value, setValue] = useState(''); const isEmpty = (): boolean => { return !(value.length > 0); }; const clearState = () => { setValue(''); }; const handleChange: React.ChangeEventHandler = ({ target }) => { setValue(target.value); }; const handleSelected = (accountId: string) => { clearState(); onSelected(accountId); }; const handleClear: React.MouseEventHandler = e => { e.preventDefault(); if (!isEmpty()) { setValue(''); } }; const handleKeyDown: React.KeyboardEventHandler = e => { if (e.key === 'Escape') { document.querySelector('.ui')?.parentElement?.focus(); } }; return (
); }; export default AccountSearch;