Traffic light component for React.
npm install --save react-trafficlight
Working demo on CodePen: React Traffic Light
import React from 'react';
import TrafficLight from 'react-trafficlight';
const TrafficLightContainerExample1 = () => (
<div>
<TrafficLight RedOn />
<TrafficLight RedOn YellowOn />
<TrafficLight YellowOn />
<TrafficLight GreenOn />
</div>
);
export default TrafficLightContainerExample1;
import React, { Component } from 'react';
import TrafficLight from 'react-trafficlight';
class TrafficLightContainerExample2 extends Component {
state = {
redOn: true,
yellowOn: false,
greenOn: false,
}
render() {
return (
<TrafficLight
onRedClick={() => this.setState({ redOn: !this.state.redOn })}
onYellowClick={() => this.setState({ yellowOn: !this.state.yellowOn })}
onGreenClick={() => this.setState({ greenOn: !this.state.greenOn })}
RedOn={this.state.redOn}
YellowOn={this.state.yellowOn}
GreenOn={this.state.greenOn}
/>
);
}
}
export default TrafficLightContainerExample2;
import React from 'react';
import TrafficLight from 'react-trafficlight';
const TrafficLightContainerExample3 = () => (
<div>
<TrafficLight GreenOn Horizontal/>
</div>
);
export default TrafficLightContainerExample3;