1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | const _excluded = ["disableUnderline", "components", "componentsProps", "fullWidth", "inputComponent", "multiline", "type"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
7 | import { refType, deepmerge } from '@mui/utils';
|
8 | import InputBase from '../InputBase';
|
9 | import styled, { rootShouldForwardProp } from '../styles/styled';
|
10 | import useThemeProps from '../styles/useThemeProps';
|
11 | import inputClasses, { getInputUtilityClass } from './inputClasses';
|
12 | import { rootOverridesResolver as inputBaseRootOverridesResolver, inputOverridesResolver as inputBaseInputOverridesResolver, InputBaseRoot, InputBaseComponent as InputBaseInput } from '../InputBase/InputBase';
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 |
|
15 | const useUtilityClasses = ownerState => {
|
16 | const {
|
17 | classes,
|
18 | disableUnderline
|
19 | } = ownerState;
|
20 | const slots = {
|
21 | root: ['root', !disableUnderline && 'underline'],
|
22 | input: ['input']
|
23 | };
|
24 | const composedClasses = composeClasses(slots, getInputUtilityClass, classes);
|
25 | return _extends({}, classes, composedClasses);
|
26 | };
|
27 |
|
28 | const InputRoot = styled(InputBaseRoot, {
|
29 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
30 | name: 'MuiInput',
|
31 | slot: 'Root',
|
32 | overridesResolver: (props, styles) => {
|
33 | const {
|
34 | ownerState
|
35 | } = props;
|
36 | return [...inputBaseRootOverridesResolver(props, styles), !ownerState.disableUnderline && styles.underline];
|
37 | }
|
38 | })(({
|
39 | theme,
|
40 | ownerState
|
41 | }) => {
|
42 | const light = theme.palette.mode === 'light';
|
43 | let bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
|
44 |
|
45 | if (theme.vars) {
|
46 | bottomLineColor = `rgba(${theme.vars.palette.common.onBackgroundChannel} / ${theme.vars.opacity.inputUnderline})`;
|
47 | }
|
48 |
|
49 | return _extends({
|
50 | position: 'relative'
|
51 | }, ownerState.formControl && {
|
52 | 'label + &': {
|
53 | marginTop: 16
|
54 | }
|
55 | }, !ownerState.disableUnderline && {
|
56 | '&:after': {
|
57 | borderBottom: `2px solid ${(theme.vars || theme).palette[ownerState.color].main}`,
|
58 | left: 0,
|
59 | bottom: 0,
|
60 |
|
61 | content: '""',
|
62 | position: 'absolute',
|
63 | right: 0,
|
64 | transform: 'scaleX(0)',
|
65 | transition: theme.transitions.create('transform', {
|
66 | duration: theme.transitions.duration.shorter,
|
67 | easing: theme.transitions.easing.easeOut
|
68 | }),
|
69 | pointerEvents: 'none'
|
70 |
|
71 | },
|
72 | [`&.${inputClasses.focused}:after`]: {
|
73 |
|
74 |
|
75 | transform: 'scaleX(1) translateX(0)'
|
76 | },
|
77 | [`&.${inputClasses.error}:after`]: {
|
78 | borderBottomColor: (theme.vars || theme).palette.error.main,
|
79 | transform: 'scaleX(1)'
|
80 |
|
81 | },
|
82 | '&:before': {
|
83 | borderBottom: `1px solid ${bottomLineColor}`,
|
84 | left: 0,
|
85 | bottom: 0,
|
86 |
|
87 | content: '"\\00a0"',
|
88 | position: 'absolute',
|
89 | right: 0,
|
90 | transition: theme.transitions.create('border-bottom-color', {
|
91 | duration: theme.transitions.duration.shorter
|
92 | }),
|
93 | pointerEvents: 'none'
|
94 |
|
95 | },
|
96 | [`&:hover:not(.${inputClasses.disabled}):before`]: {
|
97 | borderBottom: `2px solid ${(theme.vars || theme).palette.text.primary}`,
|
98 |
|
99 | '@media (hover: none)': {
|
100 | borderBottom: `1px solid ${bottomLineColor}`
|
101 | }
|
102 | },
|
103 | [`&.${inputClasses.disabled}:before`]: {
|
104 | borderBottomStyle: 'dotted'
|
105 | }
|
106 | });
|
107 | });
|
108 | const InputInput = styled(InputBaseInput, {
|
109 | name: 'MuiInput',
|
110 | slot: 'Input',
|
111 | overridesResolver: inputBaseInputOverridesResolver
|
112 | })({});
|
113 | const Input = React.forwardRef(function Input(inProps, ref) {
|
114 | const props = useThemeProps({
|
115 | props: inProps,
|
116 | name: 'MuiInput'
|
117 | });
|
118 |
|
119 | const {
|
120 | disableUnderline,
|
121 | components = {},
|
122 | componentsProps: componentsPropsProp,
|
123 | fullWidth = false,
|
124 | inputComponent = 'input',
|
125 | multiline = false,
|
126 | type = 'text'
|
127 | } = props,
|
128 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
129 |
|
130 | const classes = useUtilityClasses(props);
|
131 | const ownerState = {
|
132 | disableUnderline
|
133 | };
|
134 | const inputComponentsProps = {
|
135 | root: {
|
136 | ownerState
|
137 | }
|
138 | };
|
139 | const componentsProps = componentsPropsProp ? deepmerge(componentsPropsProp, inputComponentsProps) : inputComponentsProps;
|
140 | return _jsx(InputBase, _extends({
|
141 | components: _extends({
|
142 | Root: InputRoot,
|
143 | Input: InputInput
|
144 | }, components),
|
145 | componentsProps: componentsProps,
|
146 | fullWidth: fullWidth,
|
147 | inputComponent: inputComponent,
|
148 | multiline: multiline,
|
149 | ref: ref,
|
150 | type: type
|
151 | }, other, {
|
152 | classes: classes
|
153 | }));
|
154 | });
|
155 | process.env.NODE_ENV !== "production" ? Input.propTypes
|
156 |
|
157 | = {
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 | autoComplete: PropTypes.string,
|
169 |
|
170 | |
171 |
|
172 |
|
173 | autoFocus: PropTypes.bool,
|
174 |
|
175 | |
176 |
|
177 |
|
178 | classes: PropTypes.object,
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | color: PropTypes
|
187 |
|
188 | .oneOfType([PropTypes.oneOf(['primary', 'secondary']), PropTypes.string]),
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 |
|
195 | components: PropTypes.shape({
|
196 | Input: PropTypes.elementType,
|
197 | Root: PropTypes.elementType
|
198 | }),
|
199 |
|
200 | |
201 |
|
202 |
|
203 |
|
204 | componentsProps: PropTypes.shape({
|
205 | input: PropTypes.object,
|
206 | root: PropTypes.object
|
207 | }),
|
208 |
|
209 | |
210 |
|
211 |
|
212 | defaultValue: PropTypes.any,
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 | disabled: PropTypes.bool,
|
219 |
|
220 | |
221 |
|
222 |
|
223 | disableUnderline: PropTypes.bool,
|
224 |
|
225 | |
226 |
|
227 |
|
228 | endAdornment: PropTypes.node,
|
229 |
|
230 | |
231 |
|
232 |
|
233 |
|
234 | error: PropTypes.bool,
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 | fullWidth: PropTypes.bool,
|
241 |
|
242 | |
243 |
|
244 |
|
245 | id: PropTypes.string,
|
246 |
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 | inputComponent: PropTypes.elementType,
|
253 |
|
254 | |
255 |
|
256 |
|
257 |
|
258 | inputProps: PropTypes.object,
|
259 |
|
260 | |
261 |
|
262 |
|
263 | inputRef: refType,
|
264 |
|
265 | |
266 |
|
267 |
|
268 |
|
269 |
|
270 | margin: PropTypes.oneOf(['dense', 'none']),
|
271 |
|
272 | |
273 |
|
274 |
|
275 | maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
276 |
|
277 | |
278 |
|
279 |
|
280 | minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
281 |
|
282 | |
283 |
|
284 |
|
285 |
|
286 | multiline: PropTypes.bool,
|
287 |
|
288 | |
289 |
|
290 |
|
291 | name: PropTypes.string,
|
292 |
|
293 | |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | onChange: PropTypes.func,
|
300 |
|
301 | |
302 |
|
303 |
|
304 | placeholder: PropTypes.string,
|
305 |
|
306 | |
307 |
|
308 |
|
309 |
|
310 | readOnly: PropTypes.bool,
|
311 |
|
312 | |
313 |
|
314 |
|
315 |
|
316 | required: PropTypes.bool,
|
317 |
|
318 | |
319 |
|
320 |
|
321 | rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
322 |
|
323 | |
324 |
|
325 |
|
326 | startAdornment: PropTypes.node,
|
327 |
|
328 | |
329 |
|
330 |
|
331 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
332 |
|
333 | |
334 |
|
335 |
|
336 |
|
337 | type: PropTypes.string,
|
338 |
|
339 | |
340 |
|
341 |
|
342 | value: PropTypes.any
|
343 | } : void 0;
|
344 | Input.muiName = 'Input';
|
345 | export default Input; |
\ | No newline at end of file |