doj-react-adminlte
Version:
Simple and easy-to-use AdminLTE components for React
169 lines (126 loc) • 7.69 kB
JavaScript
;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _helpBlockStyle = _interopRequireDefault(require("../helpBlockStyle"));
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 _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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var TextInput = /*#__PURE__*/function (_React$Component) {
_inherits(TextInput, _React$Component);
var _super = _createSuper(TextInput);
function TextInput() {
var _this;
_classCallCheck(this, TextInput);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_this.handleChange = function (event) {
_this.props.onChange(_this.props.name, event.target.value);
};
_this.handleKeyUp = function (event) {
if (event.key === 'Enter' && _this.props.onEnterKey) {
_this.props.onEnterKey();
}
if (_this.props.onKeyUp) {
_this.props.onKeyUp(event);
}
};
return _this;
}
_createClass(TextInput, [{
key: "render",
value: function render() {
var _this$props = this.props,
gridClass = _this$props.gridClass,
feedbackIconClass = _this$props.feedbackIconClass,
feedbackIconLeft = _this$props.feedbackIconLeft;
if (feedbackIconClass) {
gridClass += " has-feedback";
}
if (feedbackIconLeft) {
gridClass += " has-feedback-left";
}
var value = this.props.value || ""; // Check for form errors
var errors = this.props.errors[this.props.name] || [];
return /*#__PURE__*/_react.default.createElement("div", {
className: "form-group " + (errors.length > 0 ? "has-error " : "") + gridClass
}, this.props.label && /*#__PURE__*/_react.default.createElement("label", null, this.props.label), /*#__PURE__*/_react.default.createElement("input", {
placeholder: this.props.placeholder,
className: "form-control",
type: this.props.type,
onChange: this.handleChange,
value: value,
onKeyUp: this.handleKeyUp,
disabled: this.props.disabled,
maxLength: this.props.maxLength
}), feedbackIconClass && /*#__PURE__*/_react.default.createElement("span", {
className: feedbackIconClass + " form-control-feedback"
}), errors.length > 0 && /*#__PURE__*/_react.default.createElement("ul", {
className: "help-block",
style: _helpBlockStyle.default
}, errors.map(function (e, index) {
return /*#__PURE__*/_react.default.createElement("li", {
key: index
}, /*#__PURE__*/_react.default.createElement("span", null, e));
})));
}
}]);
return TextInput;
}(_react.default.Component);
TextInput.defaultProps = {
disabled: false,
errors: {},
gridClass: "",
feedbackIconLeft: false,
onChange: function onChange() {},
type: "text"
};
TextInput.propTypes = process.env.NODE_ENV !== "production" ? {
/** If true, user won't be able to interact with the component.*/
disabled: _propTypes.default.bool,
errors: _propTypes.default.objectOf(_propTypes.default.arrayOf(_propTypes.default.string)),
/** Specifies the icon class to be displayed within the component */
feedbackIconClass: _propTypes.default.string,
/** When set to true, the icon is placed at the left side of the component*/
feedbackIconLeft: _propTypes.default.bool,
/** Layout that arranges views of the component */
gridClass: _propTypes.default.string,
/** Specifies the text to use as the label */
label: _propTypes.default.node,
/** Specifies the name of the component. It is used to distinguish elements
* when a single form change handler is used. */
name: _propTypes.default.string.isRequired,
/** Callback fired when component value changes. Accepts a function with two parameters, namely field and value */
onChange: _propTypes.default.func,
// TODO:
//onEnterKey: PropTypes.func,
// TODO:
//onKeyUp: PropTypes.func,
/** Specifies a short hint that describes the expected value of
* an input field */
placeholder: _propTypes.default.string,
/** Specifies the maximum number of characters allowed in the
* component */
maxLength: _propTypes.default.number,
/** Specifies the type. Can be one of: text, password */
type: _propTypes.default.oneOf(['text', 'password']),
/** Specifies the current value for an input field */
value: _propTypes.default.string
} : {};
TextInput.isFormComponent = true;
var _default = TextInput;
exports.default = _default;