1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["aria-describedby", "aria-label", "aria-labelledby", "autoComplete", "autoFocus", "className", "defaultValue", "disabled", "endAdornment", "error", "id", "multiline", "name", "onClick", "onChange", "onKeyDown", "onKeyUp", "onFocus", "onBlur", "placeholder", "readOnly", "required", "startAdornment", "value", "type", "rows", "slotProps", "slots", "minRows", "maxRows"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import isHostComponent from '../utils/isHostComponent';
|
7 | import { getInputUtilityClass } from './inputClasses';
|
8 | import useInput from '../useInput';
|
9 | import { useSlotProps } from '../utils';
|
10 | import composeClasses from '../composeClasses';
|
11 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
12 | import { jsx as _jsx } from "react/jsx-runtime";
|
13 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
14 | const useUtilityClasses = ownerState => {
|
15 | const {
|
16 | disabled,
|
17 | error,
|
18 | focused,
|
19 | formControlContext,
|
20 | multiline,
|
21 | startAdornment,
|
22 | endAdornment
|
23 | } = ownerState;
|
24 | const slots = {
|
25 | root: ['root', disabled && 'disabled', error && 'error', focused && 'focused', Boolean(formControlContext) && 'formControl', multiline && 'multiline', Boolean(startAdornment) && 'adornedStart', Boolean(endAdornment) && 'adornedEnd'],
|
26 | input: ['input', disabled && 'disabled', multiline && 'multiline']
|
27 | };
|
28 | return composeClasses(slots, useClassNamesOverride(getInputUtilityClass));
|
29 | };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | const Input = React.forwardRef(function Input(props, forwardedRef) {
|
42 | const {
|
43 | 'aria-describedby': ariaDescribedby,
|
44 | 'aria-label': ariaLabel,
|
45 | 'aria-labelledby': ariaLabelledby,
|
46 | autoComplete,
|
47 | autoFocus,
|
48 | className,
|
49 | defaultValue,
|
50 | disabled,
|
51 | endAdornment,
|
52 | error,
|
53 | id,
|
54 | multiline = false,
|
55 | name,
|
56 | onClick,
|
57 | onChange,
|
58 | onKeyDown,
|
59 | onKeyUp,
|
60 | onFocus,
|
61 | onBlur,
|
62 | placeholder,
|
63 | readOnly,
|
64 | required,
|
65 | startAdornment,
|
66 | value,
|
67 | type: typeProp,
|
68 | rows,
|
69 | slotProps = {},
|
70 | slots = {},
|
71 | minRows,
|
72 | maxRows
|
73 | } = props,
|
74 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
75 | const {
|
76 | getRootProps,
|
77 | getInputProps,
|
78 | focused,
|
79 | formControlContext,
|
80 | error: errorState,
|
81 | disabled: disabledState
|
82 | } = useInput({
|
83 | disabled,
|
84 | defaultValue,
|
85 | error,
|
86 | onBlur,
|
87 | onClick,
|
88 | onChange,
|
89 | onFocus,
|
90 | required,
|
91 | value
|
92 | });
|
93 | const type = !multiline ? typeProp ?? 'text' : undefined;
|
94 | const ownerState = _extends({}, props, {
|
95 | disabled: disabledState,
|
96 | error: errorState,
|
97 | focused,
|
98 | formControlContext,
|
99 | multiline,
|
100 | type
|
101 | });
|
102 | const classes = useUtilityClasses(ownerState);
|
103 | const propsToForward = {
|
104 | 'aria-describedby': ariaDescribedby,
|
105 | 'aria-label': ariaLabel,
|
106 | 'aria-labelledby': ariaLabelledby,
|
107 | autoComplete,
|
108 | autoFocus,
|
109 | id,
|
110 | onKeyDown,
|
111 | onKeyUp,
|
112 | name,
|
113 | placeholder,
|
114 | readOnly,
|
115 | type
|
116 | };
|
117 | const Root = slots.root ?? 'div';
|
118 | const rootProps = useSlotProps({
|
119 | elementType: Root,
|
120 | getSlotProps: getRootProps,
|
121 | externalSlotProps: slotProps.root,
|
122 | externalForwardedProps: other,
|
123 | additionalProps: {
|
124 | ref: forwardedRef
|
125 | },
|
126 | ownerState,
|
127 | className: [classes.root, className]
|
128 | });
|
129 | const InputComponent = multiline ? slots.textarea ?? 'textarea' : slots.input ?? 'input';
|
130 | const inputProps = useSlotProps({
|
131 | elementType: InputComponent,
|
132 | getSlotProps: otherHandlers => {
|
133 | return getInputProps(_extends({}, propsToForward, otherHandlers));
|
134 | },
|
135 | externalSlotProps: slotProps.input,
|
136 | additionalProps: _extends({
|
137 | rows: multiline ? rows : undefined
|
138 | }, multiline && !isHostComponent(InputComponent) && {
|
139 | minRows: rows || minRows,
|
140 | maxRows: rows || maxRows
|
141 | }),
|
142 | ownerState,
|
143 | className: classes.input
|
144 | });
|
145 | if (process.env.NODE_ENV !== 'production') {
|
146 | if (multiline) {
|
147 | if (rows) {
|
148 | if (minRows || maxRows) {
|
149 | console.warn('MUI: You can not use the `minRows` or `maxRows` props when the input `rows` prop is set.');
|
150 | }
|
151 | }
|
152 | }
|
153 | }
|
154 | return _jsxs(Root, _extends({}, rootProps, {
|
155 | children: [startAdornment, _jsx(InputComponent, _extends({}, inputProps)), endAdornment]
|
156 | }));
|
157 | });
|
158 | process.env.NODE_ENV !== "production" ? Input.propTypes = {
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | |
164 |
|
165 |
|
166 | 'aria-describedby': PropTypes.string,
|
167 | |
168 |
|
169 |
|
170 | 'aria-label': PropTypes.string,
|
171 | |
172 |
|
173 |
|
174 | 'aria-labelledby': PropTypes.string,
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 | autoComplete: PropTypes.string,
|
181 | |
182 |
|
183 |
|
184 | autoFocus: PropTypes.bool,
|
185 | |
186 |
|
187 |
|
188 | className: PropTypes.string,
|
189 | |
190 |
|
191 |
|
192 | defaultValue: PropTypes.any,
|
193 | |
194 |
|
195 |
|
196 |
|
197 | disabled: PropTypes.bool,
|
198 | |
199 |
|
200 |
|
201 | endAdornment: PropTypes.node,
|
202 | |
203 |
|
204 |
|
205 |
|
206 | error: PropTypes.bool,
|
207 | |
208 |
|
209 |
|
210 | id: PropTypes.string,
|
211 | |
212 |
|
213 |
|
214 | inputRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
215 | current: PropTypes.object
|
216 | })]),
|
217 | |
218 |
|
219 |
|
220 | maxRows: PropTypes.number,
|
221 | |
222 |
|
223 |
|
224 | minRows: PropTypes.number,
|
225 | |
226 |
|
227 |
|
228 |
|
229 | multiline: PropTypes.bool,
|
230 | |
231 |
|
232 |
|
233 | name: PropTypes.string,
|
234 | |
235 |
|
236 |
|
237 | onBlur: PropTypes.func,
|
238 | |
239 |
|
240 |
|
241 | onChange: PropTypes.func,
|
242 | |
243 |
|
244 |
|
245 | onClick: PropTypes.func,
|
246 | |
247 |
|
248 |
|
249 | onFocus: PropTypes.func,
|
250 | |
251 |
|
252 |
|
253 | onKeyDown: PropTypes.func,
|
254 | |
255 |
|
256 |
|
257 | onKeyUp: PropTypes.func,
|
258 | |
259 |
|
260 |
|
261 | placeholder: PropTypes.string,
|
262 | |
263 |
|
264 |
|
265 |
|
266 | readOnly: PropTypes.bool,
|
267 | |
268 |
|
269 |
|
270 |
|
271 | required: PropTypes.bool,
|
272 | |
273 |
|
274 |
|
275 | rows: PropTypes.number,
|
276 | |
277 |
|
278 |
|
279 |
|
280 | slotProps: PropTypes.shape({
|
281 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
282 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
283 | }),
|
284 | |
285 |
|
286 |
|
287 |
|
288 |
|
289 | slots: PropTypes.shape({
|
290 | input: PropTypes.elementType,
|
291 | root: PropTypes.elementType,
|
292 | textarea: PropTypes.elementType
|
293 | }),
|
294 | |
295 |
|
296 |
|
297 | startAdornment: PropTypes.node,
|
298 | |
299 |
|
300 |
|
301 |
|
302 | type: PropTypes .oneOf(['button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week']),
|
303 | |
304 |
|
305 |
|
306 | value: PropTypes.any
|
307 | } : void 0;
|
308 | export default Input; |
\ | No newline at end of file |