forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAmountTextInput.js
89 lines (74 loc) · 2.9 KB
/
AmountTextInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import PropTypes from 'prop-types';
import React from 'react';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import refPropTypes from './refPropTypes';
import TextInput from './TextInput';
const propTypes = {
/** Formatted amount in local currency */
formattedAmount: PropTypes.string.isRequired,
/** A ref to forward to amount text input */
forwardedRef: refPropTypes,
/** Function to call when amount in text input is changed */
onChangeAmount: PropTypes.func.isRequired,
/** Placeholder value for amount text input */
placeholder: PropTypes.string.isRequired,
/** Selection Object */
selection: PropTypes.shape({
start: PropTypes.number,
end: PropTypes.number,
}),
/** Function to call when selection in text input is changed */
onSelectionChange: PropTypes.func,
/** Style for the input */
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),
/** Style for the container */
touchableInputWrapperStyle: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]),
/** Function to call to handle key presses in the text input */
onKeyPress: PropTypes.func,
};
const defaultProps = {
forwardedRef: undefined,
selection: undefined,
onSelectionChange: () => {},
onKeyPress: () => {},
style: {},
touchableInputWrapperStyle: {},
};
function AmountTextInput(props) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
return (
<TextInput
disableKeyboard
autoGrow
hideFocusedState
inputStyle={[styles.iouAmountTextInput, styles.p0, styles.noLeftBorderRadius, styles.noRightBorderRadius, ...StyleUtils.parseStyleAsArray(props.style)]}
textInputContainerStyles={[styles.borderNone, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
onChangeText={props.onChangeAmount}
ref={props.forwardedRef}
value={props.formattedAmount}
placeholder={props.placeholder}
inputMode={CONST.INPUT_MODE.NUMERIC}
blurOnSubmit={false}
selection={props.selection}
onSelectionChange={props.onSelectionChange}
role={CONST.ROLE.PRESENTATION}
onKeyPress={props.onKeyPress}
touchableInputWrapperStyle={props.touchableInputWrapperStyle}
/>
);
}
AmountTextInput.propTypes = propTypes;
AmountTextInput.defaultProps = defaultProps;
AmountTextInput.displayName = 'AmountTextInput';
const AmountTextInputWithRef = React.forwardRef((props, ref) => (
<AmountTextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
forwardedRef={ref}
/>
));
AmountTextInputWithRef.displayName = 'AmountTextInputWithRef';
export default AmountTextInputWithRef;