UNPKG

6.12 kBTypeScriptView Raw
1import * as React from 'react';
2import { Simplify } from '@mui/types';
3import { FormControlState } from '../FormControl';
4import { UseInputParameters, UseInputRootSlotProps } from '../useInput';
5import { PolymorphicProps, SlotComponentProps } from '../utils';
6export interface InputRootSlotPropsOverrides {
7}
8export interface InputInputSlotPropsOverrides {
9}
10export interface SingleLineInputProps {
11 /**
12 * Maximum number of rows to display when multiline option is set to true.
13 */
14 maxRows?: undefined;
15 /**
16 * Minimum number of rows to display when multiline option is set to true.
17 */
18 minRows?: undefined;
19 /**
20 * If `true`, a `textarea` element is rendered.
21 * @default false
22 */
23 multiline?: false;
24 /**
25 * Number of rows to display when multiline option is set to true.
26 */
27 rows?: undefined;
28 /**
29 * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
30 * @default 'text'
31 */
32 type?: React.HTMLInputTypeAttribute;
33}
34export interface MultiLineInputProps {
35 /**
36 * Maximum number of rows to display when multiline option is set to true.
37 */
38 maxRows?: number;
39 /**
40 * Minimum number of rows to display when multiline option is set to true.
41 */
42 minRows?: number;
43 /**
44 * If `true`, a `textarea` element is rendered.
45 * @default false
46 */
47 multiline: true;
48 /**
49 * Number of rows to display when multiline option is set to true.
50 */
51 rows?: number;
52 /**
53 * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
54 * @default 'text'
55 */
56 type?: undefined;
57}
58export type InputOwnProps = (SingleLineInputProps | MultiLineInputProps) & Omit<UseInputParameters, 'error'> & {
59 'aria-describedby'?: string;
60 'aria-label'?: string;
61 'aria-labelledby'?: string;
62 /**
63 * This prop helps users to fill forms faster, especially on mobile devices.
64 * The name can be confusing, as it's more like an autofill.
65 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
66 */
67 autoComplete?: string;
68 /**
69 * If `true`, the `input` element is focused during the first mount.
70 */
71 autoFocus?: boolean;
72 /**
73 * Class name applied to the root element.
74 */
75 className?: string;
76 /**
77 * Trailing adornment for this input.
78 */
79 endAdornment?: React.ReactNode;
80 /**
81 * If `true`, the `input` will indicate an error by setting the `aria-invalid` attribute on the input and the `Mui-error` class on the root element.
82 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
83 */
84 error?: boolean;
85 /**
86 * The id of the `input` element.
87 */
88 id?: string;
89 /**
90 * Name attribute of the `input` element.
91 */
92 name?: string;
93 onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
94 onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
95 /**
96 * The short hint displayed in the `input` before the user enters a value.
97 */
98 placeholder?: string;
99 /**
100 * It prevents the user from changing the value of the field
101 * (not from interacting with the field).
102 */
103 readOnly?: boolean;
104 /**
105 * The props used for each slot inside the Input.
106 * @default {}
107 */
108 slotProps?: {
109 root?: SlotComponentProps<'div', InputRootSlotPropsOverrides, InputOwnerState>;
110 input?: SlotComponentProps<'input', InputInputSlotPropsOverrides, InputOwnerState>;
111 };
112 /**
113 * The components used for each slot inside the InputBase.
114 * Either a string to use a HTML element or a component.
115 * @default {}
116 */
117 slots?: InputSlots;
118 /**
119 * Leading adornment for this input.
120 */
121 startAdornment?: React.ReactNode;
122 /**
123 * The value of the `input` element, required for a controlled component.
124 */
125 value?: unknown;
126};
127export interface InputSlots {
128 /**
129 * The component that renders the root.
130 * @default 'div'
131 */
132 root?: React.ElementType;
133 /**
134 * The component that renders the input.
135 * @default 'input'
136 */
137 input?: React.ElementType;
138 /**
139 * The component that renders the textarea.
140 * @default 'textarea'
141 */
142 textarea?: React.ElementType;
143}
144export interface InputTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
145 props: InputOwnProps & AdditionalProps;
146 defaultComponent: RootComponentType;
147}
148export type InputProps<RootComponentType extends React.ElementType = InputTypeMap['defaultComponent']> = PolymorphicProps<InputTypeMap<{}, RootComponentType>, RootComponentType>;
149export type InputOwnerState = Simplify<InputOwnProps & {
150 formControlContext: FormControlState | undefined;
151 focused: boolean;
152 type: React.InputHTMLAttributes<HTMLInputElement>['type'] | undefined;
153}>;
154export type InputRootSlotProps = Simplify<UseInputRootSlotProps & {
155 ownerState: InputOwnerState;
156 className?: string;
157 children?: React.ReactNode;
158 ref?: React.Ref<HTMLDivElement>;
159}>;
160export type InputInputSlotProps = Simplify<Omit<UseInputRootSlotProps, 'onClick'> & {
161 'aria-describedby': React.AriaAttributes['aria-describedby'];
162 'aria-label': React.AriaAttributes['aria-label'];
163 'aria-labelledby': React.AriaAttributes['aria-labelledby'];
164 autoComplete: string | undefined;
165 autoFocus: boolean | undefined;
166 className?: string;
167 id: string | undefined;
168 name: string | undefined;
169 onKeyDown: React.KeyboardEventHandler<HTMLInputElement> | undefined;
170 onKeyUp: React.KeyboardEventHandler<HTMLInputElement> | undefined;
171 ownerState: InputOwnerState;
172 placeholder: string | undefined;
173 readOnly: boolean | undefined;
174 ref: React.Ref<HTMLInputElement>;
175 type: React.HTMLInputTypeAttribute | undefined;
176}>;