diff --git a/src/components/AmountTextInput.js b/src/components/AmountTextInput.js deleted file mode 100644 index 231a99f0e6a6..000000000000 --- a/src/components/AmountTextInput.js +++ /dev/null @@ -1,89 +0,0 @@ -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 ( - - ); -} - -AmountTextInput.propTypes = propTypes; -AmountTextInput.defaultProps = defaultProps; -AmountTextInput.displayName = 'AmountTextInput'; - -const AmountTextInputWithRef = React.forwardRef((props, ref) => ( - -)); - -AmountTextInputWithRef.displayName = 'AmountTextInputWithRef'; - -export default AmountTextInputWithRef; diff --git a/src/components/AmountTextInput.tsx b/src/components/AmountTextInput.tsx new file mode 100644 index 000000000000..0f3416076cc0 --- /dev/null +++ b/src/components/AmountTextInput.tsx @@ -0,0 +1,64 @@ +import React from 'react'; +import type {StyleProp, TextStyle, ViewStyle} from 'react-native'; +import useThemeStyles from '@hooks/useThemeStyles'; +import CONST from '@src/CONST'; +import type {TextSelection} from './Composer/types'; +import TextInput from './TextInput'; +import type {BaseTextInputRef} from './TextInput/BaseTextInput/types'; + +type AmountTextInputProps = { + /** Formatted amount in local currency */ + formattedAmount: string; + + /** Function to call when amount in text input is changed */ + onChangeAmount: (amount: string) => void; + + /** Placeholder value for amount text input */ + placeholder: string; + + /** Selection Object */ + selection?: TextSelection; + + /** Function to call when selection in text input is changed */ + onSelectionChange?: () => void; + + /** Style for the input */ + style?: StyleProp; + + /** Style for the container */ + touchableInputWrapperStyle?: StyleProp; + + /** Function to call to handle key presses in the text input */ + onKeyPress?: () => void; +}; + +function AmountTextInput( + {formattedAmount, onChangeAmount, placeholder, selection, onSelectionChange, style, touchableInputWrapperStyle, onKeyPress}: AmountTextInputProps, + ref: BaseTextInputRef, +) { + const styles = useThemeStyles(); + return ( + + ); +} + +AmountTextInput.displayName = 'AmountTextInput'; + +export default React.forwardRef(AmountTextInput); diff --git a/src/components/TextInput/BaseTextInput/types.ts b/src/components/TextInput/BaseTextInput/types.ts index c627c0e99e5b..21875d4dcc64 100644 --- a/src/components/TextInput/BaseTextInput/types.ts +++ b/src/components/TextInput/BaseTextInput/types.ts @@ -24,7 +24,7 @@ type CustomBaseTextInputProps = { errorText?: MaybePhraseKey; /** Icon to display in right side of text input */ - icon: IconAsset | null; + icon?: IconAsset | null; /** Customize the TextInput container */ textInputContainerStyles?: StyleProp;