/
SearchInput.tsx
41 lines (34 loc) · 1.13 KB
/
SearchInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from 'react';
import { useTranslationContext } from '../../context/TranslationContext';
export type SearchInputController = {
/** Clears the channel search state */
clearState: () => void;
inputRef: React.RefObject<HTMLInputElement>;
/** Search input change handler */
onSearch: React.ChangeEventHandler<HTMLInputElement>;
/** Current search string */
query: string;
};
export type AdditionalSearchInputProps = {
/** Sets the input element into disabled state */
disabled?: boolean;
/** Custom placeholder text to be displayed in the search input */
placeholder?: string;
};
export type SearchInputProps = AdditionalSearchInputProps & SearchInputController;
export const SearchInput = (props: SearchInputProps) => {
const { disabled, inputRef, onSearch, placeholder, query } = props;
const { t } = useTranslationContext('SearchInput');
return (
<input
className='str-chat__channel-search-input'
data-testid='search-input'
disabled={disabled}
onChange={onSearch}
placeholder={placeholder ?? t('Search')}
ref={inputRef}
type='text'
value={query}
/>
);
};