2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
2016-09-26 11:08:27 +08:00
|
|
|
|
category:
|
|
|
|
|
zh-CN: 设计基础
|
|
|
|
|
en-US: Design Fundamental
|
2016-03-31 14:17:09 +08:00
|
|
|
|
order: 2
|
2016-09-21 11:28:38 +08:00
|
|
|
|
title:
|
|
|
|
|
zh-CN: 色彩
|
|
|
|
|
en-US: Colors
|
2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
2015-08-05 17:35:52 +08:00
|
|
|
|
|
2017-01-12 21:51:40 +08:00
|
|
|
|
设计中对色彩的运用不仅应考虑品牌的识别性,还需达到信息传递、操作指引、交互反馈,或是强化和凸显某一个元素的目的。基于操作系统更注重高效、清晰等特点,Ant Design 的用色上更偏向简洁实用一些。在选择色彩时有以下三个注意点:
|
2015-08-05 17:35:52 +08:00
|
|
|
|
|
2017-01-12 21:51:40 +08:00
|
|
|
|
- 色彩应与产品定位相匹配,且符合用户心理认知;
|
|
|
|
|
- 视觉层次应清晰分明,为重要行动点或关键信息定义一个主色,并建立视觉连续性;
|
|
|
|
|
- 遵守 WCAG 2.0 的 标准,保证足够的对比度,让色彩更容易被视障碍(色盲)用户识别。
|
2015-08-05 17:35:52 +08:00
|
|
|
|
|
2016-03-14 16:18:06 +08:00
|
|
|
|
## Ant Design Colors
|
2015-08-05 17:35:52 +08:00
|
|
|
|
|
2017-01-12 21:51:40 +08:00
|
|
|
|
Ant Design PC 端的色板由 10 个由浅至深的色彩单元格组成,我们为部分色彩格定义了默认使用场景,用户在进行色彩配色时只需根据关键词选择一条色板即可得到一套完整的系统配色方案。在理论上,在 UI 设计中的色彩都应取自这份色板。
|
|
|
|
|
|
|
|
|
|
经过设计师和程序员的精心调教,结合了色彩加白、加黑、加深,贝塞尔曲线,以及针对冷暖色的不同旋转角度,得出一套[色板生成算法](https://github.com/ant-design/ant-design/blob/734beb84ffc3f0469fbae1566aa8450f966cb261/components/style/color/colorPalette.less)。使用者只需指定主色,便可导出一条完整的渐变色板。
|
|
|
|
|
|
|
|
|
|
Ant Design 的色板由 8 种基本色彩组成,每种基本色(第 6 格)又按上述算法衍生出 10 种渐变色。
|
|
|
|
|
|
|
|
|
|
> 注:在由浅至深的色板里,第 6 格色彩单元格普遍满足 [WCAG 2.0](http://leaverou.github.io/contrast-ratio/) 的 4.5:1 最小对比度(AA 级),我们将其定义为色板的默认品牌色。
|
2017-01-01 22:20:06 +08:00
|
|
|
|
|
2015-08-05 17:35:52 +08:00
|
|
|
|
|
2016-03-03 17:23:08 +08:00
|
|
|
|
`````__react
|
2017-01-04 15:13:55 +08:00
|
|
|
|
const rgbToHex = (rgbString) => {
|
|
|
|
|
const hexChars = '0123456789ABCDEF';
|
|
|
|
|
const rgb = rgbString.match(/\d+/g);
|
|
|
|
|
let r = parseInt(rgb[0]).toString(16);
|
|
|
|
|
let g = parseInt(rgb[1]).toString(16);
|
|
|
|
|
let b = parseInt(rgb[2]).toString(16);
|
|
|
|
|
r = r.length === 1 ? `0${r}` : r;
|
|
|
|
|
g = g.length === 1 ? `0${g}` : g;
|
|
|
|
|
b = b.length === 1 ? `0${ b}` : b;
|
|
|
|
|
return '#' + r + g + b;
|
|
|
|
|
};
|
2016-03-04 09:55:03 +08:00
|
|
|
|
const Palette = React.createClass({
|
2017-01-04 15:13:55 +08:00
|
|
|
|
getInitialState() {
|
|
|
|
|
return { hexColors: null };
|
|
|
|
|
},
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const hexColors = {};
|
|
|
|
|
Object.keys(this.colorNodes).forEach(key => {
|
|
|
|
|
hexColors[key] = rgbToHex(getComputedStyle(this.colorNodes[key])['background-color'])
|
|
|
|
|
});
|
|
|
|
|
this.setState({ hexColors });
|
|
|
|
|
},
|
2015-08-05 17:35:52 +08:00
|
|
|
|
render() {
|
2017-01-04 15:13:55 +08:00
|
|
|
|
this.colorNodes = this.colorNodes || {};
|
2017-01-01 22:20:06 +08:00
|
|
|
|
const { name, description, color } = this.props.color;
|
2017-01-04 15:13:55 +08:00
|
|
|
|
const { hexColors } = this.state;
|
2017-01-01 22:20:06 +08:00
|
|
|
|
const colors = [];
|
|
|
|
|
for (let i = 1; i <= 10; i++) {
|
|
|
|
|
colors.push(
|
|
|
|
|
<div
|
|
|
|
|
key={i}
|
2017-01-04 15:13:55 +08:00
|
|
|
|
ref={node => { this.colorNodes[`${name}-${i}`] = node; } }
|
2017-01-01 22:20:06 +08:00
|
|
|
|
className={`main-color-item palatte-${name}-${i}`}
|
|
|
|
|
style={{
|
|
|
|
|
color: i > 5 ? '#fff' : 'unset',
|
|
|
|
|
fontWeight: i === 6 ? 'bold' : 'normal',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{name}-{i}
|
2017-01-04 15:13:55 +08:00
|
|
|
|
{hexColors ? <span className="main-color-value">{hexColors[`${name}-${i}`]}</span> : null}
|
2017-01-01 22:20:06 +08:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="color-palette">
|
|
|
|
|
<div className="color-title">
|
|
|
|
|
{name}
|
|
|
|
|
<span className="color-description">{description}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="main-color">{colors}</div>
|
2015-08-14 20:10:17 +08:00
|
|
|
|
</div>
|
2017-01-01 22:20:06 +08:00
|
|
|
|
);
|
2015-08-05 17:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-03-04 09:55:03 +08:00
|
|
|
|
const ExtendPalettes = React.createClass({
|
2015-08-05 17:35:52 +08:00
|
|
|
|
render() {
|
2016-03-04 09:55:03 +08:00
|
|
|
|
const colors = [
|
2015-08-14 20:10:17 +08:00
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'red',
|
|
|
|
|
description: '热情、警示',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'green',
|
|
|
|
|
description: '成功、通过、安全',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'blue',
|
|
|
|
|
description: '专业、科技',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'pink',
|
|
|
|
|
description: '典雅、明快、女性',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'orange',
|
|
|
|
|
description: '醒目、温暖',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'purple',
|
|
|
|
|
description: '高雅、浪漫',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'yellow',
|
|
|
|
|
description: '活力、提示',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2017-01-01 22:20:06 +08:00
|
|
|
|
name: 'cyan',
|
|
|
|
|
description: '清新、冷静、结构化',
|
2017-03-03 13:48:22 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'grey',
|
|
|
|
|
description: '平稳、中性',
|
2015-08-14 20:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
];
|
2017-01-01 22:20:06 +08:00
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{colors.map((color, i) => <Palette key={color.name} color={color} />)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2015-08-05 17:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-03-04 09:55:03 +08:00
|
|
|
|
ReactDOM.render(<ExtendPalettes key="palettes" />, mountNode);
|
2015-08-05 17:35:52 +08:00
|
|
|
|
`````
|