UNPKG

11.7 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4import _extends from "@babel/runtime/helpers/esm/extends";
5import * as React from 'react';
6import PropTypes from 'prop-types';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import { refType, deepmerge } from '@mui/utils';
9import InputBase from '../InputBase';
10import styled, { rootShouldForwardProp } from '../styles/styled';
11import useThemeProps from '../styles/useThemeProps';
12import inputClasses, { getInputUtilityClass } from './inputClasses';
13import { rootOverridesResolver as inputBaseRootOverridesResolver, inputOverridesResolver as inputBaseInputOverridesResolver, InputBaseRoot, InputBaseComponent as InputBaseInput } from '../InputBase/InputBase';
14import { jsx as _jsx } from "react/jsx-runtime";
15
16var useUtilityClasses = function useUtilityClasses(ownerState) {
17 var classes = ownerState.classes,
18 disableUnderline = ownerState.disableUnderline;
19 var slots = {
20 root: ['root', !disableUnderline && 'underline'],
21 input: ['input']
22 };
23 var composedClasses = composeClasses(slots, getInputUtilityClass, classes);
24 return _extends({}, classes, composedClasses);
25};
26
27var InputRoot = styled(InputBaseRoot, {
28 shouldForwardProp: function shouldForwardProp(prop) {
29 return rootShouldForwardProp(prop) || prop === 'classes';
30 },
31 name: 'MuiInput',
32 slot: 'Root',
33 overridesResolver: function overridesResolver(props, styles) {
34 var ownerState = props.ownerState;
35 return [].concat(_toConsumableArray(inputBaseRootOverridesResolver(props, styles)), [!ownerState.disableUnderline && styles.underline]);
36 }
37})(function (_ref) {
38 var _ref2;
39
40 var theme = _ref.theme,
41 ownerState = _ref.ownerState;
42 var light = theme.palette.mode === 'light';
43 var bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
44
45 if (theme.vars) {
46 bottomLineColor = "rgba(".concat(theme.vars.palette.common.onBackgroundChannel, " / ").concat(theme.vars.opacity.inputUnderline, ")");
47 }
48
49 return _extends({
50 position: 'relative'
51 }, ownerState.formControl && {
52 'label + &': {
53 marginTop: 16
54 }
55 }, !ownerState.disableUnderline && (_ref2 = {
56 '&:after': {
57 borderBottom: "2px solid ".concat((theme.vars || theme).palette[ownerState.color].main),
58 left: 0,
59 bottom: 0,
60 // Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
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' // Transparent to the hover style.
70
71 }
72 }, _defineProperty(_ref2, "&.".concat(inputClasses.focused, ":after"), {
73 // translateX(0) is a workaround for Safari transform scale bug
74 // See https://github.com/mui/material-ui/issues/31766
75 transform: 'scaleX(1) translateX(0)'
76 }), _defineProperty(_ref2, "&.".concat(inputClasses.error, ":after"), {
77 borderBottomColor: (theme.vars || theme).palette.error.main,
78 transform: 'scaleX(1)' // error is always underlined in red
79
80 }), _defineProperty(_ref2, '&:before', {
81 borderBottom: "1px solid ".concat(bottomLineColor),
82 left: 0,
83 bottom: 0,
84 // Doing the other way around crash on IE11 "''" https://github.com/cssinjs/jss/issues/242
85 content: '"\\00a0"',
86 position: 'absolute',
87 right: 0,
88 transition: theme.transitions.create('border-bottom-color', {
89 duration: theme.transitions.duration.shorter
90 }),
91 pointerEvents: 'none' // Transparent to the hover style.
92
93 }), _defineProperty(_ref2, "&:hover:not(.".concat(inputClasses.disabled, "):before"), {
94 borderBottom: "2px solid ".concat((theme.vars || theme).palette.text.primary),
95 // Reset on touch devices, it doesn't add specificity
96 '@media (hover: none)': {
97 borderBottom: "1px solid ".concat(bottomLineColor)
98 }
99 }), _defineProperty(_ref2, "&.".concat(inputClasses.disabled, ":before"), {
100 borderBottomStyle: 'dotted'
101 }), _ref2));
102});
103var InputInput = styled(InputBaseInput, {
104 name: 'MuiInput',
105 slot: 'Input',
106 overridesResolver: inputBaseInputOverridesResolver
107})({});
108var Input = /*#__PURE__*/React.forwardRef(function Input(inProps, ref) {
109 var props = useThemeProps({
110 props: inProps,
111 name: 'MuiInput'
112 });
113
114 var disableUnderline = props.disableUnderline,
115 _props$components = props.components,
116 components = _props$components === void 0 ? {} : _props$components,
117 componentsPropsProp = props.componentsProps,
118 _props$fullWidth = props.fullWidth,
119 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
120 _props$inputComponent = props.inputComponent,
121 inputComponent = _props$inputComponent === void 0 ? 'input' : _props$inputComponent,
122 _props$multiline = props.multiline,
123 multiline = _props$multiline === void 0 ? false : _props$multiline,
124 _props$type = props.type,
125 type = _props$type === void 0 ? 'text' : _props$type,
126 other = _objectWithoutProperties(props, ["disableUnderline", "components", "componentsProps", "fullWidth", "inputComponent", "multiline", "type"]);
127
128 var classes = useUtilityClasses(props);
129 var ownerState = {
130 disableUnderline: disableUnderline
131 };
132 var inputComponentsProps = {
133 root: {
134 ownerState: ownerState
135 }
136 };
137 var componentsProps = componentsPropsProp ? deepmerge(componentsPropsProp, inputComponentsProps) : inputComponentsProps;
138 return /*#__PURE__*/_jsx(InputBase, _extends({
139 components: _extends({
140 Root: InputRoot,
141 Input: InputInput
142 }, components),
143 componentsProps: componentsProps,
144 fullWidth: fullWidth,
145 inputComponent: inputComponent,
146 multiline: multiline,
147 ref: ref,
148 type: type
149 }, other, {
150 classes: classes
151 }));
152});
153process.env.NODE_ENV !== "production" ? Input.propTypes
154/* remove-proptypes */
155= {
156 // ----------------------------- Warning --------------------------------
157 // | These PropTypes are generated from the TypeScript type definitions |
158 // | To update them edit the d.ts file and run "yarn proptypes" |
159 // ----------------------------------------------------------------------
160
161 /**
162 * This prop helps users to fill forms faster, especially on mobile devices.
163 * The name can be confusing, as it's more like an autofill.
164 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
165 */
166 autoComplete: PropTypes.string,
167
168 /**
169 * If `true`, the `input` element is focused during the first mount.
170 */
171 autoFocus: PropTypes.bool,
172
173 /**
174 * Override or extend the styles applied to the component.
175 */
176 classes: PropTypes.object,
177
178 /**
179 * The color of the component.
180 * It supports both default and custom theme colors, which can be added as shown in the
181 * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
182 * The prop defaults to the value (`'primary'`) inherited from the parent FormControl component.
183 */
184 color: PropTypes
185 /* @typescript-to-proptypes-ignore */
186 .oneOfType([PropTypes.oneOf(['primary', 'secondary']), PropTypes.string]),
187
188 /**
189 * The components used for each slot inside the InputBase.
190 * Either a string to use a HTML element or a component.
191 * @default {}
192 */
193 components: PropTypes.shape({
194 Input: PropTypes.elementType,
195 Root: PropTypes.elementType
196 }),
197
198 /**
199 * The props used for each slot inside the Input.
200 * @default {}
201 */
202 componentsProps: PropTypes.shape({
203 input: PropTypes.object,
204 root: PropTypes.object
205 }),
206
207 /**
208 * The default value. Use when the component is not controlled.
209 */
210 defaultValue: PropTypes.any,
211
212 /**
213 * If `true`, the component is disabled.
214 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
215 */
216 disabled: PropTypes.bool,
217
218 /**
219 * If `true`, the `input` will not have an underline.
220 */
221 disableUnderline: PropTypes.bool,
222
223 /**
224 * End `InputAdornment` for this component.
225 */
226 endAdornment: PropTypes.node,
227
228 /**
229 * If `true`, the `input` will indicate an error.
230 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
231 */
232 error: PropTypes.bool,
233
234 /**
235 * If `true`, the `input` will take up the full width of its container.
236 * @default false
237 */
238 fullWidth: PropTypes.bool,
239
240 /**
241 * The id of the `input` element.
242 */
243 id: PropTypes.string,
244
245 /**
246 * The component used for the `input` element.
247 * Either a string to use a HTML element or a component.
248 * @default 'input'
249 */
250 inputComponent: PropTypes.elementType,
251
252 /**
253 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
254 * @default {}
255 */
256 inputProps: PropTypes.object,
257
258 /**
259 * Pass a ref to the `input` element.
260 */
261 inputRef: refType,
262
263 /**
264 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
265 * FormControl.
266 * The prop defaults to the value (`'none'`) inherited from the parent FormControl component.
267 */
268 margin: PropTypes.oneOf(['dense', 'none']),
269
270 /**
271 * Maximum number of rows to display when multiline option is set to true.
272 */
273 maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
274
275 /**
276 * Minimum number of rows to display when multiline option is set to true.
277 */
278 minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
279
280 /**
281 * If `true`, a [TextareaAutosize](/material-ui/react-textarea-autosize/) element is rendered.
282 * @default false
283 */
284 multiline: PropTypes.bool,
285
286 /**
287 * Name attribute of the `input` element.
288 */
289 name: PropTypes.string,
290
291 /**
292 * Callback fired when the value is changed.
293 *
294 * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
295 * You can pull out the new value by accessing `event.target.value` (string).
296 */
297 onChange: PropTypes.func,
298
299 /**
300 * The short hint displayed in the `input` before the user enters a value.
301 */
302 placeholder: PropTypes.string,
303
304 /**
305 * It prevents the user from changing the value of the field
306 * (not from interacting with the field).
307 */
308 readOnly: PropTypes.bool,
309
310 /**
311 * If `true`, the `input` element is required.
312 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
313 */
314 required: PropTypes.bool,
315
316 /**
317 * Number of rows to display when multiline option is set to true.
318 */
319 rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
320
321 /**
322 * Start `InputAdornment` for this component.
323 */
324 startAdornment: PropTypes.node,
325
326 /**
327 * The system prop that allows defining system overrides as well as additional CSS styles.
328 */
329 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
330
331 /**
332 * 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).
333 * @default 'text'
334 */
335 type: PropTypes.string,
336
337 /**
338 * The value of the `input` element, required for a controlled component.
339 */
340 value: PropTypes.any
341} : void 0;
342Input.muiName = 'Input';
343export default Input;
\No newline at end of file