1 | 'use client';
|
2 |
|
3 | var _span;
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import capitalize from "../utils/capitalize.js";
|
9 | import Typography from "../Typography/index.js";
|
10 | import FormControlContext from "../FormControl/FormControlContext.js";
|
11 | import useFormControl from "../FormControl/useFormControl.js";
|
12 | import { styled } from "../zero-styled/index.js";
|
13 | import memoTheme from "../utils/memoTheme.js";
|
14 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
15 | import inputAdornmentClasses, { getInputAdornmentUtilityClass } from "./inputAdornmentClasses.js";
|
16 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
17 | const overridesResolver = (props, styles) => {
|
18 | const {
|
19 | ownerState
|
20 | } = props;
|
21 | return [styles.root, styles[`position${capitalize(ownerState.position)}`], ownerState.disablePointerEvents === true && styles.disablePointerEvents, styles[ownerState.variant]];
|
22 | };
|
23 | const useUtilityClasses = ownerState => {
|
24 | const {
|
25 | classes,
|
26 | disablePointerEvents,
|
27 | hiddenLabel,
|
28 | position,
|
29 | size,
|
30 | variant
|
31 | } = ownerState;
|
32 | const slots = {
|
33 | root: ['root', disablePointerEvents && 'disablePointerEvents', position && `position${capitalize(position)}`, variant, hiddenLabel && 'hiddenLabel', size && `size${capitalize(size)}`]
|
34 | };
|
35 | return composeClasses(slots, getInputAdornmentUtilityClass, classes);
|
36 | };
|
37 | const InputAdornmentRoot = styled('div', {
|
38 | name: 'MuiInputAdornment',
|
39 | slot: 'Root',
|
40 | overridesResolver
|
41 | })(memoTheme(({
|
42 | theme
|
43 | }) => ({
|
44 | display: 'flex',
|
45 | maxHeight: '2em',
|
46 | alignItems: 'center',
|
47 | whiteSpace: 'nowrap',
|
48 | color: (theme.vars || theme).palette.action.active,
|
49 | variants: [{
|
50 | props: {
|
51 | variant: 'filled'
|
52 | },
|
53 | style: {
|
54 | [`&.${inputAdornmentClasses.positionStart}&:not(.${inputAdornmentClasses.hiddenLabel})`]: {
|
55 | marginTop: 16
|
56 | }
|
57 | }
|
58 | }, {
|
59 | props: {
|
60 | position: 'start'
|
61 | },
|
62 | style: {
|
63 | marginRight: 8
|
64 | }
|
65 | }, {
|
66 | props: {
|
67 | position: 'end'
|
68 | },
|
69 | style: {
|
70 | marginLeft: 8
|
71 | }
|
72 | }, {
|
73 | props: {
|
74 | disablePointerEvents: true
|
75 | },
|
76 | style: {
|
77 | pointerEvents: 'none'
|
78 | }
|
79 | }]
|
80 | })));
|
81 | const InputAdornment = React.forwardRef(function InputAdornment(inProps, ref) {
|
82 | const props = useDefaultProps({
|
83 | props: inProps,
|
84 | name: 'MuiInputAdornment'
|
85 | });
|
86 | const {
|
87 | children,
|
88 | className,
|
89 | component = 'div',
|
90 | disablePointerEvents = false,
|
91 | disableTypography = false,
|
92 | position,
|
93 | variant: variantProp,
|
94 | ...other
|
95 | } = props;
|
96 | const muiFormControl = useFormControl() || {};
|
97 | let variant = variantProp;
|
98 | if (variantProp && muiFormControl.variant) {
|
99 | if (process.env.NODE_ENV !== 'production') {
|
100 | if (variantProp === muiFormControl.variant) {
|
101 | console.error('MUI: The `InputAdornment` variant infers the variant prop ' + 'you do not have to provide one.');
|
102 | }
|
103 | }
|
104 | }
|
105 | if (muiFormControl && !variant) {
|
106 | variant = muiFormControl.variant;
|
107 | }
|
108 | const ownerState = {
|
109 | ...props,
|
110 | hiddenLabel: muiFormControl.hiddenLabel,
|
111 | size: muiFormControl.size,
|
112 | disablePointerEvents,
|
113 | position,
|
114 | variant
|
115 | };
|
116 | const classes = useUtilityClasses(ownerState);
|
117 | return _jsx(FormControlContext.Provider, {
|
118 | value: null,
|
119 | children: _jsx(InputAdornmentRoot, {
|
120 | as: component,
|
121 | ownerState: ownerState,
|
122 | className: clsx(classes.root, className),
|
123 | ref: ref,
|
124 | ...other,
|
125 | children: typeof children === 'string' && !disableTypography ? _jsx(Typography, {
|
126 | color: "textSecondary",
|
127 | children: children
|
128 | }) : _jsxs(React.Fragment, {
|
129 | children: [position === 'start' ? (_span || (_span = _jsx("span", {
|
130 | className: "notranslate",
|
131 | children: "\u200B"
|
132 | }))) : null, children]
|
133 | })
|
134 | })
|
135 | });
|
136 | });
|
137 | process.env.NODE_ENV !== "production" ? InputAdornment.propTypes = {
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | |
143 |
|
144 |
|
145 | children: PropTypes.node,
|
146 | |
147 |
|
148 |
|
149 | classes: PropTypes.object,
|
150 | |
151 |
|
152 |
|
153 | className: PropTypes.string,
|
154 | |
155 |
|
156 |
|
157 |
|
158 | component: PropTypes.elementType,
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 | disablePointerEvents: PropTypes.bool,
|
165 | |
166 |
|
167 |
|
168 |
|
169 | disableTypography: PropTypes.bool,
|
170 | |
171 |
|
172 |
|
173 | position: PropTypes.oneOf(['end', 'start']).isRequired,
|
174 | |
175 |
|
176 |
|
177 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
178 | |
179 |
|
180 |
|
181 |
|
182 |
|
183 | variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
|
184 | } : void 0;
|
185 | export default InputAdornment; |
\ | No newline at end of file |