site: valid primary color range

This commit is contained in:
afc163 2018-04-27 22:09:49 +08:00
parent be43e56835
commit 8b02a21d36
3 changed files with 53 additions and 25 deletions

View File

@ -9,13 +9,23 @@
&-pick {
text-align: center;
font-size: 20px;
margin-bottom: 8px;
margin: 0 0 20px;
}
&-picker {
margin: 12px 0 24px;
margin: 24px 0;
&-value {
font-size: 13px;
font-size: 14px;
font-family: Consolas;
margin-left: 16px;
position: relative;
top: -3px;
}
&-validation {
font-size: 13px;
color: @error-color;
margin-left: 16px;
position: relative;
top: -3px;
}
}
}

View File

@ -3,41 +3,59 @@ import { FormattedMessage } from 'react-intl';
import ColorPicker from './ColorPicker';
import ColorPatterns from './ColorPatterns';
const primaryMinSaturation = 70; //
const primaryMinBrightness = 70; //
// eslint-disable-next-line
export default class ColorPaletteTool extends Component {
state = {
primaryColor: '#1890ff',
primaryColorInstance: null,
};
handleChangeColor = (e) => {
handleChangeColor = (e, color) => {
const value = e.target ? e.target.value : e;
this.setState({
primaryColor: value,
primaryColorInstance: color,
});
}
renderColorValidation() {
const { primaryColorInstance } = this.state;
let text = '';
if (primaryColorInstance) {
if (primaryColorInstance.hsv.s * 100 < primaryMinSaturation) {
text += ` 饱和度建议不低于${primaryMinSaturation}(现在 ${(primaryColorInstance.hsv.s * 100).toFixed(2)}`;
}
if (primaryColorInstance.hsv.v * 100 < primaryMinBrightness) {
text += ` 亮度建议不低于${primaryMinBrightness}(现在 ${(primaryColorInstance.hsv.v * 100).toFixed(2)}`;
}
}
return <span className="color-palette-picker-validation">{text.trim()}</span>;
}
render() {
return (
<div style={{ margin: '0 auto', textAlign: 'center' }}>
<div className="color-palette-horizontal">
<div className="color-palette-pick">
<FormattedMessage id="app.docs.color.pick-primary" />
<div className="color-palette-picker">
<span style={{ display: 'inline-block' }}>
<ColorPicker
type="chrome"
color={this.state.primaryColor}
onChange={this.handleChangeColor}
/>
</span>
<div className="color-palette-picker-value">
{this.state.primaryColor}
</div>
</div>
</div>
<div className="main-color">
<ColorPatterns color={this.state.primaryColor} />
</div>
<div className="color-palette-horizontal">
<div className="color-palette-pick">
<FormattedMessage id="app.docs.color.pick-primary" />
</div>
<div className="main-color">
<ColorPatterns color={this.state.primaryColor} />
</div>
<div className="color-palette-picker">
<span style={{ display: 'inline-block', verticalAlign: 'middle' }}>
<ColorPicker
type="chrome"
color={this.state.primaryColor}
onChange={this.handleChangeColor}
/>
</span>
<span className="color-palette-picker-value">
{this.state.primaryColor}
</span>
{this.renderColorValidation()}
</div>
</div>
);

View File

@ -33,7 +33,7 @@ export default class ColorPicker extends Component {
};
handleChange = (color) => {
this.setState({ color: color.hex });
this.props.onChange(color.hex);
this.props.onChange(color.hex, color);
};
handleChangeComplete = (color) => {
this.setState({ color: color.hex });