2022-12-16 15:00:01 +01:00
|
|
|
import { NumberInput } from '@mantine/core';
|
2023-02-15 13:00:09 +01:00
|
|
|
import { INumber } from '../../../../typings/dialog';
|
2022-09-08 12:00:41 +02:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-02-13 21:24:33 +01:00
|
|
|
import { Control, useController } from 'react-hook-form';
|
2023-01-03 18:55:02 +01:00
|
|
|
import { FormValues } from '../../InputDialog';
|
2022-06-19 14:57:03 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2022-08-09 23:50:14 +02:00
|
|
|
row: INumber;
|
2022-06-19 14:57:03 +02:00
|
|
|
index: number;
|
2023-01-03 18:55:02 +01:00
|
|
|
control: Control<FormValues>;
|
2022-06-19 14:57:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-09 23:50:14 +02:00
|
|
|
const NumberField: React.FC<Props> = (props) => {
|
2023-01-03 18:55:02 +01:00
|
|
|
const controller = useController({
|
|
|
|
|
name: `test.${props.index}.value`,
|
|
|
|
|
control: props.control,
|
|
|
|
|
defaultValue: props.row.default,
|
2023-01-08 11:35:30 +01:00
|
|
|
rules: { required: props.row.required },
|
2023-01-03 18:55:02 +01:00
|
|
|
});
|
2022-08-05 15:10:37 +02:00
|
|
|
|
2022-06-19 14:57:03 +02:00
|
|
|
return (
|
2022-12-16 15:00:01 +01:00
|
|
|
<NumberInput
|
2023-01-03 18:55:02 +01:00
|
|
|
value={controller.field.value}
|
|
|
|
|
name={controller.field.name}
|
|
|
|
|
ref={controller.field.ref}
|
|
|
|
|
onBlur={controller.field.onBlur}
|
|
|
|
|
onChange={controller.field.onChange}
|
2022-12-16 15:00:01 +01:00
|
|
|
label={props.row.label}
|
|
|
|
|
description={props.row.description}
|
|
|
|
|
defaultValue={props.row.default}
|
|
|
|
|
min={props.row.min}
|
|
|
|
|
max={props.row.max}
|
|
|
|
|
disabled={props.row.disabled}
|
|
|
|
|
icon={props.row.icon && <FontAwesomeIcon icon={props.row.icon} fixedWidth />}
|
2023-01-08 11:35:30 +01:00
|
|
|
withAsterisk={props.row.required}
|
2022-12-16 15:00:01 +01:00
|
|
|
/>
|
2022-06-19 14:57:03 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-09 23:50:14 +02:00
|
|
|
export default NumberField;
|