UNPKG

10.4 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 _NotchedOutline = _interopRequireDefault(require("./NotchedOutline"));
27
28var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
29
30var styles = function styles(theme) {
31 var borderColor = theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)';
32 return {
33 /* Styles applied to the root element. */
34 root: {
35 position: 'relative',
36 borderRadius: theme.shape.borderRadius,
37 '&:hover $notchedOutline': {
38 borderColor: theme.palette.text.primary
39 },
40 // Reset on touch devices, it doesn't add specificity
41 '@media (hover: none)': {
42 '&:hover $notchedOutline': {
43 borderColor: borderColor
44 }
45 },
46 '&$focused $notchedOutline': {
47 borderColor: theme.palette.primary.main,
48 borderWidth: 2
49 },
50 '&$error $notchedOutline': {
51 borderColor: theme.palette.error.main
52 },
53 '&$disabled $notchedOutline': {
54 borderColor: theme.palette.action.disabled
55 }
56 },
57
58 /* Styles applied to the root element if the color is secondary. */
59 colorSecondary: {
60 '&$focused $notchedOutline': {
61 borderColor: theme.palette.secondary.main
62 }
63 },
64
65 /* Styles applied to the root element if the component is focused. */
66 focused: {},
67
68 /* Styles applied to the root element if `disabled={true}`. */
69 disabled: {},
70
71 /* Styles applied to the root element if `startAdornment` is provided. */
72 adornedStart: {
73 paddingLeft: 14
74 },
75
76 /* Styles applied to the root element if `endAdornment` is provided. */
77 adornedEnd: {
78 paddingRight: 14
79 },
80
81 /* Pseudo-class applied to the root element if `error={true}`. */
82 error: {},
83
84 /* Styles applied to the `input` element if `margin="dense"`. */
85 marginDense: {},
86
87 /* Styles applied to the root element if `multiline={true}`. */
88 multiline: {
89 padding: '18.5px 14px',
90 '&$marginDense': {
91 paddingTop: 10.5,
92 paddingBottom: 10.5
93 }
94 },
95
96 /* Styles applied to the `NotchedOutline` element. */
97 notchedOutline: {
98 borderColor: borderColor
99 },
100
101 /* Styles applied to the `input` element. */
102 input: {
103 padding: '18.5px 14px',
104 '&:-webkit-autofill': {
105 WebkitBoxShadow: theme.palette.type === 'light' ? null : '0 0 0 100px #266798 inset',
106 WebkitTextFillColor: theme.palette.type === 'light' ? null : '#fff',
107 caretColor: theme.palette.type === 'light' ? null : '#fff',
108 borderRadius: 'inherit'
109 }
110 },
111
112 /* Styles applied to the `input` element if `margin="dense"`. */
113 inputMarginDense: {
114 paddingTop: 10.5,
115 paddingBottom: 10.5
116 },
117
118 /* Styles applied to the `input` element if `multiline={true}`. */
119 inputMultiline: {
120 padding: 0
121 },
122
123 /* Styles applied to the `input` element if `startAdornment` is provided. */
124 inputAdornedStart: {
125 paddingLeft: 0
126 },
127
128 /* Styles applied to the `input` element if `endAdornment` is provided. */
129 inputAdornedEnd: {
130 paddingRight: 0
131 }
132 };
133};
134
135exports.styles = styles;
136var OutlinedInput = /*#__PURE__*/React.forwardRef(function OutlinedInput(props, ref) {
137 var classes = props.classes,
138 _props$fullWidth = props.fullWidth,
139 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
140 _props$inputComponent = props.inputComponent,
141 inputComponent = _props$inputComponent === void 0 ? 'input' : _props$inputComponent,
142 label = props.label,
143 _props$labelWidth = props.labelWidth,
144 labelWidth = _props$labelWidth === void 0 ? 0 : _props$labelWidth,
145 _props$multiline = props.multiline,
146 multiline = _props$multiline === void 0 ? false : _props$multiline,
147 notched = props.notched,
148 _props$type = props.type,
149 type = _props$type === void 0 ? 'text' : _props$type,
150 other = (0, _objectWithoutProperties2.default)(props, ["classes", "fullWidth", "inputComponent", "label", "labelWidth", "multiline", "notched", "type"]);
151 return /*#__PURE__*/React.createElement(_InputBase.default, (0, _extends2.default)({
152 renderSuffix: function renderSuffix(state) {
153 return /*#__PURE__*/React.createElement(_NotchedOutline.default, {
154 className: classes.notchedOutline,
155 label: label,
156 labelWidth: labelWidth,
157 notched: typeof notched !== 'undefined' ? notched : Boolean(state.startAdornment || state.filled || state.focused)
158 });
159 },
160 classes: (0, _extends2.default)({}, classes, {
161 root: (0, _clsx.default)(classes.root, classes.underline),
162 notchedOutline: null
163 }),
164 fullWidth: fullWidth,
165 inputComponent: inputComponent,
166 multiline: multiline,
167 ref: ref,
168 type: type
169 }, other));
170});
171process.env.NODE_ENV !== "production" ? OutlinedInput.propTypes = {
172 // ----------------------------- Warning --------------------------------
173 // | These PropTypes are generated from the TypeScript type definitions |
174 // | To update them edit the d.ts file and run "yarn proptypes" |
175 // ----------------------------------------------------------------------
176
177 /**
178 * This prop helps users to fill forms faster, especially on mobile devices.
179 * The name can be confusing, as it's more like an autofill.
180 * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).
181 */
182 autoComplete: _propTypes.default.string,
183
184 /**
185 * If `true`, the `input` element will be focused during the first mount.
186 */
187 autoFocus: _propTypes.default.bool,
188
189 /**
190 * Override or extend the styles applied to the component.
191 * See [CSS API](#css) below for more details.
192 */
193 classes: _propTypes.default.object,
194
195 /**
196 * The color of the component. It supports those theme colors that make sense for this component.
197 */
198 color: _propTypes.default.oneOf(['primary', 'secondary']),
199
200 /**
201 * The default `input` element value. Use when the component is not controlled.
202 */
203 defaultValue: _propTypes.default.any,
204
205 /**
206 * If `true`, the `input` element will be disabled.
207 */
208 disabled: _propTypes.default.bool,
209
210 /**
211 * End `InputAdornment` for this component.
212 */
213 endAdornment: _propTypes.default.node,
214
215 /**
216 * If `true`, the input will indicate an error. This is normally obtained via context from
217 * FormControl.
218 */
219 error: _propTypes.default.bool,
220
221 /**
222 * If `true`, the input will take up the full width of its container.
223 */
224 fullWidth: _propTypes.default.bool,
225
226 /**
227 * The id of the `input` element.
228 */
229 id: _propTypes.default.string,
230
231 /**
232 * The component used for the `input` element.
233 * Either a string to use a HTML element or a component.
234 */
235 inputComponent: _propTypes.default.elementType,
236
237 /**
238 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
239 */
240 inputProps: _propTypes.default.object,
241
242 /**
243 * Pass a ref to the `input` element.
244 */
245 inputRef: _utils.refType,
246
247 /**
248 * The label of the input. It is only used for layout. The actual labelling
249 * is handled by `InputLabel`. If specified `labelWidth` is ignored.
250 */
251 label: _propTypes.default.node,
252
253 /**
254 * The width of the label. Is ignored if `label` is provided. Prefer `label`
255 * if the input label appears with a strike through.
256 */
257 labelWidth: _propTypes.default.number,
258
259 /**
260 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
261 * FormControl.
262 */
263 margin: _propTypes.default.oneOf(['dense', 'none']),
264
265 /**
266 * Maximum number of rows to display when multiline option is set to true.
267 */
268 maxRows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
269
270 /**
271 * If `true`, a textarea element will be rendered.
272 */
273 multiline: _propTypes.default.bool,
274
275 /**
276 * Name attribute of the `input` element.
277 */
278 name: _propTypes.default.string,
279
280 /**
281 * If `true`, the outline is notched to accommodate the label.
282 */
283 notched: _propTypes.default.bool,
284
285 /**
286 * Callback fired when the value is changed.
287 *
288 * @param {object} event The event source of the callback.
289 * You can pull out the new value by accessing `event.target.value` (string).
290 */
291 onChange: _propTypes.default.func,
292
293 /**
294 * The short hint displayed in the input before the user enters a value.
295 */
296 placeholder: _propTypes.default.string,
297
298 /**
299 * It prevents the user from changing the value of the field
300 * (not from interacting with the field).
301 */
302 readOnly: _propTypes.default.bool,
303
304 /**
305 * If `true`, the `input` element will be required.
306 */
307 required: _propTypes.default.bool,
308
309 /**
310 * Number of rows to display when multiline option is set to true.
311 */
312 rows: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
313
314 /**
315 * Start `InputAdornment` for this component.
316 */
317 startAdornment: _propTypes.default.node,
318
319 /**
320 * 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).
321 */
322 type: _propTypes.default.string,
323
324 /**
325 * The value of the `input` element, required for a controlled component.
326 */
327 value: _propTypes.default.any
328} : void 0;
329OutlinedInput.muiName = 'Input';
330
331var _default = (0, _withStyles.default)(styles, {
332 name: 'MuiOutlinedInput'
333})(OutlinedInput);
334
335exports.default = _default;
\No newline at end of file