1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import Typography from '../Typography';
|
7 | import withStyles from '../styles/withStyles';
|
8 | import FormControlContext, { useFormControl } from '../FormControl/FormControlContext';
|
9 | export const styles = {
|
10 |
|
11 | root: {
|
12 | display: 'flex',
|
13 | height: '0.01em',
|
14 |
|
15 | maxHeight: '2em',
|
16 | alignItems: 'center',
|
17 | whiteSpace: 'nowrap'
|
18 | },
|
19 |
|
20 |
|
21 | filled: {
|
22 | '&$positionStart:not($hiddenLabel)': {
|
23 | marginTop: 16
|
24 | }
|
25 | },
|
26 |
|
27 |
|
28 | positionStart: {
|
29 | marginRight: 8
|
30 | },
|
31 |
|
32 |
|
33 | positionEnd: {
|
34 | marginLeft: 8
|
35 | },
|
36 |
|
37 |
|
38 | disablePointerEvents: {
|
39 | pointerEvents: 'none'
|
40 | },
|
41 |
|
42 |
|
43 | hiddenLabel: {},
|
44 |
|
45 |
|
46 | marginDense: {}
|
47 | };
|
48 | const InputAdornment = React.forwardRef(function InputAdornment(props, ref) {
|
49 | const {
|
50 | children,
|
51 | classes,
|
52 | className,
|
53 | component: Component = 'div',
|
54 | disablePointerEvents = false,
|
55 | disableTypography = false,
|
56 | position,
|
57 | variant: variantProp
|
58 | } = props,
|
59 | other = _objectWithoutPropertiesLoose(props, ["children", "classes", "className", "component", "disablePointerEvents", "disableTypography", "position", "variant"]);
|
60 |
|
61 | const muiFormControl = useFormControl() || {};
|
62 | let variant = variantProp;
|
63 |
|
64 | if (variantProp && muiFormControl.variant) {
|
65 | if (process.env.NODE_ENV !== 'production') {
|
66 | if (variantProp === muiFormControl.variant) {
|
67 | console.error('Material-UI: The `InputAdornment` variant infers the variant prop ' + 'you do not have to provide one.');
|
68 | }
|
69 | }
|
70 | }
|
71 |
|
72 | if (muiFormControl && !variant) {
|
73 | variant = muiFormControl.variant;
|
74 | }
|
75 |
|
76 | return React.createElement(FormControlContext.Provider, {
|
77 | value: null
|
78 | }, React.createElement(Component, _extends({
|
79 | className: clsx(classes.root, className, position === 'end' ? classes.positionEnd : classes.positionStart, disablePointerEvents && classes.disablePointerEvents, muiFormControl.hiddenLabel && classes.hiddenLabel, variant === 'filled' && classes.filled, muiFormControl.margin === 'dense' && classes.marginDense),
|
80 | ref: ref
|
81 | }, other), typeof children === 'string' && !disableTypography ? React.createElement(Typography, {
|
82 | color: "textSecondary"
|
83 | }, children) : children));
|
84 | });
|
85 | process.env.NODE_ENV !== "production" ? InputAdornment.propTypes = {
|
86 | |
87 |
|
88 |
|
89 | children: PropTypes.node.isRequired,
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 | classes: PropTypes.object.isRequired,
|
96 |
|
97 | |
98 |
|
99 |
|
100 | className: PropTypes.string,
|
101 |
|
102 | |
103 |
|
104 |
|
105 |
|
106 | component: PropTypes
|
107 |
|
108 | .elementType,
|
109 |
|
110 | |
111 |
|
112 |
|
113 |
|
114 | disablePointerEvents: PropTypes.bool,
|
115 |
|
116 | |
117 |
|
118 |
|
119 | disableTypography: PropTypes.bool,
|
120 |
|
121 | |
122 |
|
123 |
|
124 | muiFormControl: PropTypes.object,
|
125 |
|
126 | |
127 |
|
128 |
|
129 | position: PropTypes.oneOf(['start', 'end']).isRequired,
|
130 |
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 | variant: PropTypes.oneOf(['standard', 'outlined', 'filled'])
|
137 | } : void 0;
|
138 | export default withStyles(styles, {
|
139 | name: 'MuiInputAdornment'
|
140 | })(InputAdornment); |
\ | No newline at end of file |