UNPKG

7.08 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _extends from "@babel/runtime/helpers/esm/extends";
4
5var _span;
6
7import * as React from 'react';
8import PropTypes from 'prop-types';
9import clsx from 'clsx';
10import { unstable_composeClasses as composeClasses } from '@mui/base';
11import capitalize from '../utils/capitalize';
12import Typography from '../Typography';
13import FormControlContext from '../FormControl/FormControlContext';
14import useFormControl from '../FormControl/useFormControl';
15import styled from '../styles/styled';
16import inputAdornmentClasses, { getInputAdornmentUtilityClass } from './inputAdornmentClasses';
17import useThemeProps from '../styles/useThemeProps';
18import { jsx as _jsx } from "react/jsx-runtime";
19import { jsxs as _jsxs } from "react/jsx-runtime";
20
21var overridesResolver = function overridesResolver(props, styles) {
22 var ownerState = props.ownerState;
23 return [styles.root, styles["position".concat(capitalize(ownerState.position))], ownerState.disablePointerEvents === true && styles.disablePointerEvents, styles[ownerState.variant]];
24};
25
26var useUtilityClasses = function useUtilityClasses(ownerState) {
27 var classes = ownerState.classes,
28 disablePointerEvents = ownerState.disablePointerEvents,
29 hiddenLabel = ownerState.hiddenLabel,
30 position = ownerState.position,
31 size = ownerState.size,
32 variant = ownerState.variant;
33 var slots = {
34 root: ['root', disablePointerEvents && 'disablePointerEvents', position && "position".concat(capitalize(position)), variant, hiddenLabel && 'hiddenLabel', size && "size".concat(capitalize(size))]
35 };
36 return composeClasses(slots, getInputAdornmentUtilityClass, classes);
37};
38
39var InputAdornmentRoot = styled('div', {
40 name: 'MuiInputAdornment',
41 slot: 'Root',
42 overridesResolver: overridesResolver
43})(function (_ref) {
44 var theme = _ref.theme,
45 ownerState = _ref.ownerState;
46 return _extends({
47 display: 'flex',
48 height: '0.01em',
49 // Fix IE11 flexbox alignment. To remove at some point.
50 maxHeight: '2em',
51 alignItems: 'center',
52 whiteSpace: 'nowrap',
53 color: (theme.vars || theme).palette.action.active
54 }, ownerState.variant === 'filled' && _defineProperty({}, "&.".concat(inputAdornmentClasses.positionStart, "&:not(.").concat(inputAdornmentClasses.hiddenLabel, ")"), {
55 marginTop: 16
56 }), ownerState.position === 'start' && {
57 // Styles applied to the root element if `position="start"`.
58 marginRight: 8
59 }, ownerState.position === 'end' && {
60 // Styles applied to the root element if `position="end"`.
61 marginLeft: 8
62 }, ownerState.disablePointerEvents === true && {
63 // Styles applied to the root element if `disablePointerEvents={true}`.
64 pointerEvents: 'none'
65 });
66});
67var InputAdornment = /*#__PURE__*/React.forwardRef(function InputAdornment(inProps, ref) {
68 var props = useThemeProps({
69 props: inProps,
70 name: 'MuiInputAdornment'
71 });
72
73 var children = props.children,
74 className = props.className,
75 _props$component = props.component,
76 component = _props$component === void 0 ? 'div' : _props$component,
77 _props$disablePointer = props.disablePointerEvents,
78 disablePointerEvents = _props$disablePointer === void 0 ? false : _props$disablePointer,
79 _props$disableTypogra = props.disableTypography,
80 disableTypography = _props$disableTypogra === void 0 ? false : _props$disableTypogra,
81 position = props.position,
82 variantProp = props.variant,
83 other = _objectWithoutProperties(props, ["children", "className", "component", "disablePointerEvents", "disableTypography", "position", "variant"]);
84
85 var muiFormControl = useFormControl() || {};
86 var variant = variantProp;
87
88 if (variantProp && muiFormControl.variant) {
89 if (process.env.NODE_ENV !== 'production') {
90 if (variantProp === muiFormControl.variant) {
91 console.error('MUI: The `InputAdornment` variant infers the variant prop ' + 'you do not have to provide one.');
92 }
93 }
94 }
95
96 if (muiFormControl && !variant) {
97 variant = muiFormControl.variant;
98 }
99
100 var ownerState = _extends({}, props, {
101 hiddenLabel: muiFormControl.hiddenLabel,
102 size: muiFormControl.size,
103 disablePointerEvents: disablePointerEvents,
104 position: position,
105 variant: variant
106 });
107
108 var classes = useUtilityClasses(ownerState);
109 return /*#__PURE__*/_jsx(FormControlContext.Provider, {
110 value: null,
111 children: /*#__PURE__*/_jsx(InputAdornmentRoot, _extends({
112 as: component,
113 ownerState: ownerState,
114 className: clsx(classes.root, className),
115 ref: ref
116 }, other, {
117 children: typeof children === 'string' && !disableTypography ? /*#__PURE__*/_jsx(Typography, {
118 color: "text.secondary",
119 children: children
120 }) : /*#__PURE__*/_jsxs(React.Fragment, {
121 children: [position === 'start' ?
122 /* notranslate needed while Google Translate will not fix zero-width space issue */
123 _span || (_span = /*#__PURE__*/_jsx("span", {
124 className: "notranslate",
125 children: "\u200B"
126 })) : null, children]
127 })
128 }))
129 });
130});
131process.env.NODE_ENV !== "production" ? InputAdornment.propTypes
132/* remove-proptypes */
133= {
134 // ----------------------------- Warning --------------------------------
135 // | These PropTypes are generated from the TypeScript type definitions |
136 // | To update them edit the d.ts file and run "yarn proptypes" |
137 // ----------------------------------------------------------------------
138
139 /**
140 * The content of the component, normally an `IconButton` or string.
141 */
142 children: PropTypes.node,
143
144 /**
145 * Override or extend the styles applied to the component.
146 */
147 classes: PropTypes.object,
148
149 /**
150 * @ignore
151 */
152 className: PropTypes.string,
153
154 /**
155 * The component used for the root node.
156 * Either a string to use a HTML element or a component.
157 */
158 component: PropTypes.elementType,
159
160 /**
161 * Disable pointer events on the root.
162 * This allows for the content of the adornment to focus the `input` on click.
163 * @default false
164 */
165 disablePointerEvents: PropTypes.bool,
166
167 /**
168 * If children is a string then disable wrapping in a Typography component.
169 * @default false
170 */
171 disableTypography: PropTypes.bool,
172
173 /**
174 * The position this adornment should appear relative to the `Input`.
175 */
176 position: PropTypes.oneOf(['end', 'start']).isRequired,
177
178 /**
179 * The system prop that allows defining system overrides as well as additional CSS styles.
180 */
181 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
182
183 /**
184 * The variant to use.
185 * Note: If you are using the `TextField` component or the `FormControl` component
186 * you do not have to set this manually.
187 */
188 variant: PropTypes.oneOf(['filled', 'outlined', 'standard'])
189} : void 0;
190export default InputAdornment;
\No newline at end of file