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.
25 lines
696 B
25 lines
696 B
import { InputProps as MUIInputProps } from '@mui/material'; |
|
|
|
import MAP_TO_VALUE_CONVERTER from './consts/MAP_TO_VALUE_CONVERTER'; |
|
|
|
const createInputOnChangeHandler = |
|
<TypeName extends keyof MapToInputType>({ |
|
postSet, |
|
preSet, |
|
set, |
|
setType = 'string' as TypeName, |
|
}: CreateInputOnChangeHandlerOptions<TypeName> = {}): MUIInputProps['onChange'] => |
|
(event) => { |
|
const { |
|
target: { 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;
|
|
|