Local modifications to ClusterLabs/Anvil by Alteeve
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
726 B

import { ChangeEventHandler } from 'react';
import MAP_TO_VALUE_CONVERTER from './consts/MAP_TO_VALUE_CONVERTER';
const createInputOnChangeHandler =
<TypeName extends keyof MapToInputType>({
postSet,
preSet,
set,
setType = 'string' as TypeName,
valueKey = 'value',
}: CreateInputOnChangeHandlerOptions<TypeName> = {}): ChangeEventHandler<HTMLInputElement> =>
(event) => {
const {
target: { [valueKey]: value },
} = event;
const postConvertValue = MAP_TO_VALUE_CONVERTER[setType](
value,
) as MapToInputType[TypeName];
preSet?.call(null, event);
set?.call(null, postConvertValue);
postSet?.call(null, event);
};
export default createInputOnChangeHandler;