telegram-crawler/data/mini_app/wallet/src/components/NumericInput.tsx

66 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-09-15 11:59:27 +02:00
import { forwardRef } from 'react';
const NON_WESTERN_DIGITS: {
[key: string]: string;
} = {
'٠': '0',
'١': '1',
'٢': '2',
'٣': '3',
'٤': '4',
'٥': '5',
'٦': '6',
'٧': '7',
'٨': '8',
'٩': '9',
'٫': '.',
'،': '.', // Arabic
'': '0',
'१': '1',
'२': '2',
'३': '3',
'४': '4',
'५': '5',
'६': '6',
'७': '7',
'८': '8',
'९': '9',
'।': '.', // Hindi
'': '0',
'১': '1',
'২': '2',
'৩': '3',
'': '4',
'৫': '5',
'৬': '6',
'': '7',
'৮': '8',
'৯': '9', // Bengali
};
export const NumericInput = forwardRef<
HTMLInputElement,
React.InputHTMLAttributes<HTMLInputElement>
>((props, ref) => {
return (
<input
ref={ref}
{...props}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;
const newValue = value
.split('')
.map((char) => NON_WESTERN_DIGITS[char] || char)
.join('');
event.target.value = newValue;
if (props.onChange) {
props.onChange(event);
}
}}
/>
);
});