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