Backport labels & placeholders for Editable text from Vector

This commit is contained in:
David Baker 2015-09-16 14:18:25 +01:00
parent 6cca5f4c05
commit 25ab56106a

View file

@ -21,7 +21,9 @@ var React = require('react');
module.exports = { module.exports = {
propTypes: { propTypes: {
onValueChanged: React.PropTypes.func, onValueChanged: React.PropTypes.func,
initalValue: React.PropTypes.string, initialValue: React.PropTypes.string,
label: React.PropTypes.string,
placeHolder: React.PropTypes.string,
}, },
Phases: { Phases: {
@ -32,37 +34,55 @@ module.exports = {
getDefaultProps: function() { getDefaultProps: function() {
return { return {
onValueChanged: function() {}, onValueChanged: function() {},
initalValue: '', initialValue: '',
label: 'Click to set',
placeholder: '',
}; };
}, },
getInitialState: function() { getInitialState: function() {
return { return {
value: this.props.initalValue, value: this.props.initialValue,
phase: this.Phases.Display, phase: this.Phases.Display,
} }
}, },
componentWillReceiveProps: function(nextProps) {
this.setState({
value: nextProps.initialValue
});
},
getValue: function() { getValue: function() {
return this.state.value; return this.state.value;
}, },
setValue: function(val) { setValue: function(val, shouldSubmit, suppressListener) {
var self = this;
this.setState({ this.setState({
value: val, value: val,
phase: this.Phases.Display, phase: this.Phases.Display,
}, function() {
if (!suppressListener) {
self.onValueChanged(shouldSubmit);
}
}); });
},
this.onValueChanged(); edit: function() {
this.setState({
phase: this.Phases.Edit,
});
}, },
cancelEdit: function() { cancelEdit: function() {
this.setState({ this.setState({
phase: this.Phases.Display, phase: this.Phases.Display,
}); });
this.onValueChanged(false);
}, },
onValueChanged: function() { onValueChanged: function(shouldSubmit) {
this.props.onValueChanged(this.state.value); this.props.onValueChanged(this.state.value, shouldSubmit);
}, },
}; };