UNPKG

4.91 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
9var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
11var _react = require('react');
12
13var _react2 = _interopRequireDefault(_react);
14
15var _classnames = require('classnames');
16
17var _classnames2 = _interopRequireDefault(_classnames);
18
19var _utils = require('./utils');
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
24
25function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
27function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
28
29function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint react/prefer-stateless-function: 0 */
30
31var propTypes = {
32 children: _react.PropTypes.node,
33 type: _react.PropTypes.string,
34 size: _react.PropTypes.string,
35 state: _react.PropTypes.string,
36 tag: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]),
37 getRef: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]),
38 static: _react.PropTypes.bool,
39 addon: _react.PropTypes.bool,
40 className: _react.PropTypes.string,
41 cssModule: _react.PropTypes.object
42};
43
44var defaultProps = {
45 tag: 'p',
46 type: 'text'
47};
48
49var Input = function (_React$Component) {
50 _inherits(Input, _React$Component);
51
52 function Input() {
53 _classCallCheck(this, Input);
54
55 return _possibleConstructorReturn(this, (Input.__proto__ || Object.getPrototypeOf(Input)).apply(this, arguments));
56 }
57
58 _createClass(Input, [{
59 key: 'render',
60 value: function render() {
61 var _props = this.props,
62 className = _props.className,
63 cssModule = _props.cssModule,
64 type = _props.type,
65 size = _props.size,
66 state = _props.state,
67 tag = _props.tag,
68 addon = _props.addon,
69 staticInput = _props.static,
70 getRef = _props.getRef,
71 attributes = _objectWithoutProperties(_props, ['className', 'cssModule', 'type', 'size', 'state', 'tag', 'addon', 'static', 'getRef']);
72
73 var checkInput = ['radio', 'checkbox'].indexOf(type) > -1;
74
75 var fileInput = type === 'file';
76 var textareaInput = type === 'textarea';
77 var selectInput = type === 'select';
78 var Tag = selectInput || textareaInput ? type : 'input';
79
80 var formControlClass = 'form-control';
81
82 if (staticInput) {
83 formControlClass = formControlClass + '-static';
84 Tag = tag;
85 } else if (fileInput) {
86 formControlClass = formControlClass + '-file';
87 } else if (checkInput) {
88 if (addon) {
89 formControlClass = null;
90 } else {
91 formControlClass = 'form-check-input';
92 }
93 }
94
95 var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, state ? 'form-control-' + state : false, size ? 'form-control-' + size : false, formControlClass), cssModule);
96
97 if (Tag === 'input') {
98 attributes.type = type;
99 }
100
101 return _react2.default.createElement(Tag, _extends({}, attributes, { ref: getRef, className: classes }));
102 }
103 }]);
104
105 return Input;
106}(_react2.default.Component);
107
108Input.propTypes = propTypes;
109Input.defaultProps = defaultProps;
110
111exports.default = Input;
\No newline at end of file