react-kube
Version:
Kube CSS in React Components
119 lines (99 loc) • 4.57 kB
JavaScript
"use strict";
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; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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) subClass.__proto__ = superClass; }
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _classnames = require("classnames");
var _classnames2 = _interopRequireDefault(_classnames);
var Input = (function (_React$Component) {
function Input() {
_classCallCheck(this, Input);
if (_React$Component != null) {
_React$Component.apply(this, arguments);
}
}
_inherits(Input, _React$Component);
_createClass(Input, [{
key: "render",
value: function render() {
var styles = (0, _classnames2["default"])({
"input-error": this.props.error,
"input-success": this.props.success,
"input-gray": this.props.gray,
"input-big": this.props.big,
"input-small": this.props.small,
"input-smaller": this.props.smaller,
"input-on-black": this.props.black
});
styles += this.props.width ? " width-" + this.props.width : "";
var validation = _react2["default"].createElement(
"span",
null,
this.props.required ? _react2["default"].createElement(
"span",
{ className: "req" },
"* "
) : null,
this.props.description ? _react2["default"].createElement(
"span",
{ className: "forms-desc" },
" ",
this.props.description,
" "
) : null,
this.props.errorMessage && this.props.error ? _react2["default"].createElement(
"span",
{ className: "error" },
" ",
this.props.errorMessage
) : null,
this.props.successMessage && this.props.success ? _react2["default"].createElement(
"span",
{ className: "success" },
" ",
this.props.successMessage
) : null
);
var inputField = _react2["default"].createElement("input", { autoComplete: this.props.autoComplete, className: (0, _classnames2["default"])(this.props.className, styles), disabled: this.props.disabled, name: this.props.name, onBlur: this.props.onBlur, onChange: this.props.onChange, placeholder: this.props.placeholder, ref: this.props.ref, size: this.props.size, style: this.props.style, type: this.props.type, value: this.props.value });
if (this.props.label) {
return _react2["default"].createElement(
"label",
null,
this.props.label,
validation,
inputField
);
} else {
return _react2["default"].createElement(
"span",
null,
validation,
inputField
);
}
}
}]);
return Input;
})(_react2["default"].Component);
Input.propTypes = {
autoComplete: _react2["default"].PropTypes.string,
big: _react2["default"].PropTypes.bool,
black: _react2["default"].PropTypes.bool,
children: _react2["default"].PropTypes.node,
className: _react2["default"].PropTypes.string,
description: _react2["default"].PropTypes.string,
errorMessage: _react2["default"].PropTypes.string,
gray: _react2["default"].PropTypes.bool,
onBlur: _react2["default"].PropTypes.func,
onChange: _react2["default"].PropTypes.func,
small: _react2["default"].PropTypes.bool,
smaller: _react2["default"].PropTypes.bool,
style: _react2["default"].PropTypes.object,
successMessage: _react2["default"].PropTypes.string,
value: _react2["default"].PropTypes.string,
width: _react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.string, _react2["default"].PropTypes.number])
};
Input.defaultProps = { type: "text", width: "100" };
module.exports = Input;