2022-06-19 14:57:03 +02:00
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
NumberInput,
|
|
|
|
|
NumberInputField,
|
|
|
|
|
NumberInputStepper,
|
|
|
|
|
NumberIncrementStepper,
|
|
|
|
|
NumberDecrementStepper,
|
2022-09-08 12:00:41 +02:00
|
|
|
InputLeftElement,
|
2022-08-27 15:58:36 +02:00
|
|
|
} from '@chakra-ui/react';
|
|
|
|
|
import { useEffect } from 'react';
|
2022-10-27 14:22:15 +02:00
|
|
|
import { INumber } from '../../../../interfaces/dialog';
|
2022-09-08 12:00:41 +02:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2022-10-27 14:22:15 +02:00
|
|
|
import Label from '../Label';
|
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;
|
2022-08-09 23:50:14 +02:00
|
|
|
handleChange: (value: number, index: number) => void;
|
2022-06-19 14:57:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-09 23:50:14 +02:00
|
|
|
const NumberField: React.FC<Props> = (props) => {
|
2022-08-05 15:10:37 +02:00
|
|
|
useEffect(() => {
|
2022-08-27 15:54:43 +02:00
|
|
|
if (props.row.default) props.handleChange(props.row.default, props.index);
|
2022-08-05 15:10:37 +02:00
|
|
|
}, []);
|
|
|
|
|
|
2022-06-19 14:57:03 +02:00
|
|
|
return (
|
|
|
|
|
<Box mb={3}>
|
2022-10-27 13:45:27 +02:00
|
|
|
<Label label={props.row.label} description={props.row.description} />
|
2022-08-27 15:54:43 +02:00
|
|
|
<NumberInput
|
|
|
|
|
onChange={(val: string) => props.handleChange(+val, props.index)}
|
|
|
|
|
defaultValue={props.row.default}
|
|
|
|
|
min={props.row.min}
|
|
|
|
|
max={props.row.max}
|
2022-10-27 03:17:53 -04:00
|
|
|
isDisabled={props.row.disabled}
|
2022-08-27 15:54:43 +02:00
|
|
|
>
|
2022-09-08 12:00:41 +02:00
|
|
|
{props.row.icon && (
|
|
|
|
|
<InputLeftElement pointerEvents="none" children={<FontAwesomeIcon icon={props.row.icon} fixedWidth />} />
|
|
|
|
|
)}
|
|
|
|
|
<NumberInputField placeholder={props.row.placeholder} pl={props.row.icon ? '40px' : undefined} />
|
2022-06-19 14:57:03 +02:00
|
|
|
<NumberInputStepper>
|
|
|
|
|
<NumberIncrementStepper />
|
|
|
|
|
<NumberDecrementStepper />
|
|
|
|
|
</NumberInputStepper>
|
|
|
|
|
</NumberInput>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-09 23:50:14 +02:00
|
|
|
export default NumberField;
|