UNPKG

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