0.3.14 • Published 10 years ago
react-colorpicker v0.3.14
React-ColorPicker
A simple colorpicker written using React.
Uses the Colr library: https://github.com/stayradiated/colr
Installation
npm install --save react-colorpickerYou will also need to add some css styles.
See the example stylesheet for ideas.
Example Usage
var React = require('react');
var ColorPicker = require('react-colorpicker');
var colorpicker = new ColorPicker({
    color: '#c0ffee',
    onChange: function (color) {
        // called whenever the color is changed
        console.log(color.hexString());
    }
});
React.renderComponent(colorpicker, document.body);Setting the Color
Just change the color attribute. Simple.
var Colr = require('colr');
var React = require('react');
var ColorPicker = require('react-colorpicker');
var App = React.createClass({
  getInitialState: function () {
    return {
      color: '#000000',
    };
  },
  setColor: function () {
    var color = Colr.fromRgb(
      Math.random() * 255, 
      Math.random() * 255, 
      Math.random() * 255
    );
    // replace current color and origin color
    this.setState({
      color: color.toHex()
    });
  },
  handleChange: function (color) {
    this.setState({
      color: color.toHex()
    });
  },
  render: function () {
    /* jshint ignore: start */
    return (
      <div>
        <button onClick={this.setColor}>Load Random Color</button>
        <div>Active: {this.state.color}</div>
        <div id='container'>
          <ColorPicker
            color={this.state.color}
            onChange={this.handleChange}
          />
        </div>
      </div>
    );
    /* jshint ignore: end */
  },
});
document.addEventListener('DOMContentLoaded', function () {
  React.renderComponent(new App(), document.body);
});License
MIT
0.3.14
10 years ago
0.3.13
10 years ago
0.3.12
11 years ago
0.3.11
11 years ago
0.3.9
11 years ago
0.3.8
11 years ago
0.3.7
11 years ago
0.3.6
11 years ago
0.3.5
11 years ago
0.3.4
11 years ago
0.3.3
11 years ago
0.3.2
11 years ago
0.3.1
11 years ago
0.3.0
11 years ago
0.2.1
11 years ago
0.2.0
11 years ago
0.1.0
11 years ago
0.0.7
11 years ago
0.0.6
11 years ago
0.0.5
11 years ago
0.0.4
11 years ago
0.0.3
11 years ago
0.0.2
11 years ago
0.0.1
11 years ago