0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-12 06:42:40 +00:00
Files
homebrewery/client/splatsheet/sheetRenderer/parts/textInput/textInput.jsx
2016-04-06 00:45:58 -04:00

46 lines
889 B
JavaScript

var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
var TextInput = React.createClass({
getDefaultProps: function() {
return {
data : {},
defaultValue : '',
onChange : function(){},
id : 'textInput',
label : '',
};
},
id : function(){
return _.snakeCase(this.props.label) || this.props.id;
},
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(e){
this.props.onChange({
[this.id()] : e.target.value
});
},
renderLabel : function(){
if(!this.props.label) return;
return <label htmlFor={this.id()}>{this.props.label}</label>
},
render : function(){
return <div className='textInput'>
{this.renderLabel()}
<input id={this.id()} type='text' onChange={this.handleChange} value={this.data()} />
</div>
}
});
module.exports = TextInput;