Skip to content

Instantly share code, notes, and snippets.

@apps-manager
Created August 13, 2018 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apps-manager/6c1a24d65ad06c7b651a7a44fc478d11 to your computer and use it in GitHub Desktop.
Save apps-manager/6c1a24d65ad06c7b651a7a44fc478d11 to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import {FlexCol} from 'pivotal-ui/react/flex-grids';
import {FormUnit} from 'pivotal-ui/react/forms';
import classnames from 'classnames';
export class FormCol extends React.Component {
static propTypes = {
state: PropTypes.object,
canSubmit: PropTypes.func,
onSubmit: PropTypes.func,
canReset: PropTypes.func,
reset: PropTypes.func,
hidden: PropTypes.bool,
fixed: PropTypes.bool,
colProps: PropTypes.object,
setValues: PropTypes.func
};
static defaultProps = {state: {}, colProps: {}};
render() {
const {state, canSubmit, onSubmit, canReset, reset, fixed, children, hidden, className, id, setValues, colProps} = this.props;
let child = typeof children === 'function'
? children({canSubmit, canReset, setValues, reset, onSubmit, submitting: state.submitting, state})
: children;
if (!colProps.name) {
// eslint-disable-next-line no-unused-vars
const {className: _, ...rest} = colProps;
child = (
<FormUnit {...{
// retainLabelHeight,
hasError: state.errors && !!state.errors[colProps.name],
// labelFor: htmlFor,
state,
...rest,
children: child
// help: (state.errors && state.errors[name]) || help
}}/>
);
}
return (
<FlexCol {...{className: classnames(className, 'form-col', {'col-fixed': fixed}), id, hidden}}>
{child}
</FlexCol>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment