2022-09-22 13:24:11 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
|
|
|
import { Icon, Input } from 'soapbox/components/ui';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
searchPlaceholder: { id: 'chats.search_placeholder', defaultMessage: 'Search inbox' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IChatSearchInput {
|
|
|
|
/** Search term. */
|
|
|
|
value: string,
|
|
|
|
/** Callback when the search value changes. */
|
|
|
|
onChange: React.ChangeEventHandler<HTMLInputElement>,
|
|
|
|
/** Callback when the input is cleared. */
|
|
|
|
onClear: React.MouseEventHandler<HTMLButtonElement>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Search input for filtering chats. */
|
|
|
|
const ChatSearchInput: React.FC<IChatSearchInput> = ({ value, onChange, onClear }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Input
|
2022-10-03 08:03:43 -07:00
|
|
|
data-testid='chat-search-input'
|
2022-09-22 13:24:11 -07:00
|
|
|
type='text'
|
|
|
|
autoFocus
|
|
|
|
placeholder={intl.formatMessage(messages.searchPlaceholder)}
|
|
|
|
className='rounded-full'
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
2022-10-04 14:47:15 -07:00
|
|
|
theme='search'
|
2022-09-22 13:24:11 -07:00
|
|
|
append={
|
|
|
|
<button onClick={onClear}>
|
|
|
|
<Icon
|
2022-09-22 15:06:42 -07:00
|
|
|
src={value.length ? require('@tabler/icons/x.svg') : require('@tabler/icons/search.svg')}
|
2022-09-22 13:24:11 -07:00
|
|
|
className='h-4 w-4 text-gray-700 dark:text-gray-600'
|
|
|
|
aria-hidden='true'
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChatSearchInput;
|