Giter VIP home page Giter VIP logo

react-colorpickr's Introduction

A colorpicker for React

npm version Circle CI

Demo

Install

npm install @mapbox/react-colorpickr

You'll also want to include a copy of colorpickr.css in your code.

<link href='react-colorpickr.css' rel='stylesheet' />

Usage

import React from 'react'
import ColorPicker from '@mapbox/react-colorpickr'

export default class Example extends React.PureComponent {
  onChange = color => {
    console.log(color);
  };

  render() {
    return (
      <ColorPicker onChange={this.onChange} />
    )
  }
}

Required properties

onChange

Value should be a function and is called whenever a color is updated from the colorpicker. Returns a color object.

Optional properties

theme

By default, react-colorpickr depends on Assembly and the CSS located in dist/colorpickr.css. You can however, override it thanks to react-themeable which react-colorpickr uses internally. See the properties used and the class name values in theme.js.

initialValue

Accepts any valid css color. If this isn't provided, a default color is used.

mode

Defaults to hsl. Initializes which color model tab is active. Possible options: hsl, rgb.

channel

Defaults to h. Initializes which color channel is active. Possible options: h, s, l, r, g, b.

reset

If reset is provided as a property with a value of true a reset button is added that when pressed, reverts back to the original color when the colorpicker is initialized on the page. Defaults to true.

mounted

To use internal methods from react-colorpickr, mounted provides access to the components instance. This is helpful for calling methods like overrideValue that can manually set a new color.

instance = null;

setInstance = picker => {
  this.instance = picker;
};

override = () => {
  this.instance.overrideValue('red');
};

render() {
  <div>
    <ColorPickr mounted={this.setInstance} onChange={console.log} />
    <button onClick={this.override}>Override</button>
  </div>
}

Developing

npm install & npm start

Then open http://localhost:9966/example/ in browser.

Inspired by https://github.com/wangzuo/react-input-color

react-colorpickr's People

Contributors

andrewharvey avatar cherniavskii avatar conorhastings avatar dafrok avatar davidtheclark avatar frankrowe avatar kelvinabrokwa avatar kungfoolabs avatar mcwhittemore avatar pferraris avatar samanpwbb avatar scothis avatar tmcw avatar tristen avatar waldyrious avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.