2022-06-06 13:53:02 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import { StyleSheet, TextInputProps, View } from 'react-native';
|
|
|
|
|
2022-09-23 02:03:02 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-06-06 13:53:02 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-06-27 18:46:59 +00:00
|
|
|
import { FormTextInput } from '../TextInput';
|
2022-06-06 13:53:02 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
inputContainer: {
|
|
|
|
margin: 16,
|
|
|
|
marginBottom: 16
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const SearchBox = ({ onChangeText, onSubmitEditing, testID }: TextInputProps): JSX.Element => {
|
|
|
|
const [text, setText] = useState('');
|
|
|
|
|
2022-09-23 02:03:02 +00:00
|
|
|
const { colors } = useTheme();
|
|
|
|
|
2023-08-18 17:48:33 +00:00
|
|
|
const internalOnChangeText = useCallback(value => {
|
2022-06-06 13:53:02 +00:00
|
|
|
setText(value);
|
|
|
|
onChangeText?.(value);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2022-09-23 02:03:02 +00:00
|
|
|
<View testID='searchbox' style={{ backgroundColor: colors.backgroundColor }}>
|
2022-06-06 13:53:02 +00:00
|
|
|
<FormTextInput
|
|
|
|
autoCapitalize='none'
|
|
|
|
autoCorrect={false}
|
|
|
|
blurOnSubmit
|
|
|
|
placeholder={I18n.t('Search')}
|
|
|
|
returnKeyType='search'
|
|
|
|
underlineColorAndroid='transparent'
|
|
|
|
containerStyle={styles.inputContainer}
|
|
|
|
onChangeText={internalOnChangeText}
|
|
|
|
onSubmitEditing={onSubmitEditing}
|
|
|
|
value={text}
|
|
|
|
testID={testID}
|
|
|
|
onClearInput={() => internalOnChangeText('')}
|
|
|
|
iconRight={'search'}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SearchBox;
|