Skip to content

Instantly share code, notes, and snippets.

@joshmvandercom
Created April 14, 2015 15:30
Show Gist options
  • Save joshmvandercom/d5e6b3ce85a5be4b5ee3 to your computer and use it in GitHub Desktop.
Save joshmvandercom/d5e6b3ce85a5be4b5ee3 to your computer and use it in GitHub Desktop.
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