Powerful Color Picker
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
- Supported Color Models
- Customization
- How to paste or type a color?
- Code Recipes
- TypeScript Support
- Usage with Preact
- Browser Support
- Why powerful-color-picker?
- Projects using powerful-color-picker
Getting Started
Install via npm:
npm install powerful-color-picker
Using
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
import { RgbColorPicker } from "powerful-color-picker";
const YourComponent = () => {
const [color, setColor] = useState({ r: 50, g: 100, b: 150 });
return <RgbColorPicker color={color} onChange={setColor} />;
};
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;
}
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
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>
);
};
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 />