UNPKG

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