react-json-schema-form
Version:
Fully customizable Fastest rendering JS/ Json Schema driven React Forms that support validations, POST , Success and Error Alerts , callbacks , React Components (Input, Switch, Checkbox, Radio) renders device o.s theme (iOS,Android and Windows) by default
256 lines (238 loc) • 9.24 kB
JavaScript
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 _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; }
import React, { Component } from "react";
import PropTypes from "prop-types";
import uuid from "uuid";
import Input from "./Input";
import FloatInput from "./FloatInput";
import Checkbox from "./Checkbox";
import Radio from "./Radio";
import PlaceInput from "./PlaceInput";
/**
* React Input automatically check and render Switch, Radio, Checkbox and Input depending on type
* @param {*} props
*/
var BaseInput = function (_Component) {
_inherits(BaseInput, _Component);
function BaseInput() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, BaseInput);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = BaseInput.__proto__ || Object.getPrototypeOf(BaseInput)).call.apply(_ref, [this].concat(args))), _this), _this.componentWillReceiveProps = function (nextProps) {}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(BaseInput, [{
key: "render",
value: function render() {
var _props = this.props,
type = _props.type,
value = _props.value,
inputStyle = _props.inputStyle,
inputClass = _props.inputClass,
onValueChange = _props.onValueChange,
labelClass = _props.labelClass,
labelStyle = _props.labelStyle,
labelText = _props.labelText,
showBorder = _props.showBorder,
showRoundBorder = _props.showRoundBorder,
noBorder = _props.noBorder,
showAnimation = _props.showAnimation,
floatLabel = _props.floatLabel,
borderClass = _props.borderClass,
theme = _props.theme,
validateOn = _props.validateOn,
validateRules = _props.validateRules,
borderStyle = _props.borderStyle,
radioBtnClassName = _props.radioBtnClassName,
radioBtnStyle = _props.radioBtnStyle,
radioTextClassName = _props.radioTextClassName,
radioTextStyle = _props.radioTextStyle,
radioGroupName = _props.radioGroupName,
radioOptions = _props.radioOptions,
defaultValue = _props.defaultValue,
rest = _objectWithoutProperties(_props, ["type", "value", "inputStyle", "inputClass", "onValueChange", "labelClass", "labelStyle", "labelText", "showBorder", "showRoundBorder", "noBorder", "showAnimation", "floatLabel", "borderClass", "theme", "validateOn", "validateRules", "borderStyle", "radioBtnClassName", "radioBtnStyle", "radioTextClassName", "radioTextStyle", "radioGroupName", "radioOptions", "defaultValue"]);
var id = this.props.id ? this.props.id : uuid.v4();
if (type === "checkbox") return React.createElement(Checkbox, Object.assign({
labelClass: labelClass,
labelText: labelText,
labelStyle: labelStyle,
inputStyle: inputStyle,
checked: value,
inputClass: inputClass,
onValueChange: onValueChange,
id: id,
theme: theme
}, rest));
if (type === "place") {
return React.createElement(PlaceInput, Object.assign({
labelClass: labelClass,
labelText: labelText,
labelStyle: labelStyle,
inputStyle: inputStyle,
inputClass: inputClass,
id: id,
value: value,
onValueChange: onValueChange
}, rest));
}
if (type === "radio") return React.createElement(Radio, {
labelClass: labelClass,
labelText: labelText,
labelStyle: labelStyle,
radioBtnClassName: radioBtnClassName,
radioBtnStyle: radioBtnStyle,
radioTextClassName: radioTextClassName,
radioTextStyle: radioTextStyle,
radioGroupName: radioGroupName,
onValueChange: onValueChange,
radioOptions: radioOptions,
defaultValue: defaultValue,
theme: theme
});
return floatLabel || theme === "android" ? React.createElement(FloatInput, Object.assign({
labelClass: labelClass,
labelText: labelText,
labelStyle: labelStyle,
inputStyle: inputStyle,
inputClass: inputClass,
borderClass: borderClass,
borderStyle: borderStyle,
onValueChange: onValueChange,
value: value,
id: id,
type: type,
validateOn: validateOn,
validateRules: validateRules
}, rest)) : React.createElement(Input, Object.assign({
labelClass: labelClass,
labelText: labelText,
labelStyle: labelStyle,
inputStyle: inputStyle,
inputClass: inputClass,
showBorder: showBorder,
showRoundBorder: showRoundBorder,
noBorder: noBorder,
showAnimation: showAnimation,
onValueChange: onValueChange,
theme: theme,
type: type,
value: value,
validateOn: validateOn,
validateRules: validateRules
}, rest, {
id: id
}));
}
}]);
return BaseInput;
}(Component);
BaseInput.propTypes = {
/**
* Label Text to display
*/
labelText: PropTypes.string,
/**
* Style label with css class
*/
labelClass: PropTypes.string,
/**
* Style Label with React style object
*/
labelStyle: PropTypes.object,
/**
* Style input with css class
*/
inputClass: PropTypes.string,
/**
* Style Input with React Style Object
*/
inputStyle: PropTypes.object,
/**
* Show bordered input
*/
showBorder: PropTypes.bool,
/**
* Set true show rounded border as in iOS
*/
showRoundBorder: PropTypes.bool,
/**
* Set true remove Border from input box
*/
noBorder: PropTypes.bool,
/**
* Set true animate input
*/
showAnimation: PropTypes.bool,
/**
* Float Input / Material Design or Android Input Border bottom css Class
*/
borderClass: PropTypes.string,
/**
* Float Input / Material Design or Android Input Border bottom React Style Object
*/
borderStyle: PropTypes.object,
/**
* Input Unique Identifier ,
* Id will be passed with OnChange / OnBlur events to Uniquely Identify from Multiple Inputs
*/
id: PropTypes.string.isRequired,
/**
* On value change callback Function raised for onBlur and onChange, this is a required property
*/
onValueChange: PropTypes.func.isRequired,
/**
* Input theme property
* You can override by passing theme
* Default to Android theme
* override by supplying ios for IOS theme and win for Windows theme
*/
theme: PropTypes.string,
/**
* Radio Button CSS Class Name to customize
*/
radioBtnClassName: PropTypes.string,
/**
* Radio Button Style to customize
*/
radioBtnStyle: PropTypes.object,
/**
* Radio button Text Css Class
*/
radioTextClassName: PropTypes.string,
/**
* Radio Button Text Style
*/
radioTextStyle: PropTypes.object,
/**
* Radio Buttons Group Name
*/
radioGroupName: PropTypes.string,
/**
* Array of Radio buttons with {value:'',disabled:'',text:''} objects in it
*/
radioOptions: PropTypes.array,
/**
* Default Selected Radio Value
*/
defaultValue: PropTypes.string
};
BaseInput.defaultProps = {
labelText: "Label",
inputClass: "",
inputStyle: {},
labelClass: "",
labelStyle: {},
placeholder: "",
showBorder: true,
showRoundBorder: false,
noBorder: false,
showAnimation: false,
floatLabel: false,
theme: ""
};
export default BaseInput;