直接上代码:
有兴趣的可以了解一下:
import React from 'react' import reactCSS from 'reactcss' import { SketchPicker } from 'react-color' import {ORG_INITIAL_RGBA_COLOR,ORG_INITIAL_RGBA_COLOR_OBJ,IS_HIDDEN,ORG_FREE_COLOR} from '../../../sources/constants' class SketchExample extends React.Component { constructor(props) { super(props); this.state = { color: ORG_INITIAL_RGBA_COLOR_OBJ }; } handleClick = () => { const {isHidden} = this.props; this.props.dispatch({type: IS_HIDDEN, payload: !isHidden}); }; handleClose = () => { this.props.dispatch({type: IS_HIDDEN, payload: false}); }; handleChange = (color) => { const {dispatch} = this.props; this.setState({ color: color.rgb }); const noneTrans = Math.ceil(255*(1-Number(color.rgb.a))); dispatch({type: ORG_FREE_COLOR, payload: color.hex + noneTrans.toString(16)}); }; hexTo