@td-design/react-native
Version:
react-native UI组件库
101 lines • 3.07 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, StyleSheet } 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 NumberKeyboardModal from './NumberKeyboardModal';
import useNumberKeyboard from './useNumberKeyboard';
const NumberKeyboardItem = /*#__PURE__*/forwardRef((_ref, ref) => {
let {
value,
onChange,
onCheck,
placeholder = '请输入',
disabled = false,
type,
style,
inputStyle,
extra,
allowClear = true,
digit = 0,
activeOpacity = 0.6,
inForm,
allowNegative = false,
...restProps
} = _ref;
const theme = useTheme();
const {
currentText,
handleSubmit,
handleInputClear
} = useNumberKeyboard({
value,
onChange,
onCheck,
digit,
type,
placeholder
});
const show = () => {
Keyboard.dismiss();
if (disabled) return;
Modal.show( /*#__PURE__*/React.createElement(NumberKeyboardModal, _extends({}, restProps, {
type,
value: currentText === placeholder ? '' : currentText,
onSubmit: handleSubmit,
activeOpacity,
allowNegative
})), {
position: 'bottom'
});
};
useImperativeHandle(ref, () => {
return {
focus: show
};
});
const styles = StyleSheet.create({
content: {
flexGrow: 1,
justifyContent: 'center'
},
clearIcon: {
alignItems: 'center'
}
});
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: styles.content
}, /*#__PURE__*/React.createElement(Text, {
variant: "p1",
color: currentText === placeholder ? 'gray300' : 'text',
textAlign: 'right',
style: inputStyle,
selectable: true
}, currentText)), allowClear && !disabled && !!currentText && currentText !== placeholder && /*#__PURE__*/React.createElement(Pressable, {
activeOpacity: 1,
onPress: handleInputClear,
hitOffset: 10,
style: styles.clearIcon
}, /*#__PURE__*/React.createElement(SvgIcon, {
name: "closecircleo",
color: theme.colors.icon
})), /*#__PURE__*/React.createElement(Brief, {
brief: extra
})));
});
NumberKeyboardItem.displayName = 'NumberKeyboardItem';
export default NumberKeyboardItem;
//# sourceMappingURL=NumberKeyboardItem.js.map