npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-trafficsignal

v1.3.0

Published

Traffic Signal component for React.

Downloads

12

Readme

React-TrafficSignal

Traffic Signal component for React.

Screenshot 2023-02-22 at 17 49 46

Screenshot 2023-02-23 at 17 40 20


Install

npm install react-trafficsignal

Demo

Working demo on CodeSandbox.

API

Props

  • status - A three characters string (/^[rRB][aAB][gGB]$/):
    • B: Black/OFF
    • R: Red light ON
    • r: Red light flashing
    • A: Amber light ON
    • a: Amber light flashing
    • G: Green light ON
    • g: Green light flashing
  • options - Optional :
    • horizontal: traffic signal is rotated 90° counterclockwise (default:false )
    • clockwise: if horizontal is true then traffic signal is rotated clockwise (default:false )
    • width: sets the width CSS property of the traffic signal element (default: 100%).
    • margin: sets the margin CSS property of the traffic signal element (default: 0).
    • hideRed: hides the red light (default:false )
    • hideAmber: hides the amber light (default:false )
    • hideGreen: hides the green light (default:false )
  • signalID - Optional A unique signal ID (Number)
  • onRedClick - Optional OnClick callback function. Function parameters: Event, light status (/^[rRB]$/)
  • onAmberClick - Optional OnClick callback function. Function parameters: Event, light status (/^[aAB]$/)
  • onGreenClick - Optional OnClick callback function. Function parameters: Event, light status (/^[gGB]$/)

Example 1

import './App.css';
import React from 'react'
import TrafficSignal from 'react-trafficsignal'

function App() {
  return (
    <div className="App">
      <div style={{ width: "35px" }}>
        <TrafficSignal
          status="RaG"
        />
      </div>
    </div>
  );
}

export default App;

Example 2 - Horizontal

import './App.css';
import React from 'react'
import TrafficSignal from 'react-trafficsignal'

function App() {
  return (
    <div className="App">
      <div>
        <TrafficSignal
          status="BBg" 
          options={{ horizontal: true, clockwise: false, width: '75px' }}
        />
      </div>
      <div>
        <TrafficSignal 
          status="rAB" 
          options={{ horizontal: true, clockwise: true, width: '75px' }} 
        />
      </div>
    </div>
  );
}

export default App;

Example 3 - width and margin

import './App.css';
import React from 'react'
import TrafficSignal from 'react-trafficsignal'

function App() {
  return (
    <div className="App">
      <div>
        <TrafficSignal 
          status="BBG" 
          options={{ width: '35px', margin: '1em' }} 
        />
        <TrafficSignal 
          status="BAB" 
          options={{ width: '70px', margin: '1em' }} 
        />
        <TrafficSignal 
          status="RBB" 
          options={{ width: '105px', margin: '1em' }} 
        />
      </div>
    </div>
  );
}

export default App;

Example 4 - 1, 2 and 3 aspects

import './App.css';
import React from 'react'
import TrafficSignal from 'react-trafficsignal'

function App() {
  return (
    <div className="App">
      <div>
        <TrafficSignal 
          status="BBg" 
          options={{ width: '35px', margin: '1em', hideRed: true, hideAmber: true }} 
        />
        <TrafficSignal 
          status="RAG"
          options={{ width: '35px', margin: '1em', hideAmber: true }} 
        />
        <TrafficSignal 
          status="BaB" 
          options={{ width: '35px', margin: '1em', hideRed: true }} 
        />
        <TrafficSignal 
          status="BaG" 
          options={{ width: '35px', margin: '1em', hideRed: true, hideGreen: true }} 
        />
      </div>
    </div>
  );
}

export default App;

Example 5 - onClick

import './App.css';
import React from 'react'
import TrafficSignal from 'react-trafficsignal'

function App() {
  
  const onLightClick = (e, status) => {
    const colors = {
      B: 'Black/OFF',
      R: 'Red',
      r: 'flashing Red',
      G: 'Green',
      g: 'flashing Green',
      A: 'Amber',
      a: 'flashing amber'
    };
    alert(`I am ${colors[status]}`)
  }
  
  return (
    <div className="App">
      <div style={{ width: "35px" }}>
        <TrafficSignal
          status="RaG"
          onRedClick={onLightClick}
          onAmberClick={onLightClick}
          onGreenClick={onLightClick}
        />
      </div>
    </div>
  );
}

export default App;