Skip to content

Commit

Permalink
Add support for negative amounts in BaseTextInputWithCurrencySymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
pasyukevich committed Feb 6, 2025
1 parent 588d50c commit 278761a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AmountTextInput from '@components/AmountTextInput';
import CurrencySymbolButton from '@components/CurrencySymbolButton';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Text from '@src/components/Text';

Check failure on line 7 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Delete `Text·from·'@src/components/Text';⏎import·`

Check failure on line 7 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Delete `Text·from·'@src/components/Text';⏎import·`
import * as CurrencyUtils from '@libs/CurrencyUtils';

Check failure on line 8 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';

Check failure on line 9 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"

Check failure on line 9 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `';⏎import·Text·from·'@src/components/Text`

Check failure on line 9 in src/components/TextInputWithCurrencySymbol/BaseTextInputWithCurrencySymbol.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `';⏎import·Text·from·'@src/components/Text`
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types';
Expand All @@ -22,6 +23,7 @@ function BaseTextInputWithCurrencySymbol(
isCurrencyPressable = true,
hideCurrencySymbol = false,
extraSymbol,
isNegative = false,
style,
...rest
}: BaseTextInputWithCurrencySymbolProps,
Expand Down Expand Up @@ -67,9 +69,12 @@ function BaseTextInputWithCurrencySymbol(
/>
);

const negativeSymbol = <Text style={[styles.iouAmountText]}>-</Text>;

if (isCurrencySymbolLTR) {
return (
<>
{isNegative && negativeSymbol}
{currencySymbolButton}
{amountTextInput}
{extraSymbol}
Expand All @@ -79,6 +84,7 @@ function BaseTextInputWithCurrencySymbol(

return (
<>
{isNegative && negativeSymbol}
{amountTextInput}
{currencySymbolButton}
{extraSymbol}
Expand Down
3 changes: 3 additions & 0 deletions src/components/TextInputWithCurrencySymbol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type BaseTextInputWithCurrencySymbolProps = {

/** Hide the focus styles on TextInput */
hideFocusedState?: boolean;

/** Whether the amount is negative */
isNegative?: boolean;
} & Pick<BaseTextInputProps, 'autoFocus' | 'autoGrow' | 'autoGrowExtraSpace' | 'contentWidth' | 'onPress'>;

type TextInputWithCurrencySymbolProps = Omit<BaseTextInputWithCurrencySymbolProps, 'onSelectionChange'> & {
Expand Down

0 comments on commit 278761a

Please sign in to comment.