import React from 'react' import Color from 'color' import ChromePicker from 'react-color/lib/components/chrome/Chrome' import input from '../../config/input.js' function formatColor(color) { const rgb = color.rgb return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})` } /*** Number fields with support for min, max and units and documentation*/ class ColorField extends React.Component { static propTypes = { onChange: React.PropTypes.func.isRequired, name: React.PropTypes.string.isRequired, value: React.PropTypes.string, default: React.PropTypes.number, doc: React.PropTypes.string, style: React.PropTypes.object, } constructor(props) { super(props) this.state = { pickerOpened: false } } togglePicker() { this.setState({ pickerOpened: !this.state.pickerOpened }) } render() { const picker =
this.props.onChange(formatColor(c))} />
return
{this.state.pickerOpened && picker} this.props.onChange(e.target.value)} />
} } export default ColorField