UNPKG

@e-group/material-form

Version:

Custom react components for integrate redux-form.

47 lines (39 loc) 1.47 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import React from 'react'; import TextLoading from '@e-group/material/TextLoading'; import { fromJS } from '@e-group/immutable'; const TextLoadingField = props => { const _props$meta = props.meta, touched = _props$meta.touched, error = _props$meta.error, invalid = _props$meta.invalid, asyncValidating = _props$meta.asyncValidating, errorProp = props.error, helperText = props.helperText, InputProps = props.InputProps, other = _objectWithoutProperties(props, ["meta", "error", "helperText", "InputProps"]); const isError = touched && invalid; const handleMultipleSelectOnChange = e => { props.input.onChange(fromJS(e.target.value)); }; const getInput = () => { const input = props.input, select = props.select, SelectProps = props.SelectProps; if (select && SelectProps && SelectProps.multiple) { return { value: input.value ? input.value.toJS() : [], onChange: handleMultipleSelectOnChange }; } return input; }; return /*#__PURE__*/React.createElement(TextLoading, _extends({ error: isError, loading: asyncValidating, helperText: isError ? error : helperText, InputProps: InputProps }, getInput(), other)); }; export default TextLoadingField;