import React from 'react' import PropTypes from 'prop-types' import { SketchPicker } from 'react-color' import CSSModules from 'browser/lib/CSSModules' import styles from './ColorPicker.styl' const componentHeight = 330 class ColorPicker extends React.Component { constructor(props) { super(props) this.state = { color: this.props.color || '#939395' } this.onColorChange = this.onColorChange.bind(this) this.handleConfirm = this.handleConfirm.bind(this) } componentWillReceiveProps(nextProps) { this.onColorChange(nextProps.color) } onColorChange(color) { this.setState({ color }) } handleConfirm() { this.props.onConfirm(this.state.color) } render() { const { onReset, onCancel, targetRect } = this.props const { color } = this.state const clientHeight = document.body.clientHeight const alignX = targetRect.right + 4 let alignY = targetRect.top if (targetRect.top + componentHeight > clientHeight) { alignY = targetRect.bottom - componentHeight } return (
) } } ColorPicker.propTypes = { color: PropTypes.string, targetRect: PropTypes.object, onConfirm: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired, onReset: PropTypes.func.isRequired } export default CSSModules(ColorPicker, styles)