@td-design/react-native
Version:
react-native UI组件库
91 lines • 2.78 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, { forwardRef } from 'react';
import { StyleSheet, TextInput } from 'react-native';
import { useTheme } from '@shopify/restyle';
import Box from '../box';
import Flex from '../flex';
import helpers from '../helpers';
import Pressable from '../pressable';
import SvgIcon from '../svg-icon';
import useInputItem from './useInputItem';
const {
px
} = helpers;
const InputItem = /*#__PURE__*/forwardRef((_ref, ref) => {
let {
inputType = 'input',
left,
right,
inputStyle,
editable = true,
allowClear = true,
value,
onChange,
onClear,
style,
defaultValue,
inForm,
...restProps
} = _ref;
const theme = useTheme();
const {
inputValue,
eyeOpen,
handleChange,
handleInputClear,
triggerPasswordType
} = useInputItem({
inputType,
value,
defaultValue,
onChange,
onClear
});
const styles = StyleSheet.create({
input: {
paddingHorizontal: theme.spacing.x0,
paddingVertical: theme.spacing.x2,
fontSize: px(14),
color: theme.colors.text
}
});
return /*#__PURE__*/React.createElement(Flex, {
flexGrow: 1,
paddingHorizontal: inForm ? 'x0' : 'x1',
style: style
}, left, /*#__PURE__*/React.createElement(Box, {
flexGrow: 1
}, /*#__PURE__*/React.createElement(TextInput, _extends({
ref: ref,
textAlignVertical: "center",
autoCapitalize: "none",
autoCorrect: false,
autoComplete: "off",
style: [styles.input, inputStyle],
editable: editable,
placeholderTextColor: theme.colors.gray300,
selectionColor: theme.colors.primary200,
value: inputValue,
onChangeText: handleChange,
secureTextEntry: eyeOpen,
multiline: false,
underlineColorAndroid: "transparent"
}, restProps))), inputType === 'password' && /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: 1,
onPress: triggerPasswordType,
hitOffset: 10
}, /*#__PURE__*/React.createElement(SvgIcon, {
name: eyeOpen ? 'eyeclose' : 'eyeopen',
color: theme.colors.icon
})), allowClear && editable && !!inputValue && /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: 1,
onPress: handleInputClear,
hitOffset: 10
}, /*#__PURE__*/React.createElement(SvgIcon, {
name: "closecircleo",
color: theme.colors.icon
})), right);
});
InputItem.displayName = 'InputItem';
export default InputItem;
//# sourceMappingURL=InputItem.js.map