135 lines
No EOL
5.8 KiB
JavaScript
135 lines
No EOL
5.8 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
var _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; };
|
|
|
|
var _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; }; }();
|
|
|
|
var _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
var _propTypes = require('prop-types');
|
|
|
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
|
|
var _classnames = require('classnames');
|
|
|
|
var _classnames2 = _interopRequireDefault(_classnames);
|
|
|
|
var _utils = require('./utils');
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _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; }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _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; }
|
|
|
|
function _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 */
|
|
|
|
var propTypes = {
|
|
children: _propTypes2.default.node,
|
|
type: _propTypes2.default.string,
|
|
size: _propTypes2.default.string,
|
|
bsSize: _propTypes2.default.string,
|
|
state: (0, _utils.deprecated)(_propTypes2.default.string, 'Please use the prop "valid"'),
|
|
valid: _propTypes2.default.bool,
|
|
tag: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]),
|
|
innerRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]),
|
|
static: (0, _utils.deprecated)(_propTypes2.default.bool, 'Please use the prop "plaintext"'),
|
|
plaintext: _propTypes2.default.bool,
|
|
addon: _propTypes2.default.bool,
|
|
className: _propTypes2.default.string,
|
|
cssModule: _propTypes2.default.object
|
|
};
|
|
|
|
var defaultProps = {
|
|
tag: 'p',
|
|
type: 'text'
|
|
};
|
|
|
|
var Input = function (_React$Component) {
|
|
_inherits(Input, _React$Component);
|
|
|
|
function Input() {
|
|
_classCallCheck(this, Input);
|
|
|
|
return _possibleConstructorReturn(this, (Input.__proto__ || Object.getPrototypeOf(Input)).apply(this, arguments));
|
|
}
|
|
|
|
_createClass(Input, [{
|
|
key: 'render',
|
|
value: function render() {
|
|
var _props = this.props,
|
|
className = _props.className,
|
|
cssModule = _props.cssModule,
|
|
type = _props.type,
|
|
bsSize = _props.bsSize,
|
|
state = _props.state,
|
|
valid = _props.valid,
|
|
tag = _props.tag,
|
|
addon = _props.addon,
|
|
staticInput = _props.static,
|
|
plaintext = _props.plaintext,
|
|
innerRef = _props.innerRef,
|
|
attributes = _objectWithoutProperties(_props, ['className', 'cssModule', 'type', 'bsSize', 'state', 'valid', 'tag', 'addon', 'static', 'plaintext', 'innerRef']);
|
|
|
|
var checkInput = ['radio', 'checkbox'].indexOf(type) > -1;
|
|
var isNotaNumber = new RegExp('\\D', 'g');
|
|
|
|
var fileInput = type === 'file';
|
|
var textareaInput = type === 'textarea';
|
|
var selectInput = type === 'select';
|
|
var Tag = selectInput || textareaInput ? type : 'input';
|
|
|
|
var formControlClass = 'form-control';
|
|
|
|
if (plaintext || staticInput) {
|
|
formControlClass = formControlClass + '-plaintext';
|
|
Tag = tag;
|
|
} else if (fileInput) {
|
|
formControlClass = formControlClass + '-file';
|
|
} else if (checkInput) {
|
|
if (addon) {
|
|
formControlClass = null;
|
|
} else {
|
|
formControlClass = 'form-check-input';
|
|
}
|
|
}
|
|
|
|
if (state && typeof valid === 'undefined') {
|
|
if (state === 'danger') {
|
|
valid = false;
|
|
} else if (state === 'success') {
|
|
valid = true;
|
|
}
|
|
}
|
|
|
|
if (attributes.size && isNotaNumber.test(attributes.size)) {
|
|
(0, _utils.warnOnce)('Please use the prop "bsSize" instead of the "size" to bootstrap\'s input sizing.');
|
|
bsSize = attributes.size;
|
|
delete attributes.size;
|
|
}
|
|
|
|
var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, valid === false && 'is-invalid', valid && 'is-valid', bsSize ? 'form-control-' + bsSize : false, formControlClass), cssModule);
|
|
|
|
if (Tag === 'input') {
|
|
attributes.type = type;
|
|
}
|
|
|
|
return _react2.default.createElement(Tag, _extends({}, attributes, { ref: innerRef, className: classes }));
|
|
}
|
|
}]);
|
|
|
|
return Input;
|
|
}(_react2.default.Component);
|
|
|
|
Input.propTypes = propTypes;
|
|
Input.defaultProps = defaultProps;
|
|
|
|
exports.default = Input; |