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

web-traffic-light

v1.0.2

Published

A Javascript Web Component for displaying status in the form of a traffic light on web applications.

Downloads

2

Readme

Traffic-Light

A Javascript Web Component for displaying status in the form of a traffic light on web applications.

build npm version Built With Stencil

Screenshots

Online demo

Click here for the demo (On CodePen.io)

Installing

Via CDN (JSDelivr)

Add the following HTML preferrably between the opening and closing head tags of your page:

<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/traffic-light/traffic-light.esm.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/[email protected]/dist/traffic-light/traffic-light.js"></script>

Alternatively, you can import Traffic-Light's module and register its defined elements by adding the follow Javascript to your page:

<script type="module">
  import { defineCustomElements } from 'https://cdn.jsdelivr.net/npm/[email protected]/loader/index.es2017.js';
  defineCustomElements();
</script>

Traffic-Light is built with StencilJS. You can refer to this page in their documentation where you will find additional information on how to add this component to React, Angular, Vue and Ember applications.

Via NPM

npm install web-traffic-light

Usage

After installing Traffic-Light in your page and registering its elements, it can be used just like any standard HTML component like <button/> and <input/>. In its most basic form, the component HTML tag looks like this:

<traffic-light style="width: 70px;"></traffic-light>

You need to constraint the width (with a css class or an inline style as in the example above) so that the component can be displayed correctly.

By default, the component will show without any light turned on. You can control the lights and some other aspects of the component by adding additional attributes to the component tag or by manipulating the components directly via Javascript.

Modes

Traffic-Light can be displayed in two modes:

  • three-lights - It's the default mode. In this mode the component will look like your regular street traffic light.
  • single-light - As the name implies, in this mode only a single light is displayed at a time.

You can set the mode by using the mode attribute/property:

<!-- Renders Traffic-Light in three lights mode -->
<!-- You can also omit the attribute since it's the default anyway -->
<traffic-light  mode="three-lights"  style="width: 70px;"></traffic-light>

<!-- Renders Traffic-Light in single light mode -->
<traffic-light  mode="single-light"  style="width: 70px;"></traffic-light>

State

Through the attribute/property current-state you can control whether the lights are on or off. The behavior also change slightly according to the value of the color attribute/property. Here are the possible values and the expected behaviors:

  • off - The lights will be turned off for both modes.
  • on - The light specified in the color attribute/property will be turned on. If no color is specified, the light(s) will be turned off.
  • all-on
    • In three-lights mode all lights will be turned on and the color attribute/property will be ignored.
    • In single-light mode this state works exactly like on.

Some examples below:

<traffic-light current-state="off"></traffic-light>
<traffic-light current-state="on" color="red"></traffic-light>
<traffic-light current-state="all-on"></traffic-light>

Color

Use this attribute/property to specify which color should be turned on. It supports three values:

  • red
  • yellow
  • green

Examples:

<traffic-light current-state="on" color="red"></traffic-light>
<traffic-light current-state="on" mode="single-light" color="yellow"></traffic-light>
<traffic-light current-state="all-on" mode="three-lights" color="green"></traffic-light>

Building

To build this component you need to clone the repository:

git clone https://github.com/rodrigolira/traffic-light.git traffic-light
cd traffic-light
git remote rm origin

Then you need to install all dependencies by running:

npm install

To start the development server:

npm start

And to build:

npm run build

Or to run the tests:

npm test