diff --git a/spec/colors.md b/spec/colors.md index 2cb4a5e1b2..dc547aa995 100644 --- a/spec/colors.md +++ b/spec/colors.md @@ -191,3 +191,69 @@ let ExtendPalettes = React.createClass({ }); React.render(, document.getElementById('extend-palettes')); ````` + +## 色彩换算工具 + + + +> 正数为变淡 `tint` ,负数为加深 `shade`。 + +
+ +Ant Design 专用色彩换算工具,用于解析类似 `#2db7f5 tint 80%` 的色彩标注。 + +less 或 scss 语言可以直接使用 `tint(#2db7f5, 80%)` 和 `shade(#2db7f5, 80%)` 的语法。 + + + +`````jsx +let Button = antd.Button; +let InputNumber = antd.InputNumber; +let Slider = antd.Slider; +let TintShadeTool = React.createClass({ + getInitialState() { + return { + result: '', + color: '#2db7f5', + value: 80 + }; + }, + handleChangeColor(e) { + this.setState({ + color: e.target.value + }, this.calculate); + }, + handleChangeValue(value) { + this.setState({ + value: value + }, this.calculate); + }, + componentDidMount() { + this.calculate(); + }, + calculate() { + let tintOrShade = this.state.value >= 0 ? 'tint' : 'shade'; + let c = new Values(this.state.color); + this.setState({ + result: '#' + c[tintOrShade](Math.abs(this.state.value)).hex + }); + }, + render() { + return
+
+ + + % +
+ {this.state.result} +
+
+ +
+
+
; + } +}); + +React.render(, document.getElementById('color-tint-shade-tool')); +`````