Skip to content

Instantly share code, notes, and snippets.

@pjanik
Last active August 29, 2015 14:24
Show Gist options
  • Save pjanik/c2c57819ec977e8a9518 to your computer and use it in GitHub Desktop.
Save pjanik/c2c57819ec977e8a9518 to your computer and use it in GitHub Desktop.
Lab React interactive
export default class PressureInteractive extends React.Component {
constructor(props) {
super(props);
this.state = {
properties: {
temperature: 200
}
outputs: {
pressure: 0
}
};
}
onStart() {
this.refs.lab.script.start();
}
onStop() {
this.refs.lab.script.stop();
}
onPressureChange(e) {
// (This won't work, we would need to use React helpers)
this.setState({properties: {pressure: e.target.value}});
}
render() {
return (
<div className="interactive">
<LabFrameTop about="..."/>
// this.props.interactiveDef - Lab JSON
<LabComponent ref="lab" interactiveDef={this.props.interactiveDef} outputs={this.state.outputs} properties={this.state.properties}/>
<div>Pressure value: {this.state.outputs.pressure}</div>
<div>Temperature<input type="text" value={this.state.properties.pressure} onChange={this.onPressureChange}/></div>
<LabFrameBottom onStart={this.onStart} onStop={this.onStop}/>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment