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

@raghavendradabbir/mycolorpicker

v1.0.0

Published

Scaleable color picker

Downloads

705

Readme

mycolorpicker - The Scaleable Color Picker

mycolorpicker was somewhat inspired by ColorJack and RightJS Colorpicker. Unlike those it actually scales pretty well. Essentially this means that you'll be able to define its actual dimensions and layout using a bit of CSS. This way the widget fits well responsive layouts.

In addition it's relatively easy to implement missing functionality (RGB fields, whatnot) thanks to the simple API it provides.

Installation

npm i mycolorpicker

If you prefer a standalone dist, add prepackaged dist/mycolorpicker.js and css/mycolorpicker.css to your page or use AMD to load the dependencies from src/.

Usage

const joe = mycolorpicker.rgb(element_id_or_dom_object, initial_color_value, extras);

or

const joe = mycolorpicker.hsl(element_id_or_dom_object, initial_color_value, extras);

Event Handling

The returned joe object is an event emitter style object with change and done events. The change event is fired continuously when selecting and done is fired when user has stopped selecting.

joe.on("change", color => console.log("Selecting " + color.css()));
joe.on("done", color => console.log("Selected " + color.css()));

The color object is from one.color.

Given it might be nice to trigger these events immediately, there is a specific update method. Ie. joe.on("change", function() {...}).update() would trigger change immediately. This is handy for initializing your work.

Get and Set

In addition there are set and get methods. Ie. joe.get() would return the current color while joe.set('#aabbcc') would set it. set expects a parameter that one.color default constructor would accept.

Extras

In order to make it easier to customize a picker based on your needs, mycolorpicker provides a few extras. The following example shows how to use them:

const joe = mycolorpicker.hsl('hslPicker', 'red', [
    'currentColor',
    'alpha',
    ['fields', {space: 'HSL', limit: 255, fix: 0},
    'hex'
]);

The code above would generate a HSL picker that shows in addition the currently selected color, alpha slider, HSL input fields and a hex field.

As you can see fields has been defined using an array. This array contains the name of the extra and then parameters passed to inside an object. In this case the extra accepts name of a color space (RGB, HSL, HSV or CMYK). If you append A to the color space, it will show a control for alpha too. In addition it takes a limit value (defaults to 255) and a fix value (defaults to 0). fix represents the amount of numbers shown after decimal.

hex extra accepts optional label. If set it will show that as the input's label.

Implementing Custom Extras

It is possible to implement your custom extras without having to hack the core code. This can be done as follows:

mycolorpicker.registerExtra('text', (p, joe, o) => {
    // attach new elements to p element here (as children that is)
    // o is optional and will contain any parameters you might have
    // passed to the extra using the array syntax

    // optional return. these are triggered by mycolorpicker
    // use this way instead of joe.on
    return {
        change(col) {},
        done(col) {}
    };
})

Now you can simply pass your text extra amongst the others and it will just work.

Sites Using mycolorpicker

PRs are welcome!

Contributors

Hacking

  1. npm i
  2. npm start
  3. serve (or similar command) at project root

License

mycolorpicker is available under MIT. See LICENSE for more details.