23 lines
612 B
TypeScript
23 lines
612 B
TypeScript
import type { PropsPlugin } from '../../../../../types/component-plugin';
|
|
import type { InputUIProps } from '../InputUI';
|
|
import type { InputValidator } from '../types';
|
|
|
|
export const trimInputValuePlugin =
|
|
(): PropsPlugin<InputUIProps> =>
|
|
(props) => ({
|
|
...props,
|
|
onBlur: (event) => {
|
|
event.target.value = event.target.value.trim();
|
|
props.onBlur?.(event);
|
|
},
|
|
});
|
|
|
|
export const createValidInputPlugin =
|
|
(onValid: InputValidator) =>
|
|
({ nextValue, previousValue, timing }: Parameters<InputValidator>[0]) =>
|
|
onValid({
|
|
nextValue,
|
|
previousValue,
|
|
timing,
|
|
});
|