UNPKG

9.7 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 _utils = require("@material-ui/utils");
23
24var _InputBase = _interopRequireDefault(require("../InputBase"));
25
26var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
27
28var styles = function styles(theme) {
29 var light = theme.palette.type === 'light';
30 var bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
31 return {
32 /* Styles applied to the root element. */
33 root: {
34 position: 'relative'
35 },
36
37 /* Styles applied to the root element if the component is a descendant of `FormControl`. */
38 formControl: {
39 'label + &': {
40 marginTop: 16
41 }
42 },
43
44 /* Styles applied to the root element if the component is focused. */
45 focused: {},
46
47 /* Styles applied to the root element if `disabled={true}`. */
48 disabled: {},
49
50 /* Styles applied to the root element if color secondary. */
51 colorSecondary: {
52 '&$underline:after': {
53 borderBottomColor: theme.palette.secondary.main
54 }
55 },
56
57 /* Styles applied to the root element if `disableUnderline={false}`. */
58 underline: {
59 '&:after': {
60 borderBottom: "2px solid ".concat(theme.palette.primary.main),
61 left: 0,
62 bottom: 0,
63 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
64 content: '""',
65 position: 'absolute',
66 right: 0,
67 transform: 'scaleX(0)',
68 transition: theme.transitions.create('transform', {
69 duration: theme.transitions.duration.shorter,
70 easing: theme.transitions.easing.easeOut
71 }),
72 pointerEvents: 'none' // Transparent to the hover style.
73
74 },
75 '&$focused:after': {
76 transform: 'scaleX(1)'
77 },
78 '&$error:after': {
79 borderBottomColor: theme.palette.error.main,
80 transform: 'scaleX(1)' // error is always underlined in red
81
82 },
83 '&:before': {
84 borderBottom: "1px solid ".concat(bottomLineColor),
85 left: 0,
86 bottom: 0,
87 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
88 content: '"\\00a0"',
89 position: 'absolute',
90 right: 0,
91 transition: theme.transitions.create('border-bottom-color', {
92 duration: theme.transitions.duration.shorter
93 }),
94 pointerEvents: 'none' // Transparent to the hover style.
95
96 },
97 '&:hover:not($disabled):before': {
98 borderBottom: "2px solid ".concat(theme.palette.text.primary),
99 // Reset on touch devices, it doesn't add specificity
100 '@media (hover: none)': {
101 borderBottom: "1px solid ".concat(bottomLineColor)
102 }
103 },
104 '&$disabled:before': {
105 borderBottomStyle: 'dotted'
106 }
107 },
108
109 /* Pseudo-class applied to the root element if `error={true}`. */
110 error: {},
111
112 /* Styles applied to the `input` element if `margin="dense"`. */
113 marginDense: {},
114
115 /* Styles applied to the root element if `multiline={true}`. */
116 multiline: {},
117
118 /* Styles applied to the root element if `fullWidth={true}`. */
119 fullWidth: {},
120
121 /* Styles applied to the `input` element. */
122 input: {},
123
124 /* Styles applied to the `input` element if `margin="dense"`. */
125 inputMarginDense: {},
126
127 /* Styles applied to the `input` element if `multiline={true}`. */
128 inputMultiline: {},
129
130 /* Styles applied to the `input` element if `type="search"`. */
131 inputTypeSearch: {}
132 };
133};
134
135exports.styles = styles;
136var Input = /*#__PURE__*/React.forwardRef(function Input(props, ref) {
137 var disableUnderline = props.disableUnderline,
138 classes = props.classes,
139 _props$fullWidth = props.fullWidth,
140 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
141 _props$inputComponent = props.inputComponent,
142 inputComponent = _props$inputComponent === void 0 ? 'input' : _props$inputComponent,
143 _props$multiline = props.multiline,
144 multiline = _props$multiline === void 0 ? false : _props$multiline,
145 _props$type = props.type,
146 type = _props$type === void 0 ? 'text' : _props$type,
147 other = (0, _objectWithoutProperties2.default)(props, ["disableUnderline", "classes", "fullWidth", "inputComponent", "multiline", "type"]);
148 return /*#__PURE__*/React.createElement(_InputBase.default, (0, _extends2.default)({
149 classes: (0, _extends2.default)({}, classes, {
150 root: (0, _clsx.default)(classes.root, !disableUnderline && classes.underline),
151 underline: null
152 }),
153 fullWidth: fullWidth,
154 inputComponent: inputComponent,
155 multiline: multiline,
156 ref: ref,
157 type: type
158 }, other));
159});
160process.env.NODE_ENV !== "production" ? Input.propTypes = {
161 // ----------------------------- Warning --------------------------------
162 // | These PropTypes are generated from the TypeScript type definitions |
163 // | To update them edit the d.ts file and run "yarn proptypes" |
164 // ----------------------------------------------------------------------
165
166 /**
167 * This prop helps users to fill forms faster, especially on mobile devices.
168 * The name can be confusing, as it's more like an autofill.
169 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
170 */
171 autoComplete: _propTypes.default.string,
172
173 /**
174 * If `true`, the `input` element will be focused during the first mount.
175 */
176 autoFocus: _propTypes.default.bool,
177
178 /**
179 * Override or extend the styles applied to the component.
180 * See [CSS API](#css) below for more details.
181 */
182 classes: _propTypes.default.object,
183
184 /**
185 * The color of the component. It supports those theme colors that make sense for this component.
186 */
187 color: _propTypes.default.oneOf(['primary', 'secondary']),
188
189 /**
190 * The default `input` element value. Use when the component is not controlled.
191 */
192 defaultValue: _propTypes.default.any,
193
194 /**
195 * If `true`, the `input` element will be disabled.
196 */
197 disabled: _propTypes.default.bool,
198
199 /**
200 * If `true`, the input will not have an underline.
201 */
202 disableUnderline: _propTypes.default.bool,
203
204 /**
205 * End `InputAdornment` for this component.
206 */
207 endAdornment: _propTypes.default.node,
208
209 /**
210 * If `true`, the input will indicate an error. This is normally obtained via context from
211 * FormControl.
212 */
213 error: _propTypes.default.bool,
214
215 /**
216 * If `true`, the input will take up the full width of its container.
217 */
218 fullWidth: _propTypes.default.bool,
219
220 /**
221 * The id of the `input` element.
222 */
223 id: _propTypes.default.string,
224
225 /**
226 * The component used for the `input` element.
227 * Either a string to use a HTML element or a component.
228 */
229 inputComponent: _propTypes.default.elementType,
230
231 /**
232 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
233 */
234 inputProps: _propTypes.default.object,
235
236 /**
237 * Pass a ref to the `input` element.
238 */
239 inputRef: _utils.refType,
240
241 /**
242 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
243 * FormControl.
244 */
245 margin: _propTypes.default.oneOf(['dense', 'none']),
246
247 /**
248 * Maximum number of rows to display when multiline option is set to true.
249 */
250 maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
251
252 /**
253 * If `true`, a textarea element will be rendered.
254 */
255 multiline: _propTypes.default.bool,
256
257 /**
258 * Name attribute of the `input` element.
259 */
260 name: _propTypes.default.string,
261
262 /**
263 * Callback fired when the value is changed.
264 *
265 * @param {object} event The event source of the callback.
266 * You can pull out the new value by accessing `event.target.value` (string).
267 */
268 onChange: _propTypes.default.func,
269
270 /**
271 * The short hint displayed in the input before the user enters a value.
272 */
273 placeholder: _propTypes.default.string,
274
275 /**
276 * It prevents the user from changing the value of the field
277 * (not from interacting with the field).
278 */
279 readOnly: _propTypes.default.bool,
280
281 /**
282 * If `true`, the `input` element will be required.
283 */
284 required: _propTypes.default.bool,
285
286 /**
287 * Number of rows to display when multiline option is set to true.
288 */
289 rows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
290
291 /**
292 * Start `InputAdornment` for this component.
293 */
294 startAdornment: _propTypes.default.node,
295
296 /**
297 * Type of the `input` element. It should be [a valid HTML5 input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types).
298 */
299 type: _propTypes.default.string,
300
301 /**
302 * The value of the `input` element, required for a controlled component.
303 */
304 value: _propTypes.default.any
305} : void 0;
306Input.muiName = 'Input';
307
308var _default = (0, _withStyles.default)(styles, {
309 name: 'MuiInput'
310})(Input);
311
312exports.default = _default;
\No newline at end of file