UNPKG

14.9 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 _refType = _interopRequireDefault(require("@mui/utils/refType"));
13var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14var _NotchedOutline = _interopRequireDefault(require("./NotchedOutline"));
15var _useFormControl = _interopRequireDefault(require("../FormControl/useFormControl"));
16var _formControlState = _interopRequireDefault(require("../FormControl/formControlState"));
17var _rootShouldForwardProp = _interopRequireDefault(require("../styles/rootShouldForwardProp"));
18var _zeroStyled = require("../zero-styled");
19var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
20var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
21var _DefaultPropsProvider = require("../DefaultPropsProvider");
22var _outlinedInputClasses = _interopRequireWildcard(require("./outlinedInputClasses"));
23var _InputBase = _interopRequireWildcard(require("../InputBase/InputBase"));
24var _jsxRuntime = require("react/jsx-runtime");
25const useUtilityClasses = ownerState => {
26 const {
27 classes
28 } = ownerState;
29 const slots = {
30 root: ['root'],
31 notchedOutline: ['notchedOutline'],
32 input: ['input']
33 };
34 const composedClasses = (0, _composeClasses.default)(slots, _outlinedInputClasses.getOutlinedInputUtilityClass, classes);
35 return {
36 ...classes,
37 // forward classes to the InputBase
38 ...composedClasses
39 };
40};
41const OutlinedInputRoot = (0, _zeroStyled.styled)(_InputBase.InputBaseRoot, {
42 shouldForwardProp: prop => (0, _rootShouldForwardProp.default)(prop) || prop === 'classes',
43 name: 'MuiOutlinedInput',
44 slot: 'Root',
45 overridesResolver: _InputBase.rootOverridesResolver
46})((0, _memoTheme.default)(({
47 theme
48}) => {
49 const borderColor = theme.palette.mode === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)';
50 return {
51 position: 'relative',
52 borderRadius: (theme.vars || theme).shape.borderRadius,
53 [`&:hover .${_outlinedInputClasses.default.notchedOutline}`]: {
54 borderColor: (theme.vars || theme).palette.text.primary
55 },
56 // Reset on touch devices, it doesn't add specificity
57 '@media (hover: none)': {
58 [`&:hover .${_outlinedInputClasses.default.notchedOutline}`]: {
59 borderColor: theme.vars ? `rgba(${theme.vars.palette.common.onBackgroundChannel} / 0.23)` : borderColor
60 }
61 },
62 [`&.${_outlinedInputClasses.default.focused} .${_outlinedInputClasses.default.notchedOutline}`]: {
63 borderWidth: 2
64 },
65 variants: [...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
66 props: {
67 color
68 },
69 style: {
70 [`&.${_outlinedInputClasses.default.focused} .${_outlinedInputClasses.default.notchedOutline}`]: {
71 borderColor: (theme.vars || theme).palette[color].main
72 }
73 }
74 })), {
75 props: {},
76 // to overide the above style
77 style: {
78 [`&.${_outlinedInputClasses.default.error} .${_outlinedInputClasses.default.notchedOutline}`]: {
79 borderColor: (theme.vars || theme).palette.error.main
80 },
81 [`&.${_outlinedInputClasses.default.disabled} .${_outlinedInputClasses.default.notchedOutline}`]: {
82 borderColor: (theme.vars || theme).palette.action.disabled
83 }
84 }
85 }, {
86 props: ({
87 ownerState
88 }) => ownerState.startAdornment,
89 style: {
90 paddingLeft: 14
91 }
92 }, {
93 props: ({
94 ownerState
95 }) => ownerState.endAdornment,
96 style: {
97 paddingRight: 14
98 }
99 }, {
100 props: ({
101 ownerState
102 }) => ownerState.multiline,
103 style: {
104 padding: '16.5px 14px'
105 }
106 }, {
107 props: ({
108 ownerState,
109 size
110 }) => ownerState.multiline && size === 'small',
111 style: {
112 padding: '8.5px 14px'
113 }
114 }]
115 };
116}));
117const NotchedOutlineRoot = (0, _zeroStyled.styled)(_NotchedOutline.default, {
118 name: 'MuiOutlinedInput',
119 slot: 'NotchedOutline',
120 overridesResolver: (props, styles) => styles.notchedOutline
121})((0, _memoTheme.default)(({
122 theme
123}) => {
124 const borderColor = theme.palette.mode === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)';
125 return {
126 borderColor: theme.vars ? `rgba(${theme.vars.palette.common.onBackgroundChannel} / 0.23)` : borderColor
127 };
128}));
129const OutlinedInputInput = (0, _zeroStyled.styled)(_InputBase.InputBaseInput, {
130 name: 'MuiOutlinedInput',
131 slot: 'Input',
132 overridesResolver: _InputBase.inputOverridesResolver
133})((0, _memoTheme.default)(({
134 theme
135}) => ({
136 padding: '16.5px 14px',
137 ...(!theme.vars && {
138 '&:-webkit-autofill': {
139 WebkitBoxShadow: theme.palette.mode === 'light' ? null : '0 0 0 100px #266798 inset',
140 WebkitTextFillColor: theme.palette.mode === 'light' ? null : '#fff',
141 caretColor: theme.palette.mode === 'light' ? null : '#fff',
142 borderRadius: 'inherit'
143 }
144 }),
145 ...(theme.vars && {
146 '&:-webkit-autofill': {
147 borderRadius: 'inherit'
148 },
149 [theme.getColorSchemeSelector('dark')]: {
150 '&:-webkit-autofill': {
151 WebkitBoxShadow: '0 0 0 100px #266798 inset',
152 WebkitTextFillColor: '#fff',
153 caretColor: '#fff'
154 }
155 }
156 }),
157 variants: [{
158 props: {
159 size: 'small'
160 },
161 style: {
162 padding: '8.5px 14px'
163 }
164 }, {
165 props: ({
166 ownerState
167 }) => ownerState.multiline,
168 style: {
169 padding: 0
170 }
171 }, {
172 props: ({
173 ownerState
174 }) => ownerState.startAdornment,
175 style: {
176 paddingLeft: 0
177 }
178 }, {
179 props: ({
180 ownerState
181 }) => ownerState.endAdornment,
182 style: {
183 paddingRight: 0
184 }
185 }]
186})));
187const OutlinedInput = /*#__PURE__*/React.forwardRef(function OutlinedInput(inProps, ref) {
188 var _React$Fragment;
189 const props = (0, _DefaultPropsProvider.useDefaultProps)({
190 props: inProps,
191 name: 'MuiOutlinedInput'
192 });
193 const {
194 components = {},
195 fullWidth = false,
196 inputComponent = 'input',
197 label,
198 multiline = false,
199 notched,
200 slots = {},
201 type = 'text',
202 ...other
203 } = props;
204 const classes = useUtilityClasses(props);
205 const muiFormControl = (0, _useFormControl.default)();
206 const fcs = (0, _formControlState.default)({
207 props,
208 muiFormControl,
209 states: ['color', 'disabled', 'error', 'focused', 'hiddenLabel', 'size', 'required']
210 });
211 const ownerState = {
212 ...props,
213 color: fcs.color || 'primary',
214 disabled: fcs.disabled,
215 error: fcs.error,
216 focused: fcs.focused,
217 formControl: muiFormControl,
218 fullWidth,
219 hiddenLabel: fcs.hiddenLabel,
220 multiline,
221 size: fcs.size,
222 type
223 };
224 const RootSlot = slots.root ?? components.Root ?? OutlinedInputRoot;
225 const InputSlot = slots.input ?? components.Input ?? OutlinedInputInput;
226 return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputBase.default, {
227 slots: {
228 root: RootSlot,
229 input: InputSlot
230 },
231 renderSuffix: state => /*#__PURE__*/(0, _jsxRuntime.jsx)(NotchedOutlineRoot, {
232 ownerState: ownerState,
233 className: classes.notchedOutline,
234 label: label != null && label !== '' && fcs.required ? _React$Fragment || (_React$Fragment = /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
235 children: [label, "\u2009", '*']
236 })) : label,
237 notched: typeof notched !== 'undefined' ? notched : Boolean(state.startAdornment || state.filled || state.focused)
238 }),
239 fullWidth: fullWidth,
240 inputComponent: inputComponent,
241 multiline: multiline,
242 ref: ref,
243 type: type,
244 ...other,
245 classes: {
246 ...classes,
247 notchedOutline: null
248 }
249 });
250});
251process.env.NODE_ENV !== "production" ? OutlinedInput.propTypes /* remove-proptypes */ = {
252 // ┌────────────────────────────── Warning ──────────────────────────────┐
253 // │ These PropTypes are generated from the TypeScript type definitions. │
254 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
255 // └─────────────────────────────────────────────────────────────────────┘
256 /**
257 * This prop helps users to fill forms faster, especially on mobile devices.
258 * The name can be confusing, as it's more like an autofill.
259 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
260 */
261 autoComplete: _propTypes.default.string,
262 /**
263 * If `true`, the `input` element is focused during the first mount.
264 */
265 autoFocus: _propTypes.default.bool,
266 /**
267 * Override or extend the styles applied to the component.
268 */
269 classes: _propTypes.default.object,
270 /**
271 * The color of the component.
272 * It supports both default and custom theme colors, which can be added as shown in the
273 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
274 * The prop defaults to the value (`'primary'`) inherited from the parent FormControl component.
275 */
276 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['primary', 'secondary']), _propTypes.default.string]),
277 /**
278 * The components used for each slot inside.
279 *
280 * @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.
281 *
282 * @default {}
283 */
284 components: _propTypes.default.shape({
285 Input: _propTypes.default.elementType,
286 Root: _propTypes.default.elementType
287 }),
288 /**
289 * The default value. Use when the component is not controlled.
290 */
291 defaultValue: _propTypes.default.any,
292 /**
293 * If `true`, the component is disabled.
294 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
295 */
296 disabled: _propTypes.default.bool,
297 /**
298 * End `InputAdornment` for this component.
299 */
300 endAdornment: _propTypes.default.node,
301 /**
302 * If `true`, the `input` will indicate an error.
303 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
304 */
305 error: _propTypes.default.bool,
306 /**
307 * If `true`, the `input` will take up the full width of its container.
308 * @default false
309 */
310 fullWidth: _propTypes.default.bool,
311 /**
312 * The id of the `input` element.
313 */
314 id: _propTypes.default.string,
315 /**
316 * The component used for the `input` element.
317 * Either a string to use a HTML element or a component.
318 * @default 'input'
319 */
320 inputComponent: _propTypes.default.elementType,
321 /**
322 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
323 * @default {}
324 */
325 inputProps: _propTypes.default.object,
326 /**
327 * Pass a ref to the `input` element.
328 */
329 inputRef: _refType.default,
330 /**
331 * The label of the `input`. It is only used for layout. The actual labelling
332 * is handled by `InputLabel`.
333 */
334 label: _propTypes.default.node,
335 /**
336 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
337 * FormControl.
338 * The prop defaults to the value (`'none'`) inherited from the parent FormControl component.
339 */
340 margin: _propTypes.default.oneOf(['dense', 'none']),
341 /**
342 * Maximum number of rows to display when multiline option is set to true.
343 */
344 maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
345 /**
346 * Minimum number of rows to display when multiline option is set to true.
347 */
348 minRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
349 /**
350 * If `true`, a [TextareaAutosize](https://mui.com/material-ui/react-textarea-autosize/) element is rendered.
351 * @default false
352 */
353 multiline: _propTypes.default.bool,
354 /**
355 * Name attribute of the `input` element.
356 */
357 name: _propTypes.default.string,
358 /**
359 * If `true`, the outline is notched to accommodate the label.
360 */
361 notched: _propTypes.default.bool,
362 /**
363 * Callback fired when the value is changed.
364 *
365 * @param {React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>} event The event source of the callback.
366 * You can pull out the new value by accessing `event.target.value` (string).
367 */
368 onChange: _propTypes.default.func,
369 /**
370 * The short hint displayed in the `input` before the user enters a value.
371 */
372 placeholder: _propTypes.default.string,
373 /**
374 * It prevents the user from changing the value of the field
375 * (not from interacting with the field).
376 */
377 readOnly: _propTypes.default.bool,
378 /**
379 * If `true`, the `input` element is required.
380 * The prop defaults to the value (`false`) inherited from the parent FormControl component.
381 */
382 required: _propTypes.default.bool,
383 /**
384 * Number of rows to display when multiline option is set to true.
385 */
386 rows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
387 /**
388 * The components used for each slot inside.
389 *
390 * This prop is an alias for the `components` prop, which will be deprecated in the future.
391 *
392 * @default {}
393 */
394 slots: _propTypes.default.shape({
395 input: _propTypes.default.elementType,
396 root: _propTypes.default.elementType
397 }),
398 /**
399 * Start `InputAdornment` for this component.
400 */
401 startAdornment: _propTypes.default.node,
402 /**
403 * The system prop that allows defining system overrides as well as additional CSS styles.
404 */
405 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]),
406 /**
407 * 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).
408 * @default 'text'
409 */
410 type: _propTypes.default.string,
411 /**
412 * The value of the `input` element, required for a controlled component.
413 */
414 value: _propTypes.default.any
415} : void 0;
416if (OutlinedInput) {
417 OutlinedInput.muiName = 'Input';
418}
419var _default = exports.default = OutlinedInput;
\No newline at end of file