Powerful Color Picker is a tiny color picker component for React and Preact apps

Last update: Jun 16, 2022

Powerful Color Picker

Powerful Color Picker is a tiny color picker component for React and Preact apps.

Features

  • πŸ—œ Small: Just 2,8 KB gzipped (13x lighter than react-color).
  • 🌳 Tree-shakeable: Only the parts you use will be imported into your app's bundle.
  • πŸš€ Fast: Built with hooks and functional components only.
  • πŸ›‘ Bulletproof: Written in strict TypeScript and has 100% test coverage.
  • πŸ—‚ Typed: Ships with types included
  • 😍 Simple: The interface is straightforward and easy to use.
  • πŸ‘« Cross-browser: Works out-of-the-box for most browsers, regardless of version.
  • πŸ“² Mobile-friendly: Supports mobile devices and touch screens.
  • πŸ’¬ Accessible: Follows the WAI-ARIA guidelines to support users of assistive technologies.
  • πŸ’¨ No dependencies

Live demos

Table of Contents

Getting Started

Install via npm:

npm install powerful-color-picker

Using

{ const [color, setColor] = useState("#aabbcc"); return ; };">
import { HexColorPicker } from "powerful-color-picker";

const YourComponent = () => {
  const [color, setColor] = useState("#aabbcc");
  return <HexColorPicker color={color} onChange={setColor} />;
};

Supported Color Models

We provide 12 additional color picker components for different color models, unless your app needs a HEX string as an input/output format.

How to use another color model

Available pickers

Import Value example
{ HexColorPicker } "#ffffff"
{ RgbColorPicker } { r: 255, g: 255, b: 255 }
{ RgbaColorPicker } { r: 255, g: 255, b: 255, a: 1 }
{ RgbStringColorPicker } "rgb(255, 255, 255)"
{ RgbaStringColorPicker } "rgba(255, 255, 255, 1)"
{ HslColorPicker } { h: 0, s: 0, l: 100 }
{ HslaColorPicker } { h: 0, s: 0, l: 100, a: 1 }
{ HslStringColorPicker } "hsl(0, 0%, 100%)"
{ HslaStringColorPicker } "hsla(0, 0%, 100%, 1)"
{ HsvColorPicker } { h: 0, s: 0, v: 100 }
{ HsvaColorPicker } { h: 0, s: 0, v: 100, a: 1 }
{ HsvStringColorPicker } "hsv(0, 0%, 100%)"
{ HsvaStringColorPicker } "hsva(0, 0%, 100%, 1)"

Code example

{ const [color, setColor] = useState({ r: 50, g: 100, b: 150 }); return ; };">
import { RgbColorPicker } from "powerful-color-picker";

const YourComponent = () => {
  const [color, setColor] = useState({ r: 50, g: 100, b: 150 });
  return <RgbColorPicker color={color} onChange={setColor} />;
};

Live demo β†’

Customization

The easiest way to tweak powerful-color-picker is to create another stylesheet to override the default styles.

.your-component .react-colorful {
  height: 240px;
}
.your-component .react-colorful__saturation {
  border-radius: 4px 4px 0 0;
}
.your-component .react-colorful__hue {
  height: 40px;
  border-radius: 0 0 4px 4px;
}
.your-component .react-colorful__hue-pointer {
  width: 12px;
  height: inherit;
  border-radius: 0;
}

See examples β†’

How to paste or type a color?

As you probably noticed the color picker itself does not include an input field, but do not worry if you need one. powerful-color-picker is a modular library that allows you to build any picker you need. Since v2.1 we provide an additional component that works perfectly in pair with our color picker.

How to use HexColorInput
{ const [color, setColor] = useState("#aabbcc"); return (
); };">
import { HexColorPicker, HexColorInput } from "powerful-color-picker";

const YourComponent = () => {
  const [color, setColor] = useState("#aabbcc");
  return (
    <div>
      <HexColorPicker color={color} onChange={setColor} />
      <HexColorInput color={color} onChange={setColor} />
    </div>
  );
};

Live demo β†’

Property Default Description
alpha false Allows #rgba and #rrggbbaa color formats
prefixed false Enables # prefix displaying

HexColorInput does not have any default styles, but it also accepts all properties that a regular input tag does (such as className, placeholder and autoFocus). That means you can place and modify this component as you like. Also, that allows you to combine the color picker and input in different ways:

">
<HexColorInput color={color} onChange={setColor} placeholder="Type a color" prefixed alpha />

Code Recipes

TypeScript Support

powerful-color-picker supports TypeScript and ships with types in the library itself; no need for any other install.

How you can get the most from our TypeScript support

While not only typing its own functions and variables, it can also help you type yours. Depending on the component you are using, you can also import the type that is associated with the component. For example, if you are using our HSL color picker component, you can also import the HSL type.

import { HslColorPicker, HslColor } from "powerful-color-picker";

const myHslValue: HslColor = { h: 0, s: 0, l: 0 };

Take a look at Supported Color Models for more information about the types and color formats you may want to use.

Usage with Preact

powerful-color-picker will work flawlessly with Preact out-of-the-box if you are using WMR, Preact-CLI, NextJS with Preact, or a few other tools/boilerplates thanks to aliasing.

If you are using another solution, please refer to the Aliasing React to Preact section of the Preact documentation.

Preact + Typescript

powerful-color-picker, like all other React + TS projects, can potentially cause issues in a Preact + TS application if you have the @types/react package installed, either as a direct dependency or a dependency of a dependency. For example, the Preact TS template comes with @types/enzyme which has @types/react as a dependency.

To fix this, create a declaration.d.ts file or add to your existing:

import React from "react";

declare global {
    namespace React {
        interface ReactElement {
            nodeName: any;
            attributes: any;
            children: any;
        }
    }
}

This will correct the types and allow you to use powerful-color-picker along with many other React + TS libraries in your Preact + TS application.

Browser Support

It would be an easier task to list all of the browsers and versions that powerful-color-picker does not support! We regularly test against browser versions going all the way back to 2013 and this includes IE11.

powerful-color-picker works out-of-the-box for most browsers, regardless of version, and only requires an Object.assign polyfill be provided for full IE11 support.

Why powerful-color-picker?

Today each dependency drags more dependencies and increases your project’s bundle size uncontrollably. But size is very important for everything that intends to work in a browser.

powerful-color-picker is a simple color picker for those who care about their bundle size and client-side performance. It is fast and lightweight because:

  • Has no dependencies (no risks in terms of vulnerabilities, no unexpected bundle size changes);
  • Built with hooks and functional components only (no classes and polyfills for them);
  • Ships only a minimal amount of manually optimized color conversion algorithms (while most of the popular pickers import entire color manipulation libraries that increase the bundle size by more than 10 KB and make your app slower).

To show you the problem that powerful-color-picker is trying to solve, we have performed a simple benchmark (using bundlephobia.com) against popular React color picker libraries:

Name Bundle size Bundle size (gzip) Dependencies
powerful-color-picker
react-color
react-input-color
rc-color-picker

Projects using powerful-color-picker

Storybook β€” the most widely used open-source tool for developing UI components Storybook
Resume.io β€” online resume builder with over 9,400,000 users worldwide resume.io
Wireflow.co β€” free tool for creating modern user flow prototypes wireflow.co
MagicPattern.design β€” unique geometric pattern generator magicpattern.design
Viewst.com β€” online tool for designing, creating and automating ad campaigns viewst.com
Omatsuri.app β€” progressive web application with a lot of different frontend focused tools omatsuri.app
Leva β€” open source extensible GUI panel made for React pmndrs/leva
Composable β€” online tool for creating custom vector illustrations composable.art

GitHub

https://github.com/Cong-Hieu/powerful-color-picker
You might also like...

Color palette with react jsβš›

features explore template 404 not found page color detail (view) download palette as image copy color code full responsive about page Getting Started

Jan 6, 2022

:art: Color Pickers from Sketch, Photoshop, Chrome, Github, Twitter & more

React Color 13 Different Pickers - Sketch, Photoshop, Chrome and many more Make Your Own - Use the building block components to make your own Demo Liv

Jun 26, 2022

React-colour-wheel: A circular colour-picker React component

A circular colour-picker React component; built with HTML5's canvas & context-api. Full customisation & control through props.

Jun 1, 2022

Provides a native React view that transitions between multiple colors in a linear direction

react-native-background-gradient Provides a native React view that transitions between multiple colors in a linear direction Install yarn add react-na

Jul 29, 2021

Simple login template for React Native.

Simple login template for React Native.

React Native Login Template This repo is proudly sponsored by: React Native Templates & Starter Kits and Apps for easier start. Demo https://simple-lo

Jun 13, 2022

🎨 A tiny (2,5 KB) color picker component for React and Preact apps

🎨 A tiny (2,5 KB) color picker component for React and Preact apps

react-colorful is a tiny color picker component for React and Preact apps. Features Small: Just 2,5 KB gzipped (14 times lighter than react-color). Tr

Jun 22, 2022

react-color is a tiny color picker component for React apps.

 react-color is a tiny color picker component for React apps.

react-color is a tiny color picker component for React apps. Getting Started npm i @uiw/react-color import { Alpha, Hue, Slider, Sketch, Compact } fro

Jun 22, 2022

A tiny and unobtrusive state management library for React and Preact apps

statty A tiny and unobtrusive state management library for React and Preact apps The current size of statty/dist/statty.umd.min.js is: The problem Mos

Jun 6, 2022

Color-picker-menu - Color Picker Menu Built With React

Color-picker-menu - Color Picker Menu Built With React

Color Picker Menu Demo Live Demo Installation & Usage npm install color-picker-m

Apr 13, 2022

Universal rendering for Preact: render JSX and Preact components to HTML.

Universal rendering for Preact: render JSX and Preact components to HTML.

preact-render-to-string Render JSX and Preact components to an HTML string. Works in Node & the browser, making it useful for universal/isomorphic ren

Jun 14, 2022

A Preact task list app, mainly for the purposes of learning Preact.

Toiler This is a task tracking app, written with Preact, Go, and Postgres. This version is very basic and doesn't even properly support auth yet so do

Nov 11, 2021

A tiny Color Picker for React

ColoReact A tiny Color Picker for React [ Demo ] Install $ npm i --save coloreact How to use import ColorPicker from 'coloreact'; // ... retur

May 22, 2022

🌩 A tiny (185 bytes) event-based Redux-like state manager for React, Preact, Angular, Vue, and Svelte

Storeon A tiny event-based Redux-like state manager for React, Preact, Angular, Vue and Svelte. Small. 180 bytes (minified and gzipped). No dependenci

Jun 25, 2022

A tiny (500 bytes) i18n library for React/Preact/Vue/Svelte

Nano Stores I18n Tiny and flexible JS library to make your web application translatable. Uses Nano Stores state manager and JS Internationalization AP

Jun 16, 2022

Teaful - Tiny, easy and powerful React state management

Teaful - Tiny, easy and powerful React state management

Tiny, easy and powerful React state management library What advantages does it have? ✨ πŸ“¦ ・Tiny: Less than 1kb package to manage your state in

Jun 17, 2022

BitAboutState - Tiny and powerful React hook-based state management library

BitAboutState - Tiny and powerful React hook-based state management library

πŸš€ Tiny and powerful React hook-based state management library. 100% Idiomatic React.

May 22, 2022

πŸ’« Tiny and powerful hook-based event system for React

BitAboutEvent πŸ’« Tiny and powerful hook-based event system for React. 100% Idiomatic React.

May 12, 2022

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

nwb nwb is a toolkit for: Quick Development with React, Inferno, Preact or vanilla JavaScript Developing: React Apps Preact Apps Inferno Apps Vanilla

Jun 23, 2022

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)

nwb nwb is a toolkit for: Quick Development with React, Inferno, Preact or vanilla JavaScript Developing: React Apps Preact Apps Inferno Apps Vanilla

Jun 17, 2022
react-color is a tiny color picker component for React apps.
 react-color is a tiny color picker component for React apps.

react-color is a tiny color picker component for React apps. Getting Started npm i @uiw/react-color import { Alpha, Hue, Slider, Sketch, Compact } fro

Jun 22, 2022
Color-picker-menu - Color Picker Menu Built With React
Color-picker-menu - Color Picker Menu Built With React

Color Picker Menu Demo Live Demo Installation & Usage npm install color-picker-m

Apr 13, 2022
A tiny Color Picker for React

ColoReact A tiny Color Picker for React [ Demo ] Install $ npm i --save coloreact How to use import ColorPicker from 'coloreact'; // ... retur

May 22, 2022
Pixi Color Effects - A various color Matrix filters for pixi.js
Pixi Color Effects - A various color Matrix filters for pixi.js

Pixi Color Effects - A various color Matrix filters for pixi.js

Jun 20, 2022
Hooks (and component) for building accessible color picker for React.

Hooks (and component) for building accessible color picker for React. 0 dependecies, tiny ~3K, built-in powerful color conversions, touch and pen support, keyboard and screen-reader accessible, built using React hooks, fast!

Aug 10, 2021
2KB color picker component for React.
2KB color picker component for React.

react-color-palette 2KB color picker component for React.

Jun 7, 2022
React color picker
React color picker

react-input-color React input color component with hsv color picker The color picker is inspired by the sketch color picker Starting from v2, this com

Jun 17, 2022
React best gradient color picker
React best gradient color picker

react-best-gradient-color-picker Customizable, easy to use color and gradient picker for React.js Simply pass in an rgba or css gradient string as val

Jun 9, 2022
Preview of Material-UI-color picker port to Mui v5

mui-color picker and other components Preview port of Material-ui-color to Mui v5 Collections of color components for material-ui. No dependencies, sm

Jun 17, 2022
A color list manager for React
A color list manager for React

React-Color-List A full color palette manager for React Demo Live demo and sandbox Installation React-Color-List is available as an npm package.

Apr 1, 2022