1 | import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
4 | import classNames from 'classnames';
|
5 | import React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import elementType from 'prop-types-extra/lib/elementType';
|
8 | import warning from 'warning';
|
9 | import FormControlFeedback from './FormControlFeedback';
|
10 | import FormControlStatic from './FormControlStatic';
|
11 | import { prefix, bsClass, getClassSet, splitBsProps, bsSizes } from './utils/bootstrapUtils';
|
12 | import { SIZE_MAP, Size } from './utils/StyleConfig';
|
13 | var propTypes = {
|
14 | componentClass: elementType,
|
15 |
|
16 | |
17 |
|
18 |
|
19 | type: PropTypes.string,
|
20 |
|
21 | |
22 |
|
23 |
|
24 | id: PropTypes.string,
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | inputRef: PropTypes.func
|
34 | };
|
35 | var defaultProps = {
|
36 | componentClass: 'input'
|
37 | };
|
38 | var contextTypes = {
|
39 | $bs_formGroup: PropTypes.object
|
40 | };
|
41 |
|
42 | var FormControl =
|
43 |
|
44 | function (_React$Component) {
|
45 | _inheritsLoose(FormControl, _React$Component);
|
46 |
|
47 | function FormControl() {
|
48 | return _React$Component.apply(this, arguments) || this;
|
49 | }
|
50 |
|
51 | var _proto = FormControl.prototype;
|
52 |
|
53 | _proto.render = function render() {
|
54 | var formGroup = this.context.$bs_formGroup;
|
55 | var controlId = formGroup && formGroup.controlId;
|
56 |
|
57 | var _this$props = this.props,
|
58 | Component = _this$props.componentClass,
|
59 | type = _this$props.type,
|
60 | _this$props$id = _this$props.id,
|
61 | id = _this$props$id === void 0 ? controlId : _this$props$id,
|
62 | inputRef = _this$props.inputRef,
|
63 | className = _this$props.className,
|
64 | bsSize = _this$props.bsSize,
|
65 | props = _objectWithoutPropertiesLoose(_this$props, ["componentClass", "type", "id", "inputRef", "className", "bsSize"]);
|
66 |
|
67 | var _splitBsProps = splitBsProps(props),
|
68 | bsProps = _splitBsProps[0],
|
69 | elementProps = _splitBsProps[1];
|
70 |
|
71 | process.env.NODE_ENV !== "production" ? warning(controlId == null || id === controlId, '`controlId` is ignored on `<FormControl>` when `id` is specified.') : void 0;
|
72 |
|
73 | var classes;
|
74 |
|
75 | if (type !== 'file') {
|
76 | classes = getClassSet(bsProps);
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 | if (bsSize) {
|
82 | var size = SIZE_MAP[bsSize] || bsSize;
|
83 | classes[prefix({
|
84 | bsClass: 'input'
|
85 | }, size)] = true;
|
86 | }
|
87 |
|
88 | return React.createElement(Component, _extends({}, elementProps, {
|
89 | type: type,
|
90 | id: id,
|
91 | ref: inputRef,
|
92 | className: classNames(className, classes)
|
93 | }));
|
94 | };
|
95 |
|
96 | return FormControl;
|
97 | }(React.Component);
|
98 |
|
99 | FormControl.propTypes = propTypes;
|
100 | FormControl.defaultProps = defaultProps;
|
101 | FormControl.contextTypes = contextTypes;
|
102 | FormControl.Feedback = FormControlFeedback;
|
103 | FormControl.Static = FormControlStatic;
|
104 | export default bsClass('form-control', bsSizes([Size.SMALL, Size.LARGE], FormControl)); |
\ | No newline at end of file |