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