UNPKG

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