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, disablePointerEvents && classes.disablePointerEvents, muiFormControl.hiddenLabel && classes.hiddenLabel, variant === 'filled' && classes.filled, {
|
80 | 'start': classes.positionStart,
|
81 | 'end': classes.positionEnd
|
82 | }[position], muiFormControl.margin === 'dense' && classes.marginDense),
|
83 | ref: ref
|
84 | }, other), typeof children === 'string' && !disableTypography ? React.createElement(Typography, {
|
85 | color: "textSecondary"
|
86 | }, children) : children));
|
87 | });
|
88 | process.env.NODE_ENV !== "production" ? InputAdornment.propTypes = {
|
89 | |
90 |
|
91 |
|
92 | children: PropTypes.node.isRequired,
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 | classes: PropTypes.object.isRequired,
|
99 |
|
100 | |
101 |
|
102 |
|
103 | className: PropTypes.string,
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 | component: PropTypes
|
110 |
|
111 | .elementType,
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 | disablePointerEvents: PropTypes.bool,
|
118 |
|
119 | |
120 |
|
121 |
|
122 | disableTypography: PropTypes.bool,
|
123 |
|
124 | |
125 |
|
126 |
|
127 | muiFormControl: PropTypes.object,
|
128 |
|
129 | |
130 |
|
131 |
|
132 | position: PropTypes.oneOf(['start', 'end']),
|
133 |
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 | variant: PropTypes.oneOf(['standard', 'outlined', 'filled'])
|
140 | } : void 0;
|
141 | export default withStyles(styles, {
|
142 | name: 'MuiInputAdornment'
|
143 | })(InputAdornment); |
\ | No newline at end of file |