npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-colour-wheel

v1.0.7

Published

A circular colour-picker React component; built with HTML5's canvas & context-api

Downloads

17

Readme

react-colour-wheel

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

Demo

react-colour-wheel

Check out this CodeSandbox example.

Quick-start guide

Installation

npm install react-colour-wheel
yarn add react-colour-wheel

...and wherever you need the component:

import ColourWheel from 'react-colour-wheel'

Start by giving your ColourWheel a radius, lineWidth, and utilise the rgb-value sent through onColourSelected:

<ColourWheel
  radius={200}
  lineWidth={50}
  onColourSelected={(rgb) => this.setState({ selectedColour: rgb })}
/>

However, a more typical implementation might look like:

<ColourWheel
  radius={200}
  padding={10}
  lineWidth={50}
  onColourSelected={(rgb) => this.setState({ rgb })}
  onRef={ref => (this.colourWheel = ref)}
  spacers={{
    colour: '#FFFFFF',
    shadowColour: 'grey',
    shadowBlur: 5
  }}
  preset
  presetColour={this.state.rgb}
  animated
/>

Customisation

The ColourWheel component has many options available for customisation through props:

radius

Customise the radius of the ColourWheel, all the way to the outer-edge.

  • pixels, px
  • propTypes: number, isRequired

radius={200}


lineWidth

Customise the width of the outer- and inner-wheels.

  • pixels, px
  • propTypes: number, isRequired

lineWidth={50}


onColourSelected

Method that returns an rgb-value; typical use case might be to setState({ rgb }) on the parent-component.

  • propTypes: func

onColourSelected={(rgb) => ... )}


padding

Sets the space between the outer-wheel, inner-wheel, and the center-circle.

  • pixels, px
  • propTypes: number

padding={10}


spacers

Allows you to customise the styling of the padding that was set:

  • Need to specify an object with colour, shadowColour, and shadowBlur properties.
  • propTypes: object
  spacers={{
    colour: '#FFFFFF',
    shadowColour: 'grey',
    shadowBlur: 5
  }}

colours

Allows you to define an array of colours that will populate the outer-wheel of the colour-wheel.

  • By default, an array of 16 hex-strings is provided to help you get started.
  • colours accepts hex-strings, rgb-strings & objects, names and other variations.
  • propTypes: array
  • defaultProps: A comprehensive array of 16 colours.
  colours={[
    'blue',
    'rgb(200, 200, 200)',
    '#FFFFFF'
  ]}

shades

Choose the number of shades that will be produced when any particular colour is chosen.

  • The array of shades produced & rendered will scale evenly from 10% - 90% luminosity of the selected colour.
  • propTypes: number
  • defaultProps: 16
  shades={12}

dynamicCursor

Determines whether or not the cursor-style should update dynamically depending on where it is hovering.

  • propTypes: bool
  • defaultProps: true

presetColour

If you want the colour-wheel to render w a colour already provided, use the presetColour prop:

  • propTypes: string
  • Important: You must set the preset prop to true when a presetColour is set.

animated

Specifies whether the inner-wheel will animate when an outer-wheel colour is selected.

  • propTypes: bool
  • defaultProps: true

How do I clear the colour-wheel programmatically?

  1. Create a ref to the colour-wheel component in your parent component:
<ColourWheel
 ...
 onRef={ref => (this.colourWheel = ref)}
 ...
/>
  1. Call the colour-wheel's .clear() method from your parent component where you need it:
  clearColourWheel = () => {
    this.colourWheel.clear(() => ...)
    // NOTE: Optional callback which you can use to do stuff after the wheel has been cleared.
  }

Issues

  • [ ] The ColourWheel won't animate if a spacers prop isn't provided.