@kform/react
Version:
React integration for KForm.
40 lines (39 loc) • 2.49 kB
TypeScript
import { File as KFormFile, Path } from "@kform/core";
import { Controller } from "./useController";
import { FormatterControllerState } from "./useFormatter";
import { InputOptions, InputOwnController } from "./useInput";
/**
* Options available to the {@link useFileInput} hook.
*/
export type FileInputOptions<T extends KFormFile | null = KFormFile | null, TFormatted = FileList, TInput = HTMLInputElement> = Omit<InputOptions<T, TFormatted, TInput>, "format" | "parse"> & FileInputOwnOptions<T, TFormatted, TInput>;
/**
* Own options available to the {@link useFileInput} hook.
*/
export interface FileInputOwnOptions<T extends KFormFile | null = KFormFile | null, TFormatted = FileList, TInput = HTMLInputElement> {
formatFromFileList?: (fileListValue: FileList, state: FormatterControllerState<T, TFormatted>, input: TInput | null) => TFormatted;
parseToFileList?: (formattedValue: TFormatted, state: FormatterControllerState<T, TFormatted>, input: TInput | null) => FileList;
}
/**
* Controller used to read and control the form value associated with the form
* input, exposing properties that should be set on the input itself.
*/
export type FileInputController<T extends KFormFile | null = KFormFile | null, TFormatted = FileList, TInput = HTMLInputElement> = Controller<T> & FileInputOwnController<TFormatted, TInput>;
/**
* Own file input controller.
*/
export interface FileInputOwnController<TFormatted = FileList, TInput = HTMLInputElement> extends InputOwnController<TFormatted, TInput> {
}
/**
* Hook controlling the integration between a file value of the form manager
* and an input of the form.
* @param path Path of the file form value to access, relative to the current
* path.
* @param options Available options.
* @throws {InvalidPathError} When the schema at {@link path} is not of file
* type.
* @returns A controller used to read and control the file form value associated
* with the form input, exposing properties that should be set on the input
* itself.
*/
export declare function useFileInput<T extends KFormFile | null = KFormFile | null, TFormatted = File, TInput = HTMLInputElement>(path?: Path | string, options?: undefined): FileInputController<T, TFormatted, TInput>;
export declare function useFileInput<T extends KFormFile | null = KFormFile | null, TFormatted = File, TInput = HTMLInputElement>(path: Path | string | undefined, options: FileInputOptions<T, TFormatted, TInput>): FileInputController<T, TFormatted, TInput>;