Rocket.Chat.ReactNative/app/containers/SearchBox.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
2019-07-29 16:33:28 +00:00
import {
View, StyleSheet, TextInput, Text
} from 'react-native';
import PropTypes from 'prop-types';
2019-07-29 16:33:28 +00:00
import Touchable from 'react-native-platform-touchable';
import I18n from '../i18n';
2019-01-29 19:52:56 +00:00
import { isIOS } from '../utils/deviceInfo';
import { CustomIcon } from '../lib/Icons';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../views/Styles';
const styles = StyleSheet.create({
container: {
2019-07-29 16:33:28 +00:00
backgroundColor: isIOS ? '#F7F8FA' : '#54585E',
flexDirection: 'row',
alignItems: 'center',
flex: 1
},
searchBox: {
alignItems: 'center',
backgroundColor: '#E1E5E8',
borderRadius: 10,
color: '#8E8E93',
flexDirection: 'row',
fontSize: 17,
height: 36,
margin: 16,
marginVertical: 10,
2019-07-29 16:33:28 +00:00
paddingHorizontal: 10,
flex: 1
},
input: {
color: '#8E8E93',
flex: 1,
fontSize: 17,
marginLeft: 8,
paddingTop: 0,
2019-03-29 19:36:07 +00:00
paddingBottom: 0,
...sharedStyles.textRegular
2019-07-29 16:33:28 +00:00
},
cancel: {
marginRight: 10
},
cancelText: {
...sharedStyles.textRegular,
...sharedStyles.textColorHeaderBack,
fontSize: 17
}
});
2019-07-29 16:33:28 +00:00
const CancelButton = onCancelPress => (
<Touchable onPress={onCancelPress} style={styles.cancel}>
<Text style={styles.cancelText}>{I18n.t('Cancel')}</Text>
</Touchable>
);
const SearchBox = ({
2019-11-25 20:01:17 +00:00
onChangeText, onSubmitEditing, testID, hasCancel, onCancelPress, inputRef, ...props
2019-07-29 16:33:28 +00:00
}) => (
<View style={styles.container}>
<View style={styles.searchBox}>
<CustomIcon name='magnifier' size={14} color='#8E8E93' />
<TextInput
2019-11-25 20:01:17 +00:00
ref={inputRef}
autoCapitalize='none'
autoCorrect={false}
blurOnSubmit
clearButtonMode='while-editing'
placeholder={I18n.t('Search')}
returnKeyType='search'
style={styles.input}
testID={testID}
underlineColorAndroid='transparent'
onChangeText={onChangeText}
onSubmitEditing={onSubmitEditing}
2019-07-29 16:33:28 +00:00
{...props}
/>
</View>
2019-07-29 16:33:28 +00:00
{ hasCancel ? CancelButton(onCancelPress) : null }
</View>
);
SearchBox.propTypes = {
onChangeText: PropTypes.func.isRequired,
onSubmitEditing: PropTypes.func,
2019-07-29 16:33:28 +00:00
hasCancel: PropTypes.bool,
onCancelPress: PropTypes.func,
2019-11-25 20:01:17 +00:00
inputRef: PropTypes.func,
testID: PropTypes.string
};
export default SearchBox;