UNPKG

3.21 kBTypeScriptView Raw
1import * as React from 'react';
2import { FormControlState } from '../FormControl';
3export interface UseInputParameters {
4 /**
5 * The default value. Use when the component is not controlled.
6 */
7 defaultValue?: unknown;
8 /**
9 * If `true`, the component is disabled.
10 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
11 */
12 disabled?: boolean;
13 /**
14 * If `true`, the `input` will indicate an error by setting the `aria-invalid` attribute.
15 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
16 */
17 error?: boolean;
18 onBlur?: React.FocusEventHandler;
19 onClick?: React.MouseEventHandler;
20 onChange?: React.ChangeEventHandler<HTMLInputElement>;
21 onFocus?: React.FocusEventHandler;
22 inputRef?: React.Ref<HTMLInputElement>;
23 /**
24 * If `true`, the `input` element is required.
25 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
26 */
27 required?: boolean;
28 value?: unknown;
29}
30export interface UseInputRootSlotOwnProps {
31 onClick: React.MouseEventHandler | undefined;
32}
33export type UseInputRootSlotProps<TOther = {}> = Omit<TOther, keyof UseInputRootSlotOwnProps | 'onBlur' | 'onChange' | 'onFocus'> & UseInputRootSlotOwnProps;
34export interface UseInputInputSlotOwnProps {
35 'aria-invalid': React.AriaAttributes['aria-invalid'];
36 defaultValue: string | number | readonly string[] | undefined;
37 ref: React.RefCallback<HTMLInputElement> | null;
38 value: string | number | readonly string[] | undefined;
39 onBlur: React.FocusEventHandler;
40 onChange: React.ChangeEventHandler<HTMLInputElement>;
41 onFocus: React.FocusEventHandler;
42 required: boolean;
43 disabled: boolean;
44}
45export type UseInputInputSlotProps<TOther = {}> = Omit<TOther, keyof UseInputInputSlotOwnProps> & UseInputInputSlotOwnProps;
46export interface UseInputReturnValue {
47 /**
48 * If `true`, the component will be disabled.
49 */
50 disabled: boolean;
51 /**
52 * If `true`, the `input` will indicate an error by setting the `aria-invalid` attribute.
53 */
54 error: boolean;
55 /**
56 * If `true`, the `input` will be focused.
57 */
58 focused: boolean;
59 /**
60 * Return value from the `useFormControlContext` hook.
61 */
62 formControlContext: FormControlState | undefined;
63 /**
64 * Resolver for the input slot's props.
65 * @param externalProps props for the input slot
66 * @returns props that should be spread on the input slot
67 */
68 getInputProps: <TOther extends Record<string, any> = {}>(externalProps?: TOther) => UseInputInputSlotProps<TOther>;
69 /**
70 * Resolver for the root slot's props.
71 * @param externalProps props for the root slot
72 * @returns props that should be spread on the root slot
73 */
74 getRootProps: <TOther extends Record<string, any> = {}>(externalProps?: TOther) => UseInputRootSlotProps<TOther>;
75 inputRef: React.RefCallback<HTMLInputElement> | null;
76 /**
77 * If `true`, the `input` will indicate that it's required.
78 */
79 required: boolean;
80 /**
81 * The `value` of the `input` element.
82 */
83 value: unknown;
84}