@e-group/material-form
Version:
Custom react components for integrate redux-form.
56 lines (48 loc) • 2.7 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import RadioGroup from '@e-group/material/RadioGroup';
export default class RadioGroupField extends Component {
render() {
const _this$props = this.props,
input = _this$props.input,
_this$props$meta = _this$props.meta,
touched = _this$props$meta.touched,
invalid = _this$props$meta.invalid,
error = _this$props$meta.error,
options = _this$props.options,
errorProp = _this$props.error,
helperText = _this$props.helperText,
MuiRadioGroupProps = _this$props.MuiRadioGroupProps,
other = _objectWithoutProperties(_this$props, ["input", "meta", "options", "error", "helperText", "MuiRadioGroupProps"]);
const _ref = MuiRadioGroupProps || {},
valueProp = _ref.value,
onChangeProp = _ref.onChange,
otherMuiRadioGroupProps = _objectWithoutProperties(_ref, ["value", "onChange"]);
const isError = touched && invalid;
return /*#__PURE__*/React.createElement(RadioGroup, _extends({
options: options,
MuiRadioGroupProps: _objectSpread({
value: input.value,
onChange: input.onChange
}, otherMuiRadioGroupProps),
error: isError,
helperText: isError ? error : helperText
}, other));
}
}
_defineProperty(RadioGroupField, "propTypes", {
/**
* redux from props
*/
input: PropTypes.object.isRequired,
meta: PropTypes.object.isRequired,
/**
* Mui `RadioGroup` props
*/
MuiRadioGroupProps: PropTypes.object
});