项目作者: ubcent

项目描述 :
A circular color picker component also named color-wheel performed with react and pure svg
高级语言: JavaScript
项目地址: git://github.com/ubcent/react-circular-color.git
创建时间: 2017-08-17T12:59:31Z
项目社区:https://github.com/ubcent/react-circular-color

开源协议:MIT License

下载


React Circular Color picker npm

A circular color picker component also named color-wheel performed with react and pure svg. Mobile compatible.

circular color picker circular color picker

Installation

  1. npm install react-circular-color

Usage

  1. import React, { Component } from 'react';
  2. import CircularColor from 'react-circular-color';
  3. class ExampleComponent extends Component {
  4. handleColorChange(color) {
  5. console.log(color); // it will be string with a color hash e.g. #1c1c1c
  6. }
  7. render() {
  8. return (
  9. <CircularColor size={200} onChange={this.handleColorChange} ></CircularColor>
  10. );
  11. }
  12. }

Customized elements

  1. import React, { Component } from 'react';
  2. import ColorPicker from 'react-color-picker';
  3. export default class CustomizedColorPicker extends Component {
  4. renderHandle = ({ onHandleDown, cx, cy, handleRadius }) => {
  5. return(
  6. <svg x={cx-10} y={cy-10} width={20} height={20} >
  7. <polygon points={'10,0 0,20 20,20'} fill="#fff" ></polygon>
  8. </svg>
  9. );
  10. }
  11. renderRect = ({ color, x, y }) => {
  12. return (
  13. <circle
  14. cx={x + 14}
  15. cy={y + 14}
  16. r="14"
  17. fill={color}
  18. ></circle>
  19. );
  20. }
  21. render() {
  22. return (
  23. <ColorPicker
  24. renderRect={this.renderRect}
  25. centerRect={true}
  26. renderHandle={this.renderHandle}
  27. />
  28. );
  29. }
  30. }

Props

Name Description
size Numeric size of the element in pixels. Default: 200
numberOfSectors Number of wheel’s sectors. Default: 360
className Classes to apply to the svg element
centerRect Whether to display central rectangle with picked color. Default: false.
onChange Fired when the color is changing
renderRect Use it to customize how the central rectangle with picked color is rendered. Function recieves one object with color, x & y keys
renderHandle Use it to customize how the circular color handle is rendered. Function recieves one object with cx, cy, onHandleDown & handleRadius keys
color String value of color. Default:#f2ff00

Development

To run demo locally on localhost:8080:

  1. npm install
  2. npm start

Test

To run test type:

  1. npm run test