| | |
| | | |
| | | import './index.scss' |
| | | |
| | | const presetColors = [ |
| | | '#f5222d', '#fa541c', '#fa8c16', '#faad14', '#fadb14', '#a0d911', '#52c41a', '#13c2c2', '#1890ff', '#2f54eb', '#722ed1', |
| | | '#eb2f96', '#595959', '#ffa39e', '#ffbb96', '#ffd591', '#ffe58f', '#fffb8f', '#eaff8f', '#b7eb8f', '#87e8de', '#91d5ff', |
| | | '#adc6ff', '#d3adf7', '#ffadd2', '#d9d9d9', '#000000', '#ffffff', 'transparent' |
| | | ] |
| | | |
| | | class ColorSketch extends Component { |
| | | static propTpyes = { |
| | | defaultValue: PropTypes.any, |
| | | value: PropTypes.any, |
| | | onChange: PropTypes.func |
| | | } |
| | | state = { |
| | | color: this.props.value, |
| | | color: this.props.defaultValue || this.props.value, |
| | | } |
| | | |
| | | handleChange = (color) => { |
| | | let _color = `rgba(${ color.rgb.r }, ${ color.rgb.g }, ${ color.rgb.b }, ${ color.rgb.a })` |
| | | |
| | | this.setState({ color: _color }, () => { |
| | | this.props.onChange(_color) |
| | | this.props.onChange && this.props.onChange(_color) |
| | | }) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.value !== this.state.color) { |
| | | if (nextProps.value && nextProps.value !== this.state.color) { |
| | | this.setState({ color: nextProps.value }) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { color } = this.state |
| | | |
| | | return ( |
| | | <div className="color-sketch-block"> |
| | | <Popover content={ |
| | | <SketchPicker color={ color } onChange={ this.handleChange } /> |
| | | <SketchPicker color={ color } presetColors={presetColors} onChange={ this.handleChange } /> |
| | | } overlayClassName="color-sketch-popover" placement="bottomRight" title="" trigger="click"> |
| | | <div className="color-sketch-block-inner" style={ {background: color} }></div> |
| | | </Popover> |