A simple color picker application written in pure JavaScript, for modern browsers.

Overview

Color Picker

Code Size License

A simple color picker application written in pure JavaScript, for modern browsers.

Has support for touch events. Touchy… touchy…

Color Picker

Demo and Documentation

Contribute

  • Please do not make pull requests by editing the files that are in the root of the project. They are generated automatically by the build tool.
  • Install Git and Node.js
  • Run git clone https://github.com/taufik-nurrohman/color-picker.git
  • Run cd color-picker && npm install --save-dev
  • Edit the files in the .github/factory folder.
  • Run npm run pack to generate the production ready files.

Contributors

Code Contributors

This project exists thanks to all the people who contribute.

Contributors

Financial Contributors

Become a financial contributor and help us sustain our community.

Individuals

Contribute

Organizations

Support this project with your organization. Your logo will show up here with a link to your website.

Comments
  • Text input inside picker combined with multiple instances

    Text input inside picker combined with multiple instances

    Do you have a demo of the text input inside the color picker combined with multiple instances?

    https://taufik-nurrohman.js.org/color-picker/color-picker.picker.html https://taufik-nurrohman.js.org/color-picker/color-picker.picker-view-code.html

    I've tried to get it working but changing the value in the text input doesn't get the correct instance of the picker.

    I created a demo here but you might need to run it in debug mode to get it to work.

    https://codepen.io/asa-carter/pen/YzWLZOb

    opened by asacarter 9
  • Color picker doesn't use correct cursor position when placed inside popover

    Color picker doesn't use correct cursor position when placed inside popover

    I'm trying to use the color picker inside a Bootstrap popover, but when I do this, the color picker doesn't use the correct cursor position when selecting a color. It behaves as if the color picker and the cursor were in the upper left of the screen. You can see this behavior by clicking on any of the color swatches on this page. Is there any way I can get the color picker to use the correct cursor position?

    bug question 
    opened by DePasqualeOrg 9
  • Initialize instance with predefined color

    Initialize instance with predefined color

    Hi

    How can I initialize the color picker instance with the one set in target element https://jsfiddle.net/Greggg/916wwx1h/

    Any help would be appreciated

    help wanted 
    opened by gregBerthelot 8
  • Can we use

    Can we use "hs + b" controls rather than "sb + h"?

    Thanks for a great tool! It's the very best approach - to keep it simple to use and to extend.

    My only inconvenience is that it uses rectangle of saturation * brightness, plus a slider of hue.

    That approach is good to fine-tune colors of a given hue, but it's not the best way to quickly select different colors.

    Maybe that's OK for heavy duty things like Photoshop, but for simple web applications it seems to me it would be more convenient to have a large rectangle of hue * saturation, and a stripe slider of brightness.

    Then it's like choosing a color on a large palette, and then maybe adjusting brightness.

    I tried both approaches in different color pickers and I'm pretty sure.

    My JS skills are rudimentary, so I'd like to ask you, respected professionals: is it possible to make a control "hue on X, saturation on Y" + brightness?

    Thank you again ;).

    PS. I often want to choose several colors of the same brightness, rather than of the same hue; so fro me it is brightness that should go into a separate slider.

    question 
    opened by chang-zhao 8
  • Version 1.4.1 broke update callback

    Version 1.4.1 broke update callback

    Hello,

    I tried updating your library from 1.4.0 to 1.4.1 and noticed the picker is no longer passed into events which causes issues if multiple pickers are used in the same page. We use it like this (sorry for CoffeeScript):

    class Abc
      constructor: ->
        for input in @inputs
          $input = $(input)
          picker = new CP(input)
          $input.data('picker', picker)
          picker.on('change', this._handlePickerChange)
    
      _handlePickerChange: (color, picker) => # <-- picker is undefined in 1.4.1
        color  = "##{color}"
        $input = $(picker.source)
        # ... do other stuff
    

    Is this fixable or should we do things differently?

    Thank you, Ollie

    opened by ollie 7
  • Why does picker.on(

    Why does picker.on("change", ...) fire on page load?

    Anyone know why picker.on("change", function(color) {...}); fires on page load?

    Ideally I would like to only have it fire if the color picker is interacted with but for some reason it fires even if I never use the color picker.

    Basic example:

    <script>
    
        var source = document.querySelector('input'),
            picker = new CP(source);
    
        // prevent showing native color picker panel
        source.onclick = function(e) {
            e.preventDefault();
        };
    
        picker.on("change", function(color) {
            alert('fire');
            this.source.value = '#' + color;
        });
    
    </script>
    
    opened by jjrabbit 6
  • Calling enter() doesn't fire enter hook.

    Calling enter() doesn't fire enter hook.

    Because of my issues with visibility not updating, I'm having to manually manage my own visibility flag using the enter and exit hooks. This works pretty good except if I open the color picker manually with another button using:

    CP.__instance__.someColorPicker.enter()
    

    The enter hook doesn't get fired. This would be expected behavior no? As then I could put all my flag management code in one place - the enter and exit hooks versus having to add code wherever I call enter().

    Strangely, calling the above with exit() does indeed fire the exit hook.

    This can be reproduced easily by putting a console.log in the picker.on('enter') {}, create a new color picker instance, then in Chrome's console call CP.__instance__.someColorPicker.enter(). It won't fire the enter hook. However, it will fire if you manually click the color picker to enter it.

    bug 
    opened by evolross 6
  • Disabling Auto-Fit?

    Disabling Auto-Fit?

    Is there any way to disable the way the color-picker "auto fits" to the visible screen area?

    This is happening in my app and the color picker gets moved to an area that covers up my UI and leaves the user unable to click the necessary buttons to choose a color or close the color picker.

    Could I add a PR to pass this as a setting parameter when initiating? Or would this be something easy you could do?

    EDIT: I see there's a fit hook that gets called when the color picker gets auto fitted, but there doesn't seem to be any easy way to "undo" or cancel the auto fit using that hook.

    opened by evolross 6
  • Issue with Emitter

    Issue with Emitter

    When I install color-picker with npm, the following error occurs when I try to import the package:

    Module build failed: Error: ENOENT: no such file or directory, open '.../node_modules/emitter/dist/emit
    

    When I install the package with npm install --save emitter, the error seems to disappear in the terminal but a new one occurs in Chrome:

    Uncaught (in promise) TypeError: Emitter is not a function
    

    If you inspect the file index.js in node_modules, this seems to come from:

    /**
     * Mixin Emitter.
     */
    
    Emitter(ColorPicker.prototype);
    

    For the first issue, I suggest you add this package as a module dependency in package.json. For the second one, I don't have any answer.

    opened by LeCoupa 6
  • Added package.json and UMD loader wrapper

    Added package.json and UMD loader wrapper

    Hi Taufik, I found your color-picker widget a few weeks ago and decided to use it for a few projects that I have. I neede da basic color picker and love that yours (in comparison ot many others outthere) is light in size, dependency free and not bloated with too many extra feature. What I found to be missing (for me :) ) is a package.json, which allows folks to use package managers (ex. npm) and (most important), that it provides support for use with module patterns, so that the glboal window space is not automtically poluted with the CP namespace...

    With this contribution, I am providing:

    • A package.json file
    • Changes to color-picker.js to wrap the library in an UMD declaration.

    This will enable your library to be used with packge manager, as well as modern module loaders (ex. ES2015 import or AMD or CommonJS.

    Thanks for your work on this and for sharing it on GitHub.

    /Paul

    opened by purtuga 6
  • Change Hook Running On Init

    Change Hook Running On Init

    Hi guys, I have a weird issue the change hook is running on plugin initializing, here is the test i did:

    // Initialization
    let picker = new CP(element);
    
    // change hook listener
    picker.on('change', function(r, g, b, a) {
        // firing immediately 
        console.log(1);
    });
    
    opened by mgabi4488 5
  • React 17 Cannot read properties of null

    React 17 Cannot read properties of null

    In react error click <input name="thename" type="text" value="#0f0" onclick={(new CP(document.querySelector(input[name="thename"]))) error Cannot read properties of null (reading 'append')

    opened by immakdas 1
  • How dynamically trigger move of selected point in color-picker:sv element - n points up, left, down or right?

    How dynamically trigger move of selected point in color-picker:sv element - n points up, left, down or right?

    I would like to make it possible, in custom javascript, to move the selected round point in color-picker:sv element - using e.g. the up, down, left and right arrows (and/or using the I, M, J and L keys) on the keyboard. And I would like to make it so the selected point moves n points in a given direction on each press of the arrow - where the value of n is in relation to how many points there are in total horisontally (and vertically).

    How do i get number of points in the color-picker:sv element - horisontally and vertically? How do I move the selected point n points up, right, left or down - and trigger the same events that are triggered when I left click to select a color?

    enhancement 
    opened by bongobongo 36
  • Picker not working with numeric only hex values?

    Picker not working with numeric only hex values?

    Hi, it seems that if I have a data-color="#276895" , numeric only hex number, it does not work, and returns black as fallback. Also, is it ok for the "change" event to fire after init? Thanks.


    Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

    opened by tehmaestro 1
  • Fix picker position/cursor when page has non-fixed position.

    Fix picker position/cursor when page has non-fixed position.

    This is a solution for #29. The easiest way was to force the placement of the picker to be placed at root child, and adjust origins from there, losing the custom container/bucket feature.

    opened by flamestream 2
  • Set the crosshair cursor for the hue slider

    Set the crosshair cursor for the hue slider

    Cursor: crosshair allows precise selecting of the color more easily than "ns-resize". Semantically it is also correct: rather than "regulating hue" we usually try to select the point of the necessary color.

    help wanted 
    opened by chang-zhao 2
Releases(v2.4.4)
Owner
Taufik Nurrohman
I have a dream, but it won’t make me rich.
Taufik Nurrohman
Colr Pickr, a vanilla JavaScript color picker component built with SVGs, with features like saving colors. Similar design to the chrome-dev-tools color picker.

Colr Pickr Colr Pickr, a vanilla JavaScript color picking component built with SVGs, with features like saving colors. Similar design to the chrome-de

TEK 27 Jun 27, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill).

@sanity/client Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a Promise polyfill). Requirements Sanity Clien

Sanity 23 Nov 29, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Flat and simple color-picker library. No dependencies, no jquery.

Flat and simple color-picker Fully Featured demo Features Simple: The interface is straight forward and easy to use. Practical: Multiple color represe

Ivan Matveev 15 Nov 14, 2022
🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library.

?? Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!

Simon 3.9k Dec 27, 2022
Snowfall effect written in pure JavaScript. No additional libraries, no dependencies. Works in every modern browser.

pureSnow.js Snow falling slowly on a winter night. Probably the most calming and peaceful snowfall effect written in pure JS/CSS. (No SCSS). Inspired

null 20 Dec 29, 2022
Bootstrap Colorpicker is a modular color picker plugin for Bootstrap.

Bootstrap Colorpicker Bootstrap Colorpicker is a modular color picker plugin for Bootstrap 4. THIS PROJECT IS NOT MAINTAINED ANYMORE. After almost 10

Javi Aguilar 1.4k Dec 22, 2022
Change the color of an image to a specific color you have in mind.

image-recolor Run it: https://image-recolor.vercel.app/ image.recolor.mov Acknowledgments Daniel Büchele for the algorithm: https://twitter.com/daniel

Christopher Chedeau 21 Oct 25, 2022
A little toy app to help you find the nearest match for a given color within a Figma Tokens color palette.

Hey Palette So you've got a color palette in Figma and you've used the Figma Tokens plugin to export that palette to JSON. Let's say you have a color

Kalo Pilato 5 Nov 15, 2022
A NodeJS package to convert any RGB color to HEX color or viceversa. Also supports HSL conversion.

Unhex ?? A NodeJS package to convert any RGB color to HEX, HSL color or viceversa. Example div { color: #fff; background-color: #0070f3; } After r

Arnau Espin 2 Oct 1, 2022
Kuldeep 2 Jun 21, 2022
This package generates a unique ID/String for different browsers. Like chrome, Firefox and any other browsers which supports canvas and audio Fingerprinting.

Broprint.js The world's easiest, smallest and powerful visitor identifier for browsers. This package generates a unique ID/String for different browse

Rajesh Royal 68 Dec 25, 2022
📆 The modern, open source "Airbnb style" date picker.

Date Picker A pretty, modern date picker. Coming soon. ?? Get Started wip wip ?? Testing pnpm test ?? Changelog Please see our releases page for more

Open Web Foundation 8 Oct 11, 2022
Zepto.js is a minimalist JavaScript library for modern browsers, with a jQuery-compatible API

Zepto.js – a minimalist JavaScript library Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. If you u

Thomas Fuchs 15k Dec 31, 2022
Responsive tabs-to-accordion script without jQuery, written using pure JavaScript

vanilla-tabs Responsive tabs-to-accordion script without jQuery, written using pure JavaScript Author Dmytro Kudleichuk LinkedIn GitHub Online Demo Se

Dmitriy Kudleichuk 7 Dec 20, 2022
DateTimePickerComponent is a very lightweight and dependency-free web component written in pure JavaScript

DateTimePickerComponent Description DateTimePickerComponent is a very lightweight (just over 20KB) and dependency-free web component written in pure J

null 14 Dec 24, 2022
Simple date and time picker in vanilla javascript

simplepicker Simple datetime picker in vanilla javascript. This project is mostly based on material-datetime-picker, but without it relying on externa

Priyank Patel 51 Jul 18, 2022