Tool Cool Color Picker is a color picker library written in typescript and using web component technologies.

Overview

Tool Cool Color Picker

GitHub license GitHub package.json version NPM Twitter

Tool Cool Color Picker is a color picker library written in typescript and using web component technologies. Check out the demo at https://toolcool.org/toolcool-color-picker/

Tool Cool Color Picker

Basic usage in a browser

Download the latest toolcool-color-picker.min.js script:

Add the following html to the page:

<toolcool-color-picker color="#e76ff1"></toolcool-color-picker>

<script type="text/javascript" src="toolcool-color-picker.min.js"></script>

Or with other color formats:

<toolcool-color-picker color="rgb(96, 245, 66)"></toolcool-color-picker>
<toolcool-color-picker color="rgba(96, 245, 66, 1)"></toolcool-color-picker>
<toolcool-color-picker color="hsv(110, 73%, 96%)"></toolcool-color-picker>
<toolcool-color-picker color="hsva(110, 73%, 96%, 1)"></toolcool-color-picker>
<toolcool-color-picker color="hsl(110, 90%, 61%)"></toolcool-color-picker>
<toolcool-color-picker color="hsla(110, 90%, 61%, 1)"></toolcool-color-picker>

<script type="text/javascript" src="toolcool-color-picker.min.js"></script>

Color picker popup can be aligned to the right:

<toolcool-color-picker color="rgb(255, 200, 10)" popup-position="right"></toolcool-color-picker>

CDN

The ToolCool Color Picker is also available in the jsDelivr CND:

<toolcool-color-picker color="#e76ff1"></toolcool-color-picker>

<script src="https://cdn.jsdelivr.net/npm/toolcool-color-picker/dist/toolcool-color-picker.min.js"></script>

Node.js usage

Color picker may also be included as a node module like this:

npm i toolcool-color-picker

And then you can include it in your application like this:

import 'toolcool-color-picker';

NPM package can fe found here.

APIs

You can control the color picker by referencing the toolcool-color-picker HTML tag.

<toolcool-color-picker color="#e76ff1" id="color-picker-1"></toolcool-color-picker>

<script type='text/javascript' src='toolcool-color-picker.min.js'></script>
<script>
    // get the reference
    const $colorPicker = document.getElementById('color-picker-1');
    
    // change color
    $colorPicker.color = '#60f542';
    
    // get color
    console.log($colorPicker.rgba);
</script>

APIs: Listen to the change event

// listen to the color change event
const $colorPicker = document.getElementById('color-picker');

// @param {evt} CustomEvent
$colorPicker.addEventListener('change', (evt) => {
    
    console.log(evt.detail.hex);
    console.log(evt.detail.hex8);
    console.log(evt.detail.rgb);
    console.log(evt.detail.rgba);
    console.log(evt.detail.hsl);
    console.log(evt.detail.hsla);
    console.log(evt.detail.hsv);
    console.log(evt.detail.hsva);
    console.log(evt.detail.color);
});

APIs: Change Color

The color picker uses the awesome TinyColor library for color manipulation. Each color format supported by the TinyColor library can be passed in a color property:

const $colorPicker = document.getElementById('color-picker');

// HEX format
$colorPicker.color = '#60f542';

// OR HEX with opacity
$colorPicker.color = '#60f542ff';

// OR rgb
$colorPicker.color = 'rgb(96, 245, 66)';

// OR rgb with opacity
$colorPicker.color = 'rgba(96, 245, 66, 1)';

// OR hsv
$colorPicker.color = 'hsv(110, 73%, 96%)';

// OR hsv with opacity
$colorPicker.color = 'hsva(110, 73%, 96%, 1)';

// OR hsl
$colorPicker.color = 'hsl(110, 90%, 61%)';

// OR hsl with opacity
$colorPicker.color = 'hsla(110, 90%, 61%, 1)';

APIs: Get current color in different formats

const $colorPicker = document.getElementById('color-picker');
$colorPicker.color = '#367E95';

console.log($colorPicker.hex); // #367E95

console.log($colorPicker.hex8); // #367E95FF

console.log($colorPicker.rgb); // rgb(54, 126, 149)

console.log($colorPicker.rgba); // rgba(54, 126, 149, 1)

console.log($colorPicker.hsl); // hsl(195, 47%, 40%)

console.log($colorPicker.hsla); // hsla(195, 47%, 40%, 1)

console.log($colorPicker.hsv); // hsv(195, 64%, 58%)

console.log($colorPicker.hsva); // hsva(195, 64%, 58%, 1)

You can also access the color object of the TinyColor library. It should only be used to get color values and should not be modified directly.

console.log($colorPicker.color); 

APIs: Popup

Open or close color picker popup with the following API:

<toolcool-color-picker color="#e76ff1" id="color-picker"></toolcool-color-picker>
<script src="js/toolcool-color-picker.min.js"></script>

<script>
    const $colorPicker = document.getElementById('color-picker');

    // open color picker popup
    $colorPicker.opened = true;

    // close color picker popup
    $colorPicker.opened = false;
</script>

Styles

It's possible to control color picker styles through CSS variables:

:root{
    /* button */
    --tool-cool-color-picker-btn-bg: #b9b9b9;
    --tool-cool-color-picker-btn-border-color: #000;
    --tool-cool-color-picker-btn-border-color-inner: #363636;
    --tool-cool-color-picker-btn-border-radius: 1rem;
    --tool-cool-color-picker-btn-border-radius-inner: 1rem;

    /* popup */
    --tool-cool-color-picker-popup-bg: #b9b9b9;
    --tool-cool-color-picker-popup-border-color: #000;

    /* fields */
    --tool-cool-color-picker-field-border-color: #363636;
    --tool-cool-color-picker-field-label-color: #1a3c6e;
}

It's also possible to use CSS variables as inline styles in the following way:

<toolcool-color-picker 
        color="rgb(255, 200, 10)" 
        style="--tool-cool-color-picker-btn-bg: #fff"></toolcool-color-picker>

TypeScript Usage

import 'toolcool-color-picker';
import ColorPicker from 'toolcool-color-picker/src/app/color-picker';

// ...

const $colorPicker = document.getElementById('get-color-picker') as ColorPicker;

$colorPicker.addEventListener('change', (evt: Event) => {
    const customEvent = evt as CustomEvent;
    console.log(customEvent.detail.rgba);
});

$colorPicker.hex = '#fefefe';

Credits

An awesome TinyColor Library

License

MIT license

You might also like...

A CRUD implementation using sequelize, mySQL, NODEJS, Express, JWT and other technologies.

A CRUD implementation using sequelize, mySQL, NODEJS, Express, JWT and other technologies.

A ideia do projeto é simular o funcionamento do backend de um blog através da implementação de uma aplicação em Node.js usando o pacote sequelize para

May 11, 2022

A pretty cool org-mode - interactive blog post tool

Radish A kinda-cool org-mode - interactive blog post tool written with and for Clojure(script). Here are two example posts created with this tool: Ra

Dec 28, 2021

A cool tool that saves you time if you want to remove node_modules before running 'npm i'

rmnpm A cool tool that saves you time if you want to remove your node_modules folder before running the npm install command. How does it do it? By fir

Jul 16, 2022

Tool Cool Range Slider

Tool Cool Range Slider

Responsive range slider library written in typescript and using web component technologies. Pure JavaScript without additional dependencies. It has a rich set of settings, including a vertical slider, touch, mousewheel and keyboard support, local and session storage, and RTL support.

Dec 31, 2022

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Sep 13, 2022

A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js, that is based on Dan Grossman's bootstrap-daterangepicker.

A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js, that is based on Dan Grossman's bootstrap-daterangepicker.

vanilla-datetimerange-picker Overview. A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js,

Dec 6, 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

Oct 25, 2022

A little toy app to help you find the nearest match for a given color within a Figma Tokens color palette.

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

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

Oct 1, 2022
Owner
Tool Cool
The ToolCool project is a collection of useful online web tools. Each tool has a rich set of features and can speed up the creation and development of websites
Tool Cool
A simple color picker application written in pure JavaScript, for modern browsers.

Color Picker A simple color picker application written in pure JavaScript, for modern browsers. Has support for touch events. Touchy… touchy… Demo and

Taufik Nurrohman 207 Dec 14, 2022
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
Another full-stack URL Shortener application built using web technologies

URL Shortener Another full-stack URL Shortener application built using web technologies. Technologies Node Express MongoDB React TypeScript Docker Pro

Soroush Chehresa 9 Dec 15, 2022
JavaScript/TypeScript library to run repetitive tasks with throttle control and other cool features

Repeatify JavaScript/TypeScript library to run repetitive tasks with throttle control and other cool features Install npm install repeatify Usage impo

Evert Arias 2 Jan 15, 2022
Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and easy to use it

Digispark_Overmaster Digispark Overmaster : free IDE TOOL allows to create and edit Digispark Scripts by the drag and drop technique,with cool GUI and

Yehia Elborma 5 Nov 14, 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
Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

实时计算(English Version) 运用实时计算技术、Web 技术构建一个大数据看板来解决问题。其中实用技术包括Mysql、Kafka、Flink、Redis、Flask和Echarts 目录 1.问题需求 2.方案分析 3.安装环境 4.环境启动命令和运行代码的方法 5.代码目录结构说明

Serendipity 2 Jan 8, 2022
This Project is made with HTML5, CSS3, ReactJS, Axios, MetaMask, thirdweb, Rinkeby Test Network, Web 3.0 Technologies, and OpenSea API.

Abstract Collections This Project is made with HTML5, CSS3, ReactJS, Axios, MetaMask, thirdweb, Rinkeby Test Network, Web 3.0 Technologies, and OpenSe

Shobhit Gupta 34 Jan 4, 2023
A blazingly fast CDN, at par and up-to-date with modern web technologies

A blazingly fast CDN, at par and up-to-date with modern web technologies

Compey 6 Sep 22, 2022