Created
April 14, 2015 15:30
-
-
Save joshmvandercom/d5e6b3ce85a5be4b5ee3 to your computer and use it in GitHub Desktop.
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
var Input = React.createClass({ | |
propTypes: { | |
type: React.PropTypes.string, | |
label: React.PropTypes.string, | |
help: React.PropTypes.string, | |
className: React.PropTypes.string | |
}, | |
renderInput: function() { | |
switch(this.props.type) { | |
case 'text': | |
input = <input {...this.props} className={'form-control ' + this.props.className} ref="input" key="input" /> | |
break; | |
case 'textarea': | |
input = <textarea {...this.props} className={'form-control ' + this.props.className} ref="input" key="input" /> | |
break; | |
default: | |
input = <input {...this.props} className={'form-control ' + this.props.className} ref="input" key="input" /> | |
break; | |
} | |
return input; | |
}, | |
formLabel: function() { | |
if(this.props.label != '') { | |
return <label className="control-label">{this.props.label}</label> | |
} else { | |
return ''; | |
} | |
}, | |
formHint: function() { | |
if (this.props.help != '') { | |
return <span className="help-block">{this.props.help}</span> | |
} | |
}, | |
render: function() { | |
return ( | |
<div class="form-group"> | |
{this.formLabel()} | |
{this.renderInput()} | |
{this.formHint()} | |
</div> | |
) | |
} | |
}); | |
module.exports = Input; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment