@shusen73/react-trafficlight

5.2.2 • Public • Published

react-trafficlight

Traffic light component for React. Modified from https://github.com/sgnh/react-trafficlight

Traffic light

Installation

npm i @shusen73/react-trafficlight

Usage example 1

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;

Usage example 2 - Clickable

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;

Usage example 3 - Horizontal

import React from 'react';
import TrafficLight from 'react-trafficlight';

const TrafficLightContainerExample3 = () => (
  <div>
    <TrafficLight GreenOn Horizontal/>
  </div>
);

export default TrafficLightContainerExample3;

Package Sidebar

Install

npm i @shusen73/react-trafficlight

Weekly Downloads

1

Version

5.2.2

License

MIT

Unpacked Size

4.09 kB

Total Files

4

Last publish

Collaborators

  • shusen73