35 lines
797 B
TypeScript
35 lines
797 B
TypeScript
import type { InputNumberProps } from 'antd';
|
|
import { Form, InputNumber } from 'antd';
|
|
import type { BaseElementProps } from './types';
|
|
|
|
const { Item: FormItem } = Form;
|
|
|
|
const parser = (val?: string): number => {
|
|
const res = val?.replace(/[^0-9.,]+/, '');
|
|
if (!res || res === '') return 0;
|
|
return parseFloat(res);
|
|
};
|
|
|
|
export default function Element({
|
|
value = 0,
|
|
setValue,
|
|
status,
|
|
isValid,
|
|
help,
|
|
...props
|
|
}: BaseElementProps<number>) {
|
|
return (
|
|
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
|
<InputNumber
|
|
defaultValue={value}
|
|
onChange={(val) => setValue(val)}
|
|
disabled={status === 'Disabled'}
|
|
parser={parser}
|
|
{...props}
|
|
/>
|
|
</FormItem>
|
|
);
|
|
}
|
|
|
|
export type { InputNumberProps };
|