import classNames from 'classnames'; import {__} from '@wordpress/i18n'; import CurrencyInput from 'react-currency-input-field'; import {CurrencyInputOnChangeValues} from 'react-currency-input-field/dist/components/CurrencyInputProps'; import {useEffect, useRef} from "react"; /** * @since 3.0.0 */ type CustomAmountProps = { fieldError?: string; currency?: string; currencySymbol?: string; defaultValue?: string; value?: string; onValueChange?: (value: string, name?: string, values?: CurrencyInputOnChangeValues) => void; }; const formatter = new Intl.NumberFormat(navigator.language); const groupSeparator = formatter.format(1000).replace(/[0-9]/g, ''); const decimalSeparator = formatter.format(1.1).replace(/[0-9]/g, ''); /** * @since 4.3.0 add module styles to override currency-input placeholder styling. * @since 3.0.0 */ const CustomAmount = ({defaultValue, fieldError, currency, value, onValueChange}: CustomAmountProps) => { const ref = useRef(null); useEffect(() => { if (fieldError && ref.current) { ref.current.focus(); } }, [fieldError]); return (
{ onValueChange(value !== undefined ? value : ''); }} />
); }; export default CustomAmount;