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

@andre2xu/js-color-picker

v1.1.0

Published

A simple and lightweight color picker for JavaScript projects.

Downloads

18

Readme

JS Color Picker  JavaScript TypeScript

GitHub  npm (scoped) A simple and lightweight color picker for JavaScript projects. Feel free to use it for commercial and non-commercial purposes.

View demo

STARTED: 1 June 2023 FINISHED: 13 June 2023

Installation

npm install @andre2xu/js-color-picker

Usage

The following code block shows how to use it with React:

import React from 'react';
import JSColorPicker from "@andre2xu/js-color-picker";
import "../node_modules/@andre2xu/js-color-picker/index.css";

// CLASS COMPONENT
class App extends React.Component {
  componentDidMount() {
    // creates color picker after the component has rendered
    new JSColorPicker('my-element');
  }

  render() {
    return (
      <div className="App">
        <div id="my-element"></div>
      </div>
    );
  }
}

// FUNCTIONAL COMPONENT
function App() {
  React.useEffect(() => {
    // creates color picker after the component has rendered
    new JSColorPicker('my-element');
  }, []);

  return (
    <div className="App">
      <div id="my-element"></div>
    </div>
  );
};

export default App;

The following code block shows how to use the API:

const COLOR_PICKER = new JSColorPicker('my-element');

COLOR_PICKER.setSize(300, 250); // width: 300px, height: 250px

COLOR_PICKER.setScale(2); // width: (300*2)px, height: (250*2)px

// control visibility
COLOR_PICKER.hide();

COLOR_PICKER.show();

// detect & respond to changes in the color
COLOR_PICKER.addOnChangeListener(function (event) {
  console.log(event.color); // example: {r: 255, g: 0, b: 0, a: 0.5}
});

const RGBA = COLOR_PICKER.getColor(); // returns an object containing RGBA data

const CP_ELEMENT = COLOR_PICKER.getColorPicker(); // returns the color picker's element (use this if you want to add your own CSS or overwrite the existing ones)

IMPORTANT

  • The color picker can work on its own, it does not need React

  • Make sure that the container element for the color picker has rendered on the DOM, otherwise you would get an error saying that there's no element with the id you specified in the constructor

  • Be sure to import/include the stylesheet because not only is it required to render the color picker but it's also used to compute the dimensions of the canvases

CHANGELOG

[1.1.0] - 2024-03-27

Added

  • Added an API method for binding a listener to the color picker that detects & reacts to changes in the color
  • The API code block in this README now includes all API methods

[1.0.5] - 2024-01-06

Fixed

  • Fixed the condition that was supposed to prevent NaN values for the HSLA and HSVA angles; it now properly checks for NaN

[1.0.1] - 2024-01-04 (deleted)

Fixed

  • Added a condition that prevents NaN values for the HSLA and HSVA angles

License

Distributed under the MIT License. See LICENSE for more information.