Skip to content

Instantly share code, notes, and snippets.

@kasprownik
Last active February 3, 2016 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasprownik/d6a29d39b87365317c6b to your computer and use it in GitHub Desktop.
Save kasprownik/d6a29d39b87365317c6b to your computer and use it in GitHub Desktop.
// src/components/Text.js
import React, { PropTypes } from 'react';
import TextField from 'material-ui/lib/text-field';
export default React.createClass({
displayName: 'Text',
propTypes: {
name: PropTypes.string.isRequired,
placeholder: PropTypes.string,
label: PropTypes.string
},
contextTypes: {
update: PropTypes.func.isRequired,
values: PropTypes.object.isRequired
},
updateValue(value) {
this.context.update(this.props.name, value);
},
onChange(event) {
this.updateValue(event.target.value)
},
render() {
return (
<div>
<TextField
hintText={this.props.placeholder}
floatingLabelText={this.props.label}
value={this.context.values[this.props.name]}
onChange={this.onChange}/>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment