-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathAmountTextInput.js
66 lines (56 loc) · 2.07 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
import React from 'react';
import PropTypes from 'prop-types';
import TextInput from './TextInput';
import styles from '../styles/styles';
import CONST from '../CONST';
const propTypes = {
/** Formatted amount in local currency */
formattedAmount: PropTypes.string.isRequired,
/** A ref to forward to amount text input */
forwardedRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}),
]),
/** 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,
};
const defaultProps = {
forwardedRef: undefined,
selection: undefined,
onSelectionChange: () => {},
};
function AmountTextInput(props) {
return (
<TextInput
disableKeyboard
autoGrow
hideFocusedState
inputStyle={[styles.iouAmountTextInput, styles.p0, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
textInputContainerStyles={[styles.borderNone, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
onChangeText={props.onChangeAmount}
ref={props.forwardedRef}
value={props.formattedAmount}
placeholder={props.placeholder}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
blurOnSubmit={false}
selection={props.selection}
onSelectionChange={props.onSelectionChange}
/>
);
}
AmountTextInput.propTypes = propTypes;
AmountTextInput.defaultProps = defaultProps;
AmountTextInput.displayName = 'AmountTextInput';
export default React.forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<AmountTextInput {...props} forwardedRef={ref} />
));