0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 08:42:42 +00:00

Proof of concept working

This commit is contained in:
Scott Tolksdorf
2016-04-02 12:02:05 -04:00
parent e61e1a698d
commit 263257bfb8
16 changed files with 344 additions and 112 deletions

View File

@@ -0,0 +1,50 @@
var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
var Box = React.createClass({
getDefaultProps: function() {
return {
data : {},
onChange : function(){},
defaultValue : {},
id : 'box',
};
},
//Maybe remove
id : function(){
return _.snakeCase(this.props.label) || this.props.id;
},
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(newData){
this.props.onChange({
[this.id()] : _.extend(this.data(), newData)
});
},
renderChildren : function(){
return React.Children.map(this.props.children, (child)=>{
if(!React.isValidElement(child)) return null;
return React.cloneElement(child, {
onChange : this.handleChange,
data : this.data()
})
})
},
render : function(){
return <div className={cx('box', this.props.className)}>
{this.renderChildren()}
</div>
}
});
module.exports = Box;

View File

@@ -0,0 +1,3 @@
.COM{
}

View File

@@ -0,0 +1,4 @@
module.exports = {
TextInput : require('./textInput/textInput.jsx'),
PlayerInfo : require('./playerInfo/playerInfo.jsx'),
}

View File

@@ -0,0 +1,67 @@
var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
var TextInput = require('../textInput/textInput.jsx');
var Box = require('../box/box.jsx');
var PlayerInfo = React.createClass({
getDefaultProps: function() {
return {
data : {},
onChange : function(){},
id : 'playerInfo',
};
},
/*
id : function(){
return _.snakeCase(this.props.label) || this.props.id;
},
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(newData){
this.props.onChange({
[this.id()] : _.extend(this.data(), newData)
});
},
renderChildren : function(){
return React.Children.map(this.props.children, (child)=>{
return React.cloneElement(child, {
onChange : this.handleChange,
data : this.data()
})
})
},
*/
render : function(){
return <Box className='playerInfo' {...this.props}>
<TextInput id='name' label="Name" />
<TextInput id='class' label="Class" />
<TextInput id='race' label="Race" />
{this.props.children}
</Box>
}
/*{this.props.children}*/
/*
render : function(){
return <div className='playerInfo'>
<TextInput id='name' label="Name" onChange={this.handleChange} data={this.data()} />
<TextInput id='class' label="Class" onChange={this.handleChange} data={this.data()} />
<TextInput id='race' label="Race" onChange={this.handleChange} data={this.data()} />
{this.renderChildren()}
</div>
}
*/
});
module.exports = PlayerInfo;

View File

@@ -0,0 +1,3 @@
.playerInfo{
margin-bottom: 20px;
}

View File

@@ -0,0 +1,45 @@
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;

View File

@@ -0,0 +1,6 @@
.textInput{
label{
display: inline-block;
width : 50px;
}
}