.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">;