@td-design/react-native
Version:
react-native UI组件库
118 lines • 3.6 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 Label from '../label';
import Pressable from '../pressable';
import SvgIcon from '../svg-icon';
import useInput from './useInput';
const {
ONE_PIXEL,
px
} = helpers;
const Input = /*#__PURE__*/forwardRef((_ref, ref) => {
let {
label,
labelPosition = 'left',
left,
right,
inputType = 'input',
inputStyle,
disabled = false,
allowClear = true,
value,
onChange,
onClear,
colon = false,
required = false,
style,
defaultValue,
itemHeight,
...restProps
} = _ref;
const theme = useTheme();
const {
inputValue,
eyeOpen,
handleChange,
handleInputClear,
triggerPasswordType
} = useInput({
inputType,
value,
defaultValue,
onChange,
onClear
});
const styles = StyleSheet.create({
input: {
paddingHorizontal: theme.spacing.x1,
paddingVertical: theme.spacing.x2,
fontSize: px(14),
color: theme.colors.text,
includeFontPadding: false,
textAlignVertical: 'center'
}
});
const InputContent = /*#__PURE__*/React.createElement(Flex, {
borderWidth: ONE_PIXEL,
borderColor: "border",
borderRadius: "x1",
position: "relative",
paddingHorizontal: 'x1',
flex: 1,
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: [itemHeight ? {
height: itemHeight
} : {}, styles.input, inputStyle],
editable: !disabled,
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 && !disabled && !!inputValue && /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: 1,
onPress: handleInputClear,
hitOffset: 10
}, /*#__PURE__*/React.createElement(SvgIcon, {
name: "closecircleo",
color: theme.colors.icon
})), right);
return labelPosition === 'left' ? /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Flex, {
alignItems: "center"
}, /*#__PURE__*/React.createElement(Label, {
colon,
label,
required
}), InputContent)) : /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Label, {
colon,
label,
required
}), InputContent);
});
Input.displayName = 'Input';
export default Input;
export { default as InputItem } from './InputItem';
export { default as TextArea } from './TextArea';
//# sourceMappingURL=index.js.map