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