Last active
April 8, 2019 02:36
-
-
Save leobauza/b040c848e1db24e5fa22c0c887b0a783 to your computer and use it in GitHub Desktop.
Traffic Light
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traffic Light | |
Power On* | |
power loss -> Power Off | |
Green* | |
tick -> Yellow | |
Yellow | |
tick -> Red | |
Red | |
tick -> Green | |
Power Off | |
power restored -> Power On | |
Red On* | |
tick -> Red Off | |
Red Off | |
tick -> Red On |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comp extends React.Component { | |
constructor(props) { | |
super(props) | |
console.log('hi') | |
} | |
render() { | |
return <h1>HI!</h1> | |
} | |
} | |
const Light = (props) => { | |
var styles = { | |
width: '20px', | |
height: '20px', | |
borderRadius: '10px', | |
marginBottom: '2px', | |
backgroundColor: props.color, | |
opacity: .25 | |
}; | |
if(props.isOn){ | |
styles.opacity = 1; | |
} | |
return ( | |
<div style={styles}></div> | |
) | |
} | |
const render = (model) => { | |
var active_light = model.active_states[0].name; | |
return ( | |
<div> | |
<Light color="Red" isOn={active_light === "Red" || active_light === "Red On"} /> | |
<Light color="Yellow" isOn={active_light === "Yellow"} /> | |
<Light color="Green" isOn={active_light === "Green"} /> | |
<button type="button" onClick={() => model.emit('tick')}>Tick</button> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment