UNPKG

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