Last active
March 15, 2017 11:48
-
-
Save mkozhukharenko/9e10432f7b747c74b1b9c0f963b6f4ef to your computer and use it in GitHub Desktop.
Form input component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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