From 6419b948b2a0757f9016aca8da748eb32aefad5e Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 10 Jan 2020 16:00:24 +0800 Subject: [PATCH] =?UTF-8?q?color=20=E4=B8=8D=E5=85=81=E8=AE=B8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=A2=9C=E8=89=B2=E6=97=B6,=20=E4=B8=8D?= =?UTF-8?q?=E7=A6=81=E7=94=A8=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ColorPicker.tsx | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/ColorPicker.tsx b/src/components/ColorPicker.tsx index be695972..a35b4750 100644 --- a/src/components/ColorPicker.tsx +++ b/src/components/ColorPicker.tsx @@ -42,7 +42,7 @@ export interface ColorControlState { export class ColorControl extends React.PureComponent< ColorProps, ColorControlState - > { +> { static defaultProps = { format: 'hex', clearable: true, @@ -135,6 +135,10 @@ export class ColorControl extends React.PureComponent< } handleInputChange(e: React.ChangeEvent) { + if (!this.props.allowCustomColor) { + return; + } + const onChange = this.props.onChange; this.setState( @@ -151,18 +155,26 @@ export class ColorControl extends React.PureComponent< } @autobind - validateColor(value:string) { - if (value === "") { return false; } - if (value === "inherit") { return false; } - if (value === "transparent") { return false; } + validateColor(value: string) { + if (value === '') { + return false; + } + if (value === 'inherit') { + return false; + } + if (value === 'transparent') { + return false; + } - let image = document.createElement("img"); - image.style.color = "rgb(0, 0, 0)"; + let image = document.createElement('img'); + image.style.color = 'rgb(0, 0, 0)'; image.style.color = value; - if (image.style.color !== "rgb(0, 0, 0)") { return true; } - image.style.color = "rgb(255, 255, 255)"; + if (image.style.color !== 'rgb(0, 0, 0)') { + return true; + } + image.style.color = 'rgb(255, 255, 255)'; image.style.color = value; - return image.style.color !== "rgb(255, 255, 255)"; + return image.style.color !== 'rgb(255, 255, 255)'; } handleChange(color: ColorResult) { @@ -229,7 +241,7 @@ export class ColorControl extends React.PureComponent< className={cx('ColorPicker-input')} value={this.state.inputValue || ''} placeholder={placeholder} - disabled={disabled || !allowCustomColor} + disabled={disabled} onChange={this.handleInputChange} onFocus={this.handleFocus} onBlur={this.handleBlur} @@ -274,7 +286,7 @@ export class ColorControl extends React.PureComponent< presetColors={presetColors} onChangeComplete={this.handleChange} /> - ) : ( + ) : (