Created
January 3, 2018 16:02
-
-
Save thomasmaclean/b4f9605870731fe754e451e50e128c70 to your computer and use it in GitHub Desktop.
This file contains 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, { Component, PropTypes } from 'react'; | |
import stringToClassName from '../helpers/stringToClassName'; | |
export default class FieldInput extends Component { | |
static propTypes = { | |
input: PropTypes.shape({ | |
name: PropTypes.string, | |
value: PropTypes.string, | |
onChange: PropTypes.func | |
}), | |
type: PropTypes.string, | |
label: PropTypes.string, | |
required: PropTypes.bool, | |
description: PropTypes.string, | |
meta: PropTypes.shape({ | |
touched: PropTypes.bool, | |
error: PropTypes.string | |
}) | |
}; | |
render() { | |
const {input, label, type, description, required, meta: {touched, error}} = this.props; | |
return ( | |
<div className="md-text-field with-floating-label"> | |
<input { ...input} className={touched && error ? 'has-error' : ''} id={stringToClassName(input.name)} type={type} required={required} /> | |
<label htmlFor={stringToClassName(input.name)}>{label} {this.props.required ? <span>*</span> : ''}</label> | |
{touched && error && <small className="error">{error}</small>} | |
{ description ? <p>{description}</p> : ''} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment