1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import composeClasses from '@mui/utils/composeClasses';
|
6 | import deepmerge from '@mui/utils/deepmerge';
|
7 | import refType from '@mui/utils/refType';
|
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 inputClasses, { getInputUtilityClass } from "./inputClasses.js";
|
15 | import { rootOverridesResolver as inputBaseRootOverridesResolver, inputOverridesResolver as inputBaseInputOverridesResolver, InputBaseRoot, InputBaseInput } from "../InputBase/InputBase.js";
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | classes,
|
20 | disableUnderline
|
21 | } = ownerState;
|
22 | const slots = {
|
23 | root: ['root', !disableUnderline && 'underline'],
|
24 | input: ['input']
|
25 | };
|
26 | const composedClasses = composeClasses(slots, getInputUtilityClass, classes);
|
27 | return {
|
28 | ...classes,
|
29 |
|
30 | ...composedClasses
|
31 | };
|
32 | };
|
33 | const InputRoot = styled(InputBaseRoot, {
|
34 | shouldForwardProp: prop => rootShouldForwardProp(prop) || prop === 'classes',
|
35 | name: 'MuiInput',
|
36 | slot: 'Root',
|
37 | overridesResolver: (props, styles) => {
|
38 | const {
|
39 | ownerState
|
40 | } = props;
|
41 | return [...inputBaseRootOverridesResolver(props, styles), !ownerState.disableUnderline && styles.underline];
|
42 | }
|
43 | })(memoTheme(({
|
44 | theme
|
45 | }) => {
|
46 | const light = theme.palette.mode === 'light';
|
47 | let bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
|
48 | if (theme.vars) {
|
49 | bottomLineColor = `rgba(${theme.vars.palette.common.onBackgroundChannel} / ${theme.vars.opacity.inputUnderline})`;
|
50 | }
|
51 | return {
|
52 | position: 'relative',
|
53 | variants: [{
|
54 | props: ({
|
55 | ownerState
|
56 | }) => ownerState.formControl,
|
57 | style: {
|
58 | 'label + &': {
|
59 | marginTop: 16
|
60 | }
|
61 | }
|
62 | }, {
|
63 | props: ({
|
64 | ownerState
|
65 | }) => !ownerState.disableUnderline,
|
66 | style: {
|
67 | '&::after': {
|
68 | left: 0,
|
69 | bottom: 0,
|
70 | content: '""',
|
71 | position: 'absolute',
|
72 | right: 0,
|
73 | transform: 'scaleX(0)',
|
74 | transition: theme.transitions.create('transform', {
|
75 | duration: theme.transitions.duration.shorter,
|
76 | easing: theme.transitions.easing.easeOut
|
77 | }),
|
78 | pointerEvents: 'none'
|
79 | },
|
80 | [`&.${inputClasses.focused}:after`]: {
|
81 |
|
82 |
|
83 | transform: 'scaleX(1) translateX(0)'
|
84 | },
|
85 | [`&.${inputClasses.error}`]: {
|
86 | '&::before, &::after': {
|
87 | borderBottomColor: (theme.vars || theme).palette.error.main
|
88 | }
|
89 | },
|
90 | '&::before': {
|
91 | borderBottom: `1px solid ${bottomLineColor}`,
|
92 | left: 0,
|
93 | bottom: 0,
|
94 | content: '"\\00a0"',
|
95 | position: 'absolute',
|
96 | right: 0,
|
97 | transition: theme.transitions.create('border-bottom-color', {
|
98 | duration: theme.transitions.duration.shorter
|
99 | }),
|
100 | pointerEvents: 'none'
|
101 | },
|
102 | [`&:hover:not(.${inputClasses.disabled}, .${inputClasses.error}):before`]: {
|
103 | borderBottom: `2px solid ${(theme.vars || theme).palette.text.primary}`,
|
104 |
|
105 | '@media (hover: none)': {
|
106 | borderBottom: `1px solid ${bottomLineColor}`
|
107 | }
|
108 | },
|
109 | [`&.${inputClasses.disabled}:before`]: {
|
110 | borderBottomStyle: 'dotted'
|
111 | }
|
112 | }
|
113 | }, ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter()).map(([color]) => ({
|
114 | props: {
|
115 | color,
|
116 | disableUnderline: false
|
117 | },
|
118 | style: {
|
119 | '&::after': {
|
120 | borderBottom: `2px solid ${(theme.vars || theme).palette[color].main}`
|
121 | }
|
122 | }
|
123 | }))]
|
124 | };
|
125 | }));
|
126 | const InputInput = styled(InputBaseInput, {
|
127 | name: 'MuiInput',
|
128 | slot: 'Input',
|
129 | overridesResolver: inputBaseInputOverridesResolver
|
130 | })({});
|
131 | const Input = React.forwardRef(function Input(inProps, ref) {
|
132 | const props = useDefaultProps({
|
133 | props: inProps,
|
134 | name: 'MuiInput'
|
135 | });
|
136 | const {
|
137 | disableUnderline = false,
|
138 | components = {},
|
139 | componentsProps: componentsPropsProp,
|
140 | fullWidth = false,
|
141 | inputComponent = 'input',
|
142 | multiline = false,
|
143 | slotProps,
|
144 | slots = {},
|
145 | type = 'text',
|
146 | ...other
|
147 | } = props;
|
148 | const classes = useUtilityClasses(props);
|
149 | const ownerState = {
|
150 | disableUnderline
|
151 | };
|
152 | const inputComponentsProps = {
|
153 | root: {
|
154 | ownerState
|
155 | }
|
156 | };
|
157 | const componentsProps = slotProps ?? componentsPropsProp ? deepmerge(slotProps ?? componentsPropsProp, inputComponentsProps) : inputComponentsProps;
|
158 | const RootSlot = slots.root ?? components.Root ?? InputRoot;
|
159 | const InputSlot = slots.input ?? components.Input ?? InputInput;
|
160 | return _jsx(InputBase, {
|
161 | slots: {
|
162 | root: RootSlot,
|
163 | input: InputSlot
|
164 | },
|
165 | slotProps: componentsProps,
|
166 | fullWidth: fullWidth,
|
167 | inputComponent: inputComponent,
|
168 | multiline: multiline,
|
169 | ref: ref,
|
170 | type: type,
|
171 | ...other,
|
172 | classes: classes
|
173 | });
|
174 | });
|
175 | process.env.NODE_ENV !== "production" ? Input.propTypes = {
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 | autoComplete: PropTypes.string,
|
186 | |
187 |
|
188 |
|
189 | autoFocus: PropTypes.bool,
|
190 | |
191 |
|
192 |
|
193 | classes: PropTypes.object,
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary']), PropTypes.string]),
|
201 | |
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | components: PropTypes.shape({
|
209 | Input: PropTypes.elementType,
|
210 | Root: PropTypes.elementType
|
211 | }),
|
212 | |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | componentsProps: PropTypes.shape({
|
221 | input: PropTypes.object,
|
222 | root: PropTypes.object
|
223 | }),
|
224 | |
225 |
|
226 |
|
227 | defaultValue: PropTypes.any,
|
228 | |
229 |
|
230 |
|
231 |
|
232 | disabled: PropTypes.bool,
|
233 | |
234 |
|
235 |
|
236 |
|
237 | disableUnderline: PropTypes.bool,
|
238 | |
239 |
|
240 |
|
241 | endAdornment: PropTypes.node,
|
242 | |
243 |
|
244 |
|
245 |
|
246 | error: PropTypes.bool,
|
247 | |
248 |
|
249 |
|
250 |
|
251 | fullWidth: PropTypes.bool,
|
252 | |
253 |
|
254 |
|
255 | id: PropTypes.string,
|
256 | |
257 |
|
258 |
|
259 |
|
260 |
|
261 | inputComponent: PropTypes.elementType,
|
262 | |
263 |
|
264 |
|
265 |
|
266 | inputProps: PropTypes.object,
|
267 | |
268 |
|
269 |
|
270 | inputRef: refType,
|
271 | |
272 |
|
273 |
|
274 |
|
275 |
|
276 | margin: PropTypes.oneOf(['dense', 'none']),
|
277 | |
278 |
|
279 |
|
280 | maxRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
281 | |
282 |
|
283 |
|
284 | minRows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
285 | |
286 |
|
287 |
|
288 |
|
289 | multiline: PropTypes.bool,
|
290 | |
291 |
|
292 |
|
293 | name: PropTypes.string,
|
294 | |
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 | onChange: PropTypes.func,
|
301 | |
302 |
|
303 |
|
304 | placeholder: PropTypes.string,
|
305 | |
306 |
|
307 |
|
308 |
|
309 | readOnly: PropTypes.bool,
|
310 | |
311 |
|
312 |
|
313 |
|
314 | required: PropTypes.bool,
|
315 | |
316 |
|
317 |
|
318 | rows: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
319 | |
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | slotProps: PropTypes.shape({
|
328 | input: PropTypes.object,
|
329 | root: PropTypes.object
|
330 | }),
|
331 | |
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | slots: PropTypes.shape({
|
339 | input: PropTypes.elementType,
|
340 | root: PropTypes.elementType
|
341 | }),
|
342 | |
343 |
|
344 |
|
345 | startAdornment: PropTypes.node,
|
346 | |
347 |
|
348 |
|
349 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
350 | |
351 |
|
352 |
|
353 |
|
354 | type: PropTypes.string,
|
355 | |
356 |
|
357 |
|
358 | value: PropTypes.any
|
359 | } : void 0;
|
360 | if (Input) {
|
361 | Input.muiName = 'Input';
|
362 | }
|
363 | export default Input; |
\ | No newline at end of file |