react-color icon indicating copy to clipboard operation
react-color copied to clipboard

How to add `transparent` on `SketchPicker`?

Open zhaoyi0113 opened this issue 7 years ago • 5 comments

I am using SketchPicker in my website and want to add a transparent button on the picker. What is the easiest way to do that?

zhaoyi0113 avatar Jan 25 '19 07:01 zhaoyi0113

You can add a preset color value as 'TRANSPARENT'

sukhminderx avatar Jan 30 '19 08:01 sukhminderx

After that, you can add a css rule such as

.your_color_picker_container div[title='TRANSPARENT']{
background-image = url('some transparent checkered image') !important;
}

sukhminderx avatar Jan 30 '19 09:01 sukhminderx

Is there any doc or sample which demonstrate how to set preset? Below is my code and is preset a property can be passed in?

<SketchPicker
                            color={this.state.color}
                            className={`${colorPickerClassName} color-picker`}
                            onChangeComplete={color => {
                                this.props.setColor(color);
                                this.setState({ color });
                            }}
                        />

zhaoyi0113 avatar Jan 30 '19 09:01 zhaoyi0113

yeah, pass it as props as: `presetColors - Array of Strings or Objects, Hex strings for default colors at bottom of picker. Default

presetColors={['TRANSPARENT','#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF']}

presetColors may also be described as an array of objects with color and title properties: [{ color: '#f00', title: 'red' }] or a combination of both`

sukhminderx avatar Jan 30 '19 09:01 sukhminderx

works great. Thanks.

zhaoyi0113 avatar Jan 30 '19 09:01 zhaoyi0113