import React from 'react';
|
import { NumberInput } from 'react-admin';
|
import { maxDecimalPlaces } from '@/utils/common';
|
|
const MAX_DECIMALS = 6;
|
const QUANTITY_VALIDATE = [maxDecimalPlaces(MAX_DECIMALS, '最多6位小数')];
|
|
/**
|
* 数量输入框:支持最多 6 位小数,超过时提示并阻止提交
|
*/
|
const QuantityInput = (props) => {
|
const { validate = [], helperText, ...rest } = props;
|
const mergedValidate = Array.isArray(validate) ? [...QUANTITY_VALIDATE, ...validate] : [...QUANTITY_VALIDATE, validate];
|
return (
|
<NumberInput
|
validate={mergedValidate}
|
helperText={helperText ?? '最多6位小数'}
|
{...rest}
|
/>
|
);
|
};
|
|
export default QuantityInput;
|