From b648a77c9b7d7f0f818153688779f2254060ee88 Mon Sep 17 00:00:00 2001 From: memoyil <2213635+memoyil@users.noreply.github.com> Date: Fri, 7 May 2021 07:19:33 +0200 Subject: [PATCH] fix: Add missing ios support for balance input (#75) * fix: Add missing ios support for balance input * fix: Test * fix: Test * fix: Format * fix: Remove inputmode from params, changedefault to decimal * fix: Add validations properly * fix: Type --- .../components/balanceinput.test.tsx | 6 ++- .../components/BalanceInput/BalanceInput.tsx | 18 +++++++- .../components/BalanceInput/index.stories.tsx | 44 ++++++++++++++----- .../src/components/BalanceInput/types.ts | 2 +- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/packages/pancake-uikit/src/__tests__/components/balanceinput.test.tsx b/packages/pancake-uikit/src/__tests__/components/balanceinput.test.tsx index e1d028d5c..dde005e53 100644 --- a/packages/pancake-uikit/src/__tests__/components/balanceinput.test.tsx +++ b/packages/pancake-uikit/src/__tests__/components/balanceinput.test.tsx @@ -5,7 +5,7 @@ import BalanceInput from "../../components/BalanceInput/BalanceInput"; const handleChange = jest.fn(); it("renders correctly", () => { - const { asFragment } = renderWithTheme(); + const { asFragment } = renderWithTheme(); expect(asFragment()).toMatchInlineSnapshot(` .c3 { @@ -100,9 +100,11 @@ it("renders correctly", () => { >
= ({ value, placeholder = "0.0", - onChange, + onUserInput, currencyValue, inputProps, isWarning = false, ...props }) => { + const handleOnChange = (e: React.ChangeEvent) => { + if (e.currentTarget.validity.valid) { + onUserInput(e.currentTarget.value.replace(/,/g, ".")); + } + }; + return ( - + {currencyValue && ( {currencyValue} diff --git a/packages/pancake-uikit/src/components/BalanceInput/index.stories.tsx b/packages/pancake-uikit/src/components/BalanceInput/index.stories.tsx index b486b4159..87c4429e7 100644 --- a/packages/pancake-uikit/src/components/BalanceInput/index.stories.tsx +++ b/packages/pancake-uikit/src/components/BalanceInput/index.stories.tsx @@ -9,27 +9,49 @@ export default { }; export const Default: React.FC = () => { - const [value, setValue] = useState(1.43333); - const currencyValue = `~${(value * 1.3).toLocaleString(undefined, { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })} USD`; + const [decimalValue, setDecimalValue] = useState(1.43333); + const [numericValue, setNumericValue] = useState(5); - const handleChange = (evt) => { - setValue(evt.target.value); + const currencyValue = (input: number) => { + return `~${(input * 1.3).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} USD`; + }; + + const handleDecimalChange = (input) => { + setDecimalValue(input); + }; + + const handleNumericChange = (input) => { + setNumericValue(input); }; return ( - + + ); }; diff --git a/packages/pancake-uikit/src/components/BalanceInput/types.ts b/packages/pancake-uikit/src/components/BalanceInput/types.ts index e94637155..c5359be44 100644 --- a/packages/pancake-uikit/src/components/BalanceInput/types.ts +++ b/packages/pancake-uikit/src/components/BalanceInput/types.ts @@ -3,7 +3,7 @@ import { BoxProps } from "../Box"; export interface BalanceInputProps extends BoxProps { value: ReactText; - onChange?: InputHTMLAttributes["onChange"]; + onUserInput: (input: string) => void; currencyValue?: ReactNode; placeholder?: string; inputProps?: Omit, "value" | "placeholder" | "onChange">;