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