Skip to content

Instantly share code, notes, and snippets.

@mkozhukharenko
Last active March 15, 2017 11:48
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 mkozhukharenko/9e10432f7b747c74b1b9c0f963b6f4ef to your computer and use it in GitHub Desktop.
Save mkozhukharenko/9e10432f7b747c74b1b9c0f963b6f4ef to your computer and use it in GitHub Desktop.
Form input component
import React, { PropTypes } from 'react';
import classNames from 'classnames'
let getFormInputClasses = ({valid, error}) => classNames('form-input', {
'form-input--error': !!error,
})
let FormInput = (props) => (
<span className={getFormInputClasses(props)}>
<input {...props}
type={props.type || 'test'}
className="form-input__field"
onChange={(e) => props.onChange(e.target.name, e.target.value)}/>
{props.error && <div className="form-input__error">{props.error}</div> }
</span>
)
FormInput.PropTypes = {
onChange: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
type: PropTypes.oneOf(['text', 'email', 'password']),
error: PropTypes.string,
placeholder: PropTypes.string,
};
export default FormInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment