Socket
Socket
Sign inDemoInstall

react-canvas-color-picker

Package Overview
Dependencies
8
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-canvas-color-picker

Simple and customizable canvas color picker built in React + TS


Version published
Maintainers
2
Created

Readme

Source

Image of Color Picker

React Canvas Color Picker

Simple, fast, customizable canvas based color picker built in React. Supports HSLA, HSVA color spectrums, and hsla, hsva, rgba, hex, and hex8 color formats.

Install

npm

npm install react-canvas-color-picker

yarn

yarn add react-canvas-color-picker

Basic Usage

import React, { useState, useRef, useCallback } from "react";
import { ColorPicker } from "react-canvas-color-picker";


function App() {
  const [color, setColor] = useState({ r: 255, g: 255, b: 255, a: 1 });
  const formats = useRef(["rgba"]);

  const handleChange = useCallback(({ colors }) => {
    setColor({ ...colors.rgba });
  }, []);


  return (
      <ColorPicker
        spectrum="hsva"
        formats={formats.current}
        initialColor={color}
        onPanStart={handleChange}
        onPan={handleChange}
      />
  );

}

Props

PropRequiredTypeDefaultDescription
initialColornoRGBA, HSLA, HSVA, HEX, CSS Color{ r: 255, g: 255, b: 255, a: 1 }Color the color picker will mount with
formatsnoCOLOR_FORMATS[] ex: ["rgba", hsla"]["rgba"]Array of color formats sent in callback functions
spectrumno"hsva" or "hsla"hsvaSpecify which color spectrum to use
spectrumWidthnonumber240Sets width of color box and sliders
spectrumHeightnonumber240Sets height of color box
sliderHeightnonumber14Sets height of hue and alpha sliders
classNamenostringundefinedAdditional classes for parent container
spectrumClassesnostringundefinedAdditional classes for hsla / hsva spectrum container
hueClassesnostringundefinedAdditional classes for hue slider container
alphaClassesnostringundefinedAdditional classes for alpha slider container
handleClassesnostringundefinedAdditional classes for slider and spectrum handles
onPanStartno(event: colorPickerChangeEvent) => voidundefinedCallback function when pan starts
onPanno(event: colorPickerChangeEvent) => voidundefinedCallback function on pan
onPanEndno(event: colorPickerChangeEvent) => voidundefinedCallback function when pan ends

Change Events

onPanStart, onPan, and onPanEnd all return an object containing the colors specified in the formats prop, and the id of the spectrum or slider that was panned with.

{
  colors: object;
  canvasId: string;
}

Advanced Usage

See: https://codesandbox.io/s/react-canvas-color-picker-q4heh?file=/src/App.tsx:1280-1429

Keywords

FAQs

Last updated on 30 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc