1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import deepmerge from '@mui/utils/deepmerge';
|
5 | import refType from '@mui/utils/refType';
|
6 | import PropTypes from 'prop-types';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import InputBase from "../InputBase/index.js";
|
9 | import rootShouldForwardProp from "../styles/rootShouldForwardProp.js";
|
10 | import { styled } from "../zero-styled/index.js";
|
11 | import memoTheme from "../utils/memoTheme.js";
|
12 | import createSimplePaletteValueFilter from "../utils/createSimplePaletteValueFilter.js";
|
13 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
14 | import filledInputClasses, { getFilledInputUtilityClass } from "./filledInputClasses.js";
|
15 | import { rootOverridesResolver as inputBaseRootOverridesResolver, inputOverridesResolver as inputBaseInputOverridesResolver, InputBaseRoot, InputBaseInput } from "../InputBase/InputBase.js";
|
16 | import { capitalize } from "../utils/index.js";
|
17 | import { jsx as _jsx } from "react/jsx-runtime";
|
18 | const useUtilityClasses = ownerState => {
|
19 | const {
|
20 | classes,
|
21 | disableUnderline,
|
22 | startAdornment,
|
23 | endAdornment,
|
24 | size,
|
25 | hiddenLabel,
|
26 | multiline
|
27 | } = ownerState;
|
28 | const slots = {
|
29 | root: ['root', !disableUnderline && 'underline', startAdornment && 'adornedStart', endAdornment && 'adornedEnd', size === 'small' && `size${capitalize(size)}`, hiddenLabel && 'hiddenLabel', multiline && 'multiline'],
|
30 | input: ['input']
|
31 | };
|
32 | const composedClasses = composeClasses(slots, getFilledInputUtilityClass, classes);
|
33 | return {
|
34 | ...classes,
|
35 |
|
36 | ...composedClasses
|
37 | };
|
38 | };
|
39 | const FilledInputRoot = styled(InputBaseRoot, {
|
40 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
41 | name: 'MuiFilledInput',
|
42 | slot: 'Root',
|
43 | overridesResolver: (props, styles) => {
|
44 | const {
|
45 | ownerState
|
46 | } = props;
|
47 | return [...inputBaseRootOverridesResolver(props, styles), !ownerState.disableUnderline && styles.underline];
|
48 | }
|
49 | })(memoTheme(({
|
50 | theme
|
51 | }) => {
|
52 | const light = theme.palette.mode === 'light';
|
53 | const bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
|
54 | const backgroundColor = light ? 'rgba(0, 0, 0, 0.06)' : 'rgba(255, 255, 255, 0.09)';
|
55 | const hoverBackground = light ? 'rgba(0, 0, 0, 0.09)' : 'rgba(255, 255, 255, 0.13)';
|
56 | const disabledBackground = light ? 'rgba(0, 0, 0, 0.12)' : 'rgba(255, 255, 255, 0.12)';
|
57 | return {
|
58 | position: 'relative',
|
59 | backgroundColor: theme.vars ? theme.vars.palette.FilledInput.bg : backgroundColor,
|
60 | borderTopLeftRadius: (theme.vars || theme).shape.borderRadius,
|
61 | borderTopRightRadius: (theme.vars || theme).shape.borderRadius,
|
62 | transition: theme.transitions.create('background-color', {
|
63 | duration: theme.transitions.duration.shorter,
|
64 | easing: theme.transitions.easing.easeOut
|
65 | }),
|
66 | '&:hover': {
|
67 | backgroundColor: theme.vars ? theme.vars.palette.FilledInput.hoverBg : hoverBackground,
|
68 |
|
69 | '@media (hover: none)': {
|
70 | backgroundColor: theme.vars ? theme.vars.palette.FilledInput.bg : backgroundColor
|
71 | }
|
72 | },
|
73 | [`&.${filledInputClasses.focused}`]: {
|
74 | backgroundColor: theme.vars ? theme.vars.palette.FilledInput.bg : backgroundColor
|
75 | },
|
76 | [`&.${filledInputClasses.disabled}`]: {
|
77 | backgroundColor: theme.vars ? theme.vars.palette.FilledInput.disabledBg : disabledBackground
|
78 | },
|
79 | variants: [{
|
80 | props: ({
|
81 | ownerState
|
82 | }) => !ownerState.disableUnderline,
|
83 | style: {
|
84 | '&::after': {
|
85 | left: 0,
|
86 | bottom: 0,
|
87 | content: '""',
|
88 | position: 'absolute',
|
89 | right: 0,
|
90 | transform: 'scaleX(0)',
|
91 | transition: theme.transitions.create('transform', {
|
92 | duration: theme.transitions.duration.shorter,
|
93 | easing: theme.transitions.easing.easeOut
|
94 | }),
|
95 | pointerEvents: 'none'
|
96 | },
|
97 | [`&.${filledInputClasses.focused}:after`]: {
|
98 |
|
99 |
|
100 | transform: 'scaleX(1) translateX(0)'
|
101 | },
|
102 | [`&.${filledInputClasses.error}`]: {
|
103 | '&::before, &::after': {
|
104 | borderBottomColor: (theme.vars || theme).palette.error.main
|
105 | }
|
106 | },
|
107 | '&::before': {
|
108 | borderBottom: `1px solid ${theme.vars ? `rgba(${theme.vars.palette.common.onBackgroundChannel} / ${theme.vars.opacity.inputUnderline})` : bottomLineColor}`,
|
109 | left: 0,
|
110 | bottom: 0,
|
111 | content: '"\\00a0"',
|
112 | position: 'absolute',
|
113 | right: 0,
|
114 | transition: theme.transitions.create('border-bottom-color', {
|
115 | duration: theme.transitions.duration.shorter
|
116 | }),
|
117 | pointerEvents: 'none'
|
118 | },
|
119 | [`&:hover:not(.${filledInputClasses.disabled}, .${filledInputClasses.error}):before`]: {
|
120 | borderBottom: `1px solid ${(theme.vars || theme).palette.text.primary}`
|
121 | },
|
122 | [`&.${filledInputClasses.disabled}:before`]: {
|
123 | borderBottomStyle: 'dotted'
|
124 | }
|
125 | }
|
126 | }, ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter())
|
127 | .map(([color]) => ({
|
128 | props: {
|
129 | disableUnderline: false,
|
130 | color
|
131 | },
|
132 | style: {
|
133 | '&::after': {
|
134 | borderBottom: `2px solid ${(theme.vars || theme).palette[color]?.main}`
|
135 | }
|
136 | }
|
137 | })), {
|
138 | props: ({
|
139 | ownerState
|
140 | }) => ownerState.startAdornment,
|
141 | style: {
|
142 | paddingLeft: 12
|
143 | }
|
144 | }, {
|
145 | props: ({
|
146 | ownerState
|
147 | }) => ownerState.endAdornment,
|
148 | style: {
|
149 | paddingRight: 12
|
150 | }
|
151 | }, {
|
152 | props: ({
|
153 | ownerState
|
154 | }) => ownerState.multiline,
|
155 | style: {
|
156 | padding: '25px 12px 8px'
|
157 | }
|
158 | }, {
|
159 | props: ({
|
160 | ownerState,
|
161 | size
|
162 | }) => ownerState.multiline && size === 'small',
|
163 | style: {
|
164 | paddingTop: 21,
|
165 | paddingBottom: 4
|
166 | }
|
167 | }, {
|
168 | props: ({
|
169 | ownerState
|
170 | }) => ownerState.multiline && ownerState.hiddenLabel,
|
171 | style: {
|
172 | paddingTop: 16,
|
173 | paddingBottom: 17
|
174 | }
|
175 | }, {
|
176 | props: ({
|
177 | ownerState
|
178 | }) => ownerState.multiline && ownerState.hiddenLabel && ownerState.size === 'small',
|
179 | style: {
|
180 | paddingTop: 8,
|
181 | paddingBottom: 9
|
182 | }
|
183 | }]
|
184 | };
|
185 | }));
|
186 | const FilledInputInput = styled(InputBaseInput, {
|
187 | name: 'MuiFilledInput',
|
188 | slot: 'Input',
|
189 | overridesResolver: inputBaseInputOverridesResolver
|
190 | })(memoTheme(({
|
191 | theme
|
192 | }) => ({
|
193 | paddingTop: 25,
|
194 | paddingRight: 12,
|
195 | paddingBottom: 8,
|
196 | paddingLeft: 12,
|
197 | ...(!theme.vars && {
|
198 | '&:-webkit-autofill': {
|
199 | WebkitBoxShadow: theme.palette.mode === 'light' ? null : '0 0 0 100px #266798 inset',
|
200 | WebkitTextFillColor: theme.palette.mode === 'light' ? null : '#fff',
|
201 | caretColor: theme.palette.mode === 'light' ? null : '#fff',
|
202 | borderTopLeftRadius: 'inherit',
|
203 | borderTopRightRadius: 'inherit'
|
204 | }
|
205 | }),
|
206 | ...(theme.vars && {
|
207 | '&:-webkit-autofill': {
|
208 | borderTopLeftRadius: 'inherit',
|
209 | borderTopRightRadius: 'inherit'
|
210 | },
|
211 | [theme.getColorSchemeSelector('dark')]: {
|
212 | '&:-webkit-autofill': {
|
213 | WebkitBoxShadow: '0 0 0 100px #266798 inset',
|
214 | WebkitTextFillColor: '#fff',
|
215 | caretColor: '#fff'
|
216 | }
|
217 | }
|
218 | }),
|
219 | variants: [{
|
220 | props: {
|
221 | size: 'small'
|
222 | },
|
223 | style: {
|
224 | paddingTop: 21,
|
225 | paddingBottom: 4
|
226 | }
|
227 | }, {
|
228 | props: ({
|
229 | ownerState
|
230 | }) => ownerState.hiddenLabel,
|
231 | style: {
|
232 | paddingTop: 16,
|
233 | paddingBottom: 17
|
234 | }
|
235 | }, {
|
236 | props: ({
|
237 | ownerState
|
238 | }) => ownerState.startAdornment,
|
239 | style: {
|
240 | paddingLeft: 0
|
241 | }
|
242 | }, {
|
243 | props: ({
|
244 | ownerState
|
245 | }) => ownerState.endAdornment,
|
246 | style: {
|
247 | paddingRight: 0
|
248 | }
|
249 | }, {
|
250 | props: ({
|
251 | ownerState
|
252 | }) => ownerState.hiddenLabel && ownerState.size === 'small',
|
253 | style: {
|
254 | paddingTop: 8,
|
255 | paddingBottom: 9
|
256 | }
|
257 | }, {
|
258 | props: ({
|
259 | ownerState
|
260 | }) => ownerState.multiline,
|
261 | style: {
|
262 | paddingTop: 0,
|
263 | paddingBottom: 0,
|
264 | paddingLeft: 0,
|
265 | paddingRight: 0
|
266 | }
|
267 | }]
|
268 | })));
|
269 | const FilledInput = React.forwardRef(function FilledInput(inProps, ref) {
|
270 | const props = useDefaultProps({
|
271 | props: inProps,
|
272 | name: 'MuiFilledInput'
|
273 | });
|
274 | const {
|
275 | disableUnderline = false,
|
276 | components = {},
|
277 | componentsProps: componentsPropsProp,
|
278 | fullWidth = false,
|
279 | hiddenLabel,
|
280 |
|
281 | inputComponent = 'input',
|
282 | multiline = false,
|
283 | slotProps,
|
284 | slots = {},
|
285 | type = 'text',
|
286 | ...other
|
287 | } = props;
|
288 | const ownerState = {
|
289 | ...props,
|
290 | disableUnderline,
|
291 | fullWidth,
|
292 | inputComponent,
|
293 | multiline,
|
294 | type
|
295 | };
|
296 | const classes = useUtilityClasses(props);
|
297 | const filledInputComponentsProps = {
|
298 | root: {
|
299 | ownerState
|
300 | },
|
301 | input: {
|
302 | ownerState
|
303 | }
|
304 | };
|
305 | const componentsProps = slotProps ?? componentsPropsProp ? deepmerge(filledInputComponentsProps, slotProps ?? componentsPropsProp) : filledInputComponentsProps;
|
306 | const RootSlot = slots.root ?? components.Root ?? FilledInputRoot;
|
307 | const InputSlot = slots.input ?? components.Input ?? FilledInputInput;
|
308 | return _jsx(InputBase, {
|
309 | slots: {
|
310 | root: RootSlot,
|
311 | input: InputSlot
|
312 | },
|
313 | componentsProps: componentsProps,
|
314 | fullWidth: fullWidth,
|
315 | inputComponent: inputComponent,
|
316 | multiline: multiline,
|
317 | ref: ref,
|
318 | type: type,
|
319 | ...other,
|
320 | classes: classes
|
321 | });
|
322 | });
|
323 | process.env.NODE_ENV !== "production" ? FilledInput.propTypes = {
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 | autoComplete: PropTypes.string,
|
334 | |
335 |
|
336 |
|
337 | autoFocus: PropTypes.bool,
|
338 | |
339 |
|
340 |
|
341 | classes: PropTypes.object,
|
342 | |
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary']), PropTypes.string]),
|
349 | |
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | components: PropTypes.shape({
|
357 | Input: PropTypes.elementType,
|
358 | Root: PropTypes.elementType
|
359 | }),
|
360 | |
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 | componentsProps: PropTypes.shape({
|
369 | input: PropTypes.object,
|
370 | root: PropTypes.object
|
371 | }),
|
372 | |
373 |
|
374 |
|
375 | defaultValue: PropTypes.any,
|
376 | |
377 |
|
378 |
|
379 |
|
380 | disabled: PropTypes.bool,
|
381 | |
382 |
|
383 |
|
384 |
|
385 | disableUnderline: PropTypes.bool,
|
386 | |
387 |
|
388 |
|
389 | endAdornment: PropTypes.node,
|
390 | |
391 |
|
392 |
|
393 |
|
394 | error: PropTypes.bool,
|
395 | |
396 |
|
397 |
|
398 |
|
399 | fullWidth: PropTypes.bool,
|
400 | |
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 | hiddenLabel: PropTypes.bool,
|
407 | |
408 |
|
409 |
|
410 | id: PropTypes.string,
|
411 | |
412 |
|
413 |
|
414 |
|
415 |
|
416 | inputComponent: PropTypes.elementType,
|
417 | |
418 |
|
419 |
|
420 |
|
421 | inputProps: PropTypes.object,
|
422 | |
423 |
|
424 |
|
425 | inputRef: refType,
|
426 | |
427 |
|
428 |
|
429 |
|
430 |
|
431 | margin: PropTypes.oneOf(['dense', 'none']),
|
432 | |
433 |
|
434 |
|
435 | maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
436 | |
437 |
|
438 |
|
439 | minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
440 | |
441 |
|
442 |
|
443 |
|
444 | multiline: PropTypes.bool,
|
445 | |
446 |
|
447 |
|
448 | name: PropTypes.string,
|
449 | |
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | onChange: PropTypes.func,
|
456 | |
457 |
|
458 |
|
459 | placeholder: PropTypes.string,
|
460 | |
461 |
|
462 |
|
463 |
|
464 | readOnly: PropTypes.bool,
|
465 | |
466 |
|
467 |
|
468 |
|
469 | required: PropTypes.bool,
|
470 | |
471 |
|
472 |
|
473 | rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
474 | |
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | slotProps: PropTypes.shape({
|
483 | input: PropTypes.object,
|
484 | root: PropTypes.object
|
485 | }),
|
486 | |
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | slots: PropTypes.shape({
|
494 | input: PropTypes.elementType,
|
495 | root: PropTypes.elementType
|
496 | }),
|
497 | |
498 |
|
499 |
|
500 | startAdornment: PropTypes.node,
|
501 | |
502 |
|
503 |
|
504 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
505 | |
506 |
|
507 |
|
508 |
|
509 | type: PropTypes.string,
|
510 | |
511 |
|
512 |
|
513 | value: PropTypes.any
|
514 | } : void 0;
|
515 | if (FilledInput) {
|
516 | FilledInput.muiName = 'Input';
|
517 | }
|
518 | export default FilledInput; |
\ | No newline at end of file |