JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 34832
  • Score
    100M100P100Q147791F
  • License MIT

🎨 Lightweight Color Picker component for React.

Package Exports

  • react-color-palette
  • react-color-palette/css
  • react-color-palette/dist/css/rcp.css
  • react-color-palette/package.json

Readme

react-color-palette

🎨 Lightweight <ColorPicker /> component for React.

npm downloads size

Installation

yarn

yarn add react-color-palette

npm

npm install react-color-palette

Usage

import { ColorPicker, useColor } from "react-color-palette";
import "react-color-palette/css";

export function App() {
  const [color, setColor] = useColor("#561ecb");

  return <ColorPicker color={color} onChange={setColor} />;
}

Examples

Usage rgb() in useColor()

import { ColorPicker, useColor } from "react-color-palette";
import "react-color-palette/css";

export function App() {
  const [color, setColor] = useColor("rgb(86 30 203)");

  return <ColorPicker color={color} onChange={setColor} />;
}

Usage <named-color> in useColor()

import { ColorPicker, useColor } from "react-color-palette";
import "react-color-palette/css";

export function App() {
  const [color, setColor] = useColor("cyan");

  return <ColorPicker color={color} onChange={setColor} />;
}

Custom Layout

import { Saturation, Hue, useColor } from "react-color-palette";
import "react-color-palette/css";

export function App() {
  const [color, setColor] = useColor("hsl(120 100% 50% / .5)");

  return (
    <div className="custom-layout">
      <Saturation height={300} color={color} onChange={setColor} />
      <Hue color={color} onChange={setColor} />
    </div>
  );
}

API

<ColorPicker />

The main component, which includes: <Saturation />, <Hue />, <Alpha /> and <Fields /> components for instant use.
If you need a custom layout, then you can use <Saturation />, <Hue /> and <Alpha /> components separately, which are also exported from the library.

Prop Type Default Description
height number 200 Height of the Saturation component in pixels.
hideAlpha boolean false Hides the Alpha component.
hideInput boolean false Hides the Fields component.
color IColor Currently color.
onChange Function Сallback function will be fired when color changes.

<Saturation />

Prop Type Default Description
height number Height of the saturation element in pixels.
color IColor Currently color.
onChange Function Сallback function will be fired when color changes.

<Hue />

Prop Type Default Description
color IColor Currently color.
onChange Function Сallback function will be fired when color changes.

<Alpha />

Prop Type Default Description
color IColor Currently color.
onChange Function Сallback function will be fired when color changes.

useColor()

Arg Type Default Description
initialColor TColor Initial сolor.

TColor

Value can be specified using one of the methods listed below:

IColor

Field Type
hex string
rgb IColorRgb
hsv IColorHsv

IColorRgb

Field Type
r number
g number
b number
a number

IColorHsv

Field Type
h number
s number
v number
a number

License

Code released under the MIT license.