@devrue/rn-select
Version:
Custom typescript only select component for react native
83 lines • 3.27 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { useRef, useState } from 'react';
import { TextInput, View } from 'react-native';
import ChevronLeft from '../icons/ChevronLeftIcon';
import { Pressable } from 'react-native';
import Close from '../icons/CloseIcon';
import useStyles from '../hooks/useStyles';
export default function SearchBox({
onBackPress,
onChangeText,
placeholder,
searchContainerStyle,
searchInputStyle,
searchBackIconStyle,
searchClearIconStyle,
...rest
}) {
const ref = useRef(null);
const [value, setValue] = useState('');
const styles = useStyles(({
tokens: {
size
}
}) => ({
container: {
borderRadius: size.xs,
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: size.sm
},
inputWrapper: {
flex: 1,
height: size.xl
},
input: {
flex: 1,
backgroundColor: '#f9f9f9',
borderRadius: size.xs,
paddingRight: size.lg,
paddingLeft: size.sm
},
close: {
marginLeft: -size.lg,
width: (searchClearIconStyle === null || searchClearIconStyle === void 0 ? void 0 : searchClearIconStyle.fontSize) ?? size.md,
height: (searchClearIconStyle === null || searchClearIconStyle === void 0 ? void 0 : searchClearIconStyle.fontSize) ?? size.md
},
back: {
width: (searchBackIconStyle === null || searchBackIconStyle === void 0 ? void 0 : searchBackIconStyle.fontSize) ?? size.lg,
height: (searchBackIconStyle === null || searchBackIconStyle === void 0 ? void 0 : searchBackIconStyle.fontSize) ?? size.lg
}
}), []);
const clearText = () => {
var _ref$current;
(_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.clear();
setValue('');
onChangeText === null || onChangeText === void 0 || onChangeText('');
};
return /*#__PURE__*/React.createElement(View, {
style: [styles.container, searchContainerStyle]
}, onBackPress && /*#__PURE__*/React.createElement(Pressable, {
onPress: onBackPress
}, /*#__PURE__*/React.createElement(ChevronLeft, {
stroke: (searchBackIconStyle === null || searchBackIconStyle === void 0 ? void 0 : searchBackIconStyle.color) ?? '#c5c5c5',
style: styles.back
})), /*#__PURE__*/React.createElement(Pressable, {
style: styles.inputWrapper
}, /*#__PURE__*/React.createElement(TextInput, _extends({
ref: ref
}, rest, {
placeholder: placeholder ?? 'Search...',
style: [styles.input, searchInputStyle],
onChangeText: v => {
setValue(v);
onChangeText === null || onChangeText === void 0 || onChangeText(v);
}
}))), !!value && /*#__PURE__*/React.createElement(Pressable, {
onPress: clearText
}, /*#__PURE__*/React.createElement(Close, {
stroke: (searchClearIconStyle === null || searchClearIconStyle === void 0 ? void 0 : searchClearIconStyle.color) ?? '#c5c5c5',
style: styles.close
})));
}
//# sourceMappingURL=SearchBox.js.map