UNPKG

react-color

Version:

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

33 lines (26 loc) 1.09 kB
--- id: api-color title: color --- Color controls what color is active on the color picker. You can use this to initialize the color picker with a particular color, or to keep it in sync with the state of a parent component. Color accepts either a string of a hex color `'#333'` or a object of rgb or hsl values `{ r: 51, g: 51, b: 51 }` or `{ h: 0, s: 0, l: .10 }`. Both rgb and hsl will also take a `a: 1` value for alpha. ``` var React = require('react'); var ColorPicker = require('react-color'); class Component extends React.Component { constructor() { super(); this.state = { background: '#fff', }; this.handleChangeComplete = this.handleChangeComplete.bind(this); } handleChangeComplete(color) { this.setState({ background: color.hex }); } render() { return <ColorPicker color={ this.state.background } type="sketch" onChangeComplete={ this.handleChangeComplete } />; } } ``` In this case, the color picker will initialize with the color `#fff`. When the color is changed, `handleChangeComplete` will fire and set the new color to state.