UNPKG

5.51 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _Typography = _interopRequireDefault(require("../Typography"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _FormControlContext = _interopRequireWildcard(require("../FormControl/FormControlContext"));
27
28var styles = {
29 /* Styles applied to the root element. */
30 root: {
31 display: 'flex',
32 height: '0.01em',
33 // Fix IE 11 flexbox alignment. To remove at some point.
34 maxHeight: '2em',
35 alignItems: 'center',
36 whiteSpace: 'nowrap'
37 },
38
39 /* Styles applied to the root element if `variant="filled"`. */
40 filled: {
41 '&$positionStart:not($hiddenLabel)': {
42 marginTop: 16
43 }
44 },
45
46 /* Styles applied to the root element if `position="start"`. */
47 positionStart: {
48 marginRight: 8
49 },
50
51 /* Styles applied to the root element if `position="end"`. */
52 positionEnd: {
53 marginLeft: 8
54 },
55
56 /* Styles applied to the root element if `disablePointerEvents=true`. */
57 disablePointerEvents: {
58 pointerEvents: 'none'
59 },
60
61 /* Styles applied if the adornment is used inside <FormControl hiddenLabel />. */
62 hiddenLabel: {},
63
64 /* Styles applied if the adornment is used inside <FormControl margin="dense" />. */
65 marginDense: {}
66};
67exports.styles = styles;
68var InputAdornment = /*#__PURE__*/React.forwardRef(function InputAdornment(props, ref) {
69 var children = props.children,
70 classes = props.classes,
71 className = props.className,
72 _props$component = props.component,
73 Component = _props$component === void 0 ? 'div' : _props$component,
74 _props$disablePointer = props.disablePointerEvents,
75 disablePointerEvents = _props$disablePointer === void 0 ? false : _props$disablePointer,
76 _props$disableTypogra = props.disableTypography,
77 disableTypography = _props$disableTypogra === void 0 ? false : _props$disableTypogra,
78 position = props.position,
79 variantProp = props.variant,
80 other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "component", "disablePointerEvents", "disableTypography", "position", "variant"]);
81 var muiFormControl = (0, _FormControlContext.useFormControl)() || {};
82 var variant = variantProp;
83
84 if (variantProp && muiFormControl.variant) {
85 if (process.env.NODE_ENV !== 'production') {
86 if (variantProp === muiFormControl.variant) {
87 console.error('Material-UI: The `InputAdornment` variant infers the variant prop ' + 'you do not have to provide one.');
88 }
89 }
90 }
91
92 if (muiFormControl && !variant) {
93 variant = muiFormControl.variant;
94 }
95
96 return /*#__PURE__*/React.createElement(_FormControlContext.default.Provider, {
97 value: null
98 }, /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
99 className: (0, _clsx.default)(classes.root, className, disablePointerEvents && classes.disablePointerEvents, muiFormControl.hiddenLabel && classes.hiddenLabel, variant === 'filled' && classes.filled, {
100 'start': classes.positionStart,
101 'end': classes.positionEnd
102 }[position], muiFormControl.margin === 'dense' && classes.marginDense),
103 ref: ref
104 }, other), typeof children === 'string' && !disableTypography ? /*#__PURE__*/React.createElement(_Typography.default, {
105 color: "textSecondary"
106 }, children) : children));
107});
108process.env.NODE_ENV !== "production" ? InputAdornment.propTypes = {
109 /**
110 * The content of the component, normally an `IconButton` or string.
111 */
112 children: _propTypes.default.node.isRequired,
113
114 /**
115 * Override or extend the styles applied to the component.
116 * See [CSS API](#css) below for more details.
117 */
118 classes: _propTypes.default.object.isRequired,
119
120 /**
121 * @ignore
122 */
123 className: _propTypes.default.string,
124
125 /**
126 * The component used for the root node.
127 * Either a string to use a HTML element or a component.
128 */
129 component: _propTypes.default
130 /* @typescript-to-proptypes-ignore */
131 .elementType,
132
133 /**
134 * Disable pointer events on the root.
135 * This allows for the content of the adornment to focus the input on click.
136 */
137 disablePointerEvents: _propTypes.default.bool,
138
139 /**
140 * If children is a string then disable wrapping in a Typography component.
141 */
142 disableTypography: _propTypes.default.bool,
143
144 /**
145 * @ignore
146 */
147 muiFormControl: _propTypes.default.object,
148
149 /**
150 * The position this adornment should appear relative to the `Input`.
151 */
152 position: _propTypes.default.oneOf(['start', 'end']),
153
154 /**
155 * The variant to use.
156 * Note: If you are using the `TextField` component or the `FormControl` component
157 * you do not have to set this manually.
158 */
159 variant: _propTypes.default.oneOf(['standard', 'outlined', 'filled'])
160} : void 0;
161
162var _default = (0, _withStyles.default)(styles, {
163 name: 'MuiInputAdornment'
164})(InputAdornment);
165
166exports.default = _default;
\No newline at end of file