UNPKG

@kform/react

Version:

React integration for KForm.

41 lines (40 loc) 2.66 kB
import { Path } from "@kform/core"; import { Temporal } from "../utils/temporalUtils"; import { Controller } from "./useController"; import { FormatterControllerState } from "./useFormatter"; import { InputOptions, InputOwnController } from "./useInput"; /** * Options available to the {@link useTemporalInput} hook. */ export type TemporalInputOptions<T extends Temporal | null = Temporal | null, TFormatted = string, TInput = HTMLInputElement> = Omit<InputOptions<T, TFormatted, TInput>, "format" | "parse"> & TemporalInputOwnOptions<T, TFormatted, TInput>; /** * Own options available to the {@link useTemporalInput} hook. */ export interface TemporalInputOwnOptions<T extends Temporal | null = Temporal | null, TFormatted = string, TInput = HTMLInputElement> { formatFromString?: (stringValue: string, state: FormatterControllerState<T, TFormatted>, input: TInput | null) => TFormatted; parseToString?: (formattedValue: TFormatted, state: FormatterControllerState<T, TFormatted>, input: TInput | null) => string; } /** * 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 TemporalInputController<T extends Temporal | null = Temporal | null, TFormatted = string, TInput = HTMLInputElement> = Controller<T> & TemporalInputOwnController<TFormatted, TInput>; /** * Own temporal input controller. */ export type TemporalInputOwnController<TFormatted = string, TInput = HTMLInputElement> = InputOwnController<TFormatted, TInput>; /** * Hook controlling the integration between a temporal value (`Instant`, * `LocalDate`, `LocalDateTime`, or `Date`) of the form manager and an input of * the form. * @param path Path of the temporal form value to access, relative to the * current path. * @param options Available options. * @throws {InvalidPathError} When the schema at {@link path} is not temporal * (not `Instant`, `LocalDate`, `LocalDateTime`, or `Date`). * @returns A controller used to read and control the temporal form value * associated with the form input, exposing properties that should be set on the * input itself. */ export declare function useTemporalInput<T extends Temporal | null = Temporal | null, TFormatted = string, TInput = HTMLInputElement>(path?: Path | string, options?: undefined): TemporalInputController<T, TFormatted, TInput>; export declare function useTemporalInput<T extends Temporal | null = Temporal | null, TFormatted = string, TInput = HTMLInputElement>(path: Path | string | undefined, options: TemporalInputOptions<T, TFormatted, TInput>): TemporalInputController<T, TFormatted, TInput>;