React Color Palette

7.3.1 · active · verified Sun Apr 19

react-color-palette is a lightweight, performant React component library providing a comprehensive color picker interface. Currently stable at version 7.3.1, it receives regular maintenance and feature updates, with minor releases typically occurring every few months. Its core strength lies in its flexibility, offering a complete `<ColorPicker />` component for immediate use, alongside individual `<Saturation />`, `<Hue />`, and `<Alpha />` components for creating highly customized color picker layouts. It fully supports TypeScript, shipping with declaration files for all its components and hooks like `useColor`. Key features include robust support for various CSS color formats (HEX, RGB, HSL, named colors) in the `useColor` hook, an `onChangeComplete` callback for handling final color selections, and options to customize input visibility or disable the picker entirely. This makes it a versatile choice for applications requiring intuitive and customizable color selection capabilities within a React environment.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic setup of the ColorPicker component, including state management with `useColor`, importing necessary CSS, and handling both continuous color changes and final selection with `onChangeComplete`.

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

function MyColorPickerComponent() {
  // Initialize the color state using the useColor hook. 
  // It can accept HEX, RGB, HSL, or named CSS colors.
  const [color, setColor] = useColor('#561ecb');

  // Optional: Define a callback for when the color selection is finalized (e.g., mouse up).
  const handleColorChangeComplete = (selectedColor) => {
    console.log('Final color selected:', selectedColor.hex);
    // Example: Save to local storage or dispatch an action
    localStorage.setItem('lastSelectedColor', selectedColor.hex);
  };

  return (
    <div>
      <h1>My Application Color Selector</h1>
      <ColorPicker 
        color={color} 
        onChange={setColor} 
        height={250} 
        width={450}
        onChangeComplete={handleColorChangeComplete}
        hideInput={['rgb', 'hsv']}
      />
      <p>Current HEX Color: {color.hex}</p>
      <p>Current RGB Color: {color.rgb.r}, {color.rgb.g}, {color.rgb.b}</p>
    </div>
  );
}

export default MyColorPickerComponent;

view raw JSON →