Skip to content

Commit

Permalink
Merge pull request #33955 from software-mansion-labs/ts-amount-text-i…
Browse files Browse the repository at this point in the history
…nput

[TS migration] Migrate 'AmountTextInput' component to TypeScript
  • Loading branch information
blimpich authored Jan 8, 2024
2 parents b9c2514 + 242113c commit 30a91a7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 90 deletions.
89 changes: 0 additions & 89 deletions src/components/AmountTextInput.js

This file was deleted.

64 changes: 64 additions & 0 deletions src/components/AmountTextInput.tsx
Original file line number Diff line number Diff line change
@@ -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<TextStyle>;

/** Style for the container */
touchableInputWrapperStyle?: StyleProp<ViewStyle>;

/** 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 (
<TextInput
disableKeyboard
autoGrow
hideFocusedState
inputStyle={[styles.iouAmountTextInput, styles.p0, styles.noLeftBorderRadius, styles.noRightBorderRadius, style]}
textInputContainerStyles={[styles.borderNone, styles.noLeftBorderRadius, styles.noRightBorderRadius]}
onChangeText={onChangeAmount}
ref={ref}
value={formattedAmount}
placeholder={placeholder}
inputMode={CONST.INPUT_MODE.NUMERIC}
blurOnSubmit={false}
selection={selection}
onSelectionChange={onSelectionChange}
role={CONST.ROLE.PRESENTATION}
onKeyPress={onKeyPress}
touchableInputWrapperStyle={touchableInputWrapperStyle}
/>
);
}

AmountTextInput.displayName = 'AmountTextInput';

export default React.forwardRef(AmountTextInput);
2 changes: 1 addition & 1 deletion src/components/TextInput/BaseTextInput/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewStyle>;
Expand Down

0 comments on commit 30a91a7

Please sign in to comment.