A local-first personal finance app
[Maintenance] Refactor amount input to typescript (#1936)
Kyle Mckay849262c95e54
diff --git a/packages/desktop-client/src/components/common/InputWithContent.tsx b/packages/desktop-client/src/components/common/InputWithContent.tsxindex 058c311613..6321a7d857 100644--- a/packages/desktop-client/src/components/common/InputWithContent.tsx+++ b/packages/desktop-client/src/components/common/InputWithContent.tsx@@ -6,8 +6,8 @@ import Input, { defaultInputStyle } from './Input';import View from './View';type InputWithContentProps = ComponentProps<typeof Input> & {- leftContent: ReactNode;- rightContent: ReactNode;+ leftContent?: ReactNode;+ rightContent?: ReactNode;inputStyle?: CSSProperties;focusStyle?: CSSProperties;style?: CSSProperties;diff --git a/packages/desktop-client/src/components/util/AmountInput.js b/packages/desktop-client/src/components/util/AmountInput.tsxsimilarity index 85%rename from packages/desktop-client/src/components/util/AmountInput.jsrename to packages/desktop-client/src/components/util/AmountInput.tsxindex bc59bf268e..a002cb5bf7 100644--- a/packages/desktop-client/src/components/util/AmountInput.js+++ b/packages/desktop-client/src/components/util/AmountInput.tsx@@ -1,4 +1,4 @@-import React, { useRef, useState } from 'react';+import React, { type MutableRefObject, useRef, useState } from 'react';import evalArithmetic from 'loot-core/src/shared/arithmetic';import { amountToInteger } from 'loot-core/src/shared/util';@@ -6,12 +6,24 @@ import { amountToInteger } from 'loot-core/src/shared/util';import { useMergedRefs } from '../../hooks/useMergedRefs';import Add from '../../icons/v1/Add';import Subtract from '../../icons/v1/Subtract';-import { theme } from '../../style';+import { type CSSProperties, theme } from '../../style';import Button from '../common/Button';import InputWithContent from '../common/InputWithContent';import View from '../common/View';import useFormat from '../spreadsheet/useFormat';+type AmountInputProps = {+ id?: string;+ inputRef?: MutableRefObject<HTMLInputElement>;+ initialValue: number;+ zeroSign?: '-' | '+';+ onChange?: (value: number) => void;+ onBlur?: () => void;+ style?: CSSProperties;+ textStyle?: CSSProperties;+ focused?: boolean;+};+export function AmountInput({id,inputRef,@@ -22,7 +34,7 @@ export function AmountInput({style,textStyle,focused,-}) {+}: AmountInputProps) {let format = useFormat();let [negative, setNegative] = useState((initialValue === 0 && zeroSign === '-') || initialValue < 0,@@ -49,8 +61,8 @@ export function AmountInput({setValue(value ? value : '');}- let ref = useRef();- let mergedRef = useMergedRefs(inputRef, ref);+ let ref = useRef<HTMLInputElement>();+ let mergedRef = useMergedRefs<HTMLInputElement>(inputRef, ref);function onInputAmountBlur(e) {fireChange(value, negative);diff --git a/upcoming-release-notes/1936.md b/upcoming-release-notes/1936.mdnew file mode 100644index 0000000000..6f1da6f284--- /dev/null+++ b/upcoming-release-notes/1936.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [kymckay]+---++Refactor AmountInput component to TypeScript.