@react-md/form
Version:
This package is for creating all the different form input types.
50 lines (49 loc) • 1.52 kB
TypeScript
import type { ChangeEventHandler, FocusEventHandler } from "react";
/**
* @internal
* @remarks \@since 2.5.2
*/
declare type FormElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
/**
* @internal
* @remarks \@since 2.5.2
*/
interface EventHandlers<E extends FormElement> {
onBlur?: FocusEventHandler<E>;
onFocus?: FocusEventHandler<E>;
onChange?: ChangeEventHandler<E>;
}
/**
* @internal
* @remarks \@since 2.5.2
*/
interface FieldStatesOptions<E extends FormElement> extends EventHandlers<E> {
value?: string | readonly string[];
defaultValue?: string | readonly string[];
}
/**
* @internal
* @remarks \@since 2.5.2
*/
interface ReturnValue<E extends FormElement> extends Required<EventHandlers<E>> {
/**
* Boolean if the TextField or TextArea current has a value with a `length > 0`
* so that any labels will correctly float above the text field. This will
* also make sure that number inputs will still be considered valued when
* there is a `badInput` validity error.
*/
valued: boolean;
/**
* Boolean if the TextField or TextArea currently has focus.
*/
focused: boolean;
}
/**
* This hook is used to handle the different states for the text field based on
* the current value and user interaction.
*
* @internal
* @remarks \@since 2.5.2
*/
export declare function useFieldStates<E extends FormElement>({ onBlur, onFocus, onChange, value, defaultValue, }: FieldStatesOptions<E>): ReturnValue<E>;
export {};