UNPKG

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