Skip to content

Instantly share code, notes, and snippets.

@sirgallifrey
Created August 5, 2017 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirgallifrey/2b68dad15e5a68007e5bc50acf510ca2 to your computer and use it in GitHub Desktop.
Save sirgallifrey/2b68dad15e5a68007e5bc50acf510ca2 to your computer and use it in GitHub Desktop.
import Input from './input';
import Label from './label';
import FormGroup from './form-group';
export default function Field ({children, name, inline, ...props}) {
return (
<FormGroup inline={ inline }>
<Label inline={ inline } htmlFor={ name }>{ label }</Label>
<Input inline={ inline } { ...props } id={ name }>
{ children }
</Input>
</FormGroup>
)
}
function FormGroup (props) {
return (
<div className={`form-group ${inlineClass(props)} ${hasErroClass(props)}`}>
{props.children}
</div>
);
}
function inlineClass (props) {
return props.inline ? 'row' : '';
}
function hasErrorClass (props) {
return props.meta && props.meta.touched && props.meta.error ? 'has-error' : '';
}
function Input ({name, ...props}) {
return (
<div className={inlineClass(props)}>
<input { ...props } className="form-control" />
{ children }
</div>
);
}
function inlineClass(props) {
return props.inline ? 'col-md-10' : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment