@td-design/react-native
Version:
react-native UI组件库
92 lines • 2.91 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, useImperativeHandle } from 'react';
import { Keyboard } from 'react-native';
import { useTheme } from '@shopify/restyle';
import Box from '../box';
import Brief from '../brief';
import Flex from '../flex';
import Modal from '../modal';
import Pressable from '../pressable';
import SvgIcon from '../svg-icon';
import Text from '../text';
import useVehicleKeyboard from './useVehicleKeyboard';
import VehicleKeyboardModal from './VehicleKeyboardModal';
const VehicleKeyboardItem = /*#__PURE__*/forwardRef((_ref, ref) => {
let {
value,
onChange,
onCheck,
placeholder = '请输入',
disabled = false,
style,
inputStyle,
extra,
allowClear = true,
activeOpacity = 0.6,
inForm,
...restProps
} = _ref;
const theme = useTheme();
const {
currentText,
handleSubmit,
handleInputClear
} = useVehicleKeyboard({
value,
onChange,
onCheck,
placeholder
});
const show = () => {
Keyboard.dismiss();
if (disabled) return;
Modal.show( /*#__PURE__*/React.createElement(VehicleKeyboardModal, _extends({}, restProps, {
value: currentText === placeholder ? '' : currentText,
onSubmit: handleSubmit,
activeOpacity
})), {
position: 'bottom'
});
};
useImperativeHandle(ref, () => {
return {
focus: show
};
});
return /*#__PURE__*/React.createElement(Box, {
width: "100%",
paddingHorizontal: inForm ? 'x0' : 'x1',
justifyContent: 'center',
style: style
}, /*#__PURE__*/React.createElement(Flex, null, /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: activeOpacity,
onPress: show,
style: [{
flexGrow: 1,
paddingVertical: theme.spacing.x2,
justifyContent: 'center'
}]
}, /*#__PURE__*/React.createElement(Text, {
variant: "p1",
color: currentText === placeholder ? 'gray300' : 'text',
style: [{
textAlign: 'right'
}, inputStyle],
selectable: true
}, currentText)), allowClear && !disabled && !!currentText && currentText !== placeholder && /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: 1,
onPress: handleInputClear,
hitOffset: 10,
style: {
alignItems: 'center'
}
}, /*#__PURE__*/React.createElement(SvgIcon, {
name: "closecircleo",
color: theme.colors.icon
})), /*#__PURE__*/React.createElement(Brief, {
brief: extra
})));
});
VehicleKeyboardItem.displayName = 'VehicleKeyboardItem';
export default VehicleKeyboardItem;
//# sourceMappingURL=VehicleKeyboardItem.js.map