Signed-off-by: Charles <charles.bourque96@gmail.com>
This commit is contained in:
Charles
2022-06-01 16:21:48 +01:00
parent e372a9c4a7
commit 276a469405
127 changed files with 3786 additions and 2304 deletions

View File

@@ -0,0 +1,48 @@
import React, { useCallback } from 'react';
import useFastField from 'hooks/useFastField';
import { FieldProps } from 'models/Form';
import Field from './FastToggleInput';
interface Props extends FieldProps {
defaultValue: object;
fieldsToDestroy?: string[];
}
const ConfigurationSubSectionToggle: React.FC<Props> = ({
name,
isDisabled = false,
label,
defaultValue,
isRequired = false,
definitionKey,
fieldsToDestroy,
}) => {
const { value, error, isError, onChange, onBlur, setFieldValue } = useFastField<object | undefined>({ name });
const onValueChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
if (!e.target.checked) {
onChange(undefined);
if (fieldsToDestroy) {
for (const field of fieldsToDestroy) {
setFieldValue(field, undefined);
}
}
} else onChange(defaultValue);
}, []);
return (
<Field
label={label ?? name}
value={value !== undefined}
onChange={onValueChange}
error={error}
onBlur={onBlur}
isError={isError}
isDisabled={isDisabled}
isRequired={isRequired}
definitionKey={definitionKey}
/>
);
};
export default React.memo(ConfigurationSubSectionToggle);