@react-input/core
Version:
The core of the packages included in the `@react-input` scope.
33 lines (32 loc) • 1.09 kB
TypeScript
export type InputType = 'insert' | 'deleteBackward' | 'deleteForward';
export type InitFunction<T> = (param: {
initialValue: string;
controlled: boolean;
}) => {
value: string;
options: T;
};
export type TrackingFunction<T> = (param: {
inputType: InputType;
previousValue: string;
previousOptions: T;
value: string;
addedValue: string;
changeStart: number;
changeEnd: number;
selectionStart: number;
selectionEnd: number;
}) => {
value: string;
selectionStart: number;
selectionEnd: number;
options: T;
};
export interface InputOptions<T = unknown> {
init: InitFunction<T>;
tracking: TrackingFunction<T>;
}
export type InputComponentProps<C extends React.ComponentType | undefined = undefined> = {
component?: C;
} & (C extends React.ComponentType<infer P> ? P : React.InputHTMLAttributes<HTMLInputElement>);
export type InputComponent<P extends object> = <C extends React.ComponentType<any> | undefined = undefined>(props: P & InputComponentProps<C> & React.RefAttributes<HTMLInputElement>) => React.JSX.Element;