UNPKG

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