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

js-color-gradient

v1.1.7

Published

This project hepls to get color gradient code based on value.

Downloads

7

Readme

js-color-gradient

js-color-gradient helps you get gradient colors for your web application.Like in table , list etc.It gives result in an array of colors. It allows you to configure options like color, fromColor, toColor, style. Currently it takes gradient steps based on the range provided.Like for range '0-20' gradient steps will be 20.

To build the examples locally with npm, run:

npm install npm start

Then localhost:3000 should open in a browser. If not you can go to that directly.

Installation

To use js-color-gardient, install it from NPM with npm using the command:

npm install --save js-color-gradient

To use js-color-gradient, install it from yarn using the command:

yarn add js-color-gradient

Demo link

Usage

To use this component, first import js-color-gradient:

import {getColors} from 'js-color-gradient'; and then provide it the options.

ReactJS Example (Assuming Node and ReactJS app is already setup) :

  let options = [{
    style: 'gradient',
    range: '0-20',
    fromColor: '#8B0000',
    toColor: '#FFCCCB'
},
{
    style: 'gradient',
    range: '21-40',
    fromColor: '#8B8000',
    toColor: '#FFFFE0'
},
{
    style: 'gradient',
    range: '41-100',
    fromColor: '#0000ff',
    toColor: '#ADD8E6'
}];
let data = [{
        item: 'item1',
        count: 1,
        percentage: 1
    },
    {
        item: 'item2',
        count: 2,
        percentage: 2 
    },
    {
        item: 'item3',
        count: 3,
        percentage: 3
    },
    {
        item: 'item4',
        count: 4,
        percentage: 4
    },
    {
        item: 'item5',
        count: 5,
        percentage: 5
    },
    {
        item: 'item6',
        count: 6,
        percentage: 6
    },
    {
        item: 'item7',
        count: 7,
        percentage: 7
    },
    {
        item: 'item8',
        count: 8,
        percentage: 8
    },
    {
        item: 'item9',
        count: 9,
        percentage: 9
    },
    {
        item: 'item10',
        count: 10,
        percentage: 10
    }];
let gradientColorForTable = getColors(options);
let tableData = data;
  return (
    <div>
            <table>
                <thead>
                    <tr>
                        <td><h4>Item</h4></td>
                        <td><h4>Count</h4></td>
                        <td><h4>Percentage</h4></td>
                    </tr>
                </thead>
                <tbody>
                    {tableData.map((data, i) => (
                        <tr key={i+1}>
                            <td>
                                {data.item}
                            </td>
                            <td>
                                {data.count}
                            </td>
                            <td style={{ backgroundColor: gradientColorForTable[data.percentage]}}>
                                {data.percentage}
                            </td>
                        </tr>
                    ))}
                </tbody>
            </table>
        </div>
  );
}

export default App;

Options:

  • style: 'gradient'->If you want gradient for the given range, 'constant'->If you don't want gradient for the given range.
  • range: range of the values .Ex '0-20','20-100' etc.
  • color: if style is 'constant' the provide color.
  • fromColor: if style is 'gradient' provide fromColor
  • toColor: if style is 'gradient' provide toColor

Example for options:

If style is 'gradient':

{
    style: 'gradient',
    range: '0-20',
    fromColor: '#8B0000',
    toColor: '#FFCCCB'
}

If style is 'constant':

{
    style: 'constant',
    range: '0-20',
    color: '#8B0000'
}

You can provide as many range as you want and style also can be given same or different as per the requirement.

You can take a look at the example given in example folder. To run the React Example use npm i then npm start

Contributing

Fork this repo, add your proposed features and make a pull request. I will review as soon as possible.

License

This project is licensed under the terms of the MIT license. Check LICENSE.txt for more information.

Keywords

Javascript color gradient