mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
Make color value can be selectable
This commit is contained in:
parent
4443db4de6
commit
6750c0b82b
@ -19,14 +19,38 @@ Ant Design 的色板由 8 种基本色彩组成,通过一套[精心设计的
|
|||||||
> 我们结合了色彩加白、加黑、加深,贝塞尔曲线,以及针对冷暖色的不同旋转角度,调教出一套色彩算法。使用者只需指定主色,便可导出一条完整的渐变色板。
|
> 我们结合了色彩加白、加黑、加深,贝塞尔曲线,以及针对冷暖色的不同旋转角度,调教出一套色彩算法。使用者只需指定主色,便可导出一条完整的渐变色板。
|
||||||
|
|
||||||
`````__react
|
`````__react
|
||||||
|
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;
|
||||||
|
};
|
||||||
const Palette = React.createClass({
|
const Palette = React.createClass({
|
||||||
|
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 });
|
||||||
|
},
|
||||||
render() {
|
render() {
|
||||||
|
this.colorNodes = this.colorNodes || {};
|
||||||
const { name, description, color } = this.props.color;
|
const { name, description, color } = this.props.color;
|
||||||
|
const { hexColors } = this.state;
|
||||||
const colors = [];
|
const colors = [];
|
||||||
for (let i = 1; i <= 10; i++) {
|
for (let i = 1; i <= 10; i++) {
|
||||||
colors.push(
|
colors.push(
|
||||||
<div
|
<div
|
||||||
key={i}
|
key={i}
|
||||||
|
ref={node => { this.colorNodes[`${name}-${i}`] = node; } }
|
||||||
className={`main-color-item palatte-${name}-${i}`}
|
className={`main-color-item palatte-${name}-${i}`}
|
||||||
style={{
|
style={{
|
||||||
color: i > 5 ? '#fff' : 'unset',
|
color: i > 5 ? '#fff' : 'unset',
|
||||||
@ -34,6 +58,7 @@ const Palette = React.createClass({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{name}-{i}
|
{name}-{i}
|
||||||
|
{hexColors ? <span className="main-color-value">{hexColors[`${name}-${i}`]}</span> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,21 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-color .main-color-item {
|
.main-color {
|
||||||
width: 80px;
|
&-item {
|
||||||
height: 60px;
|
width: 80px;
|
||||||
border-radius: 4px;
|
height: 60px;
|
||||||
float: left;
|
border-radius: 4px;
|
||||||
margin: 0 5px 5px 0;
|
float: left;
|
||||||
transition: all .2s;
|
margin: 0 5px 5px 0;
|
||||||
position: relative;
|
transition: all .2s;
|
||||||
text-align: center;
|
position: relative;
|
||||||
padding-top: 20px;
|
text-align: center;
|
||||||
font-family: Consolas;
|
padding-top: 20px;
|
||||||
font-size: 12px;
|
font-family: Consolas;
|
||||||
&:after {
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
&-item &-value {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -4px;
|
bottom: -4px;
|
||||||
@ -49,10 +51,10 @@
|
|||||||
.main-color:hover {
|
.main-color:hover {
|
||||||
.main-color-item {
|
.main-color-item {
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
&:after {
|
}
|
||||||
opacity: 0.7;
|
.main-color-value {
|
||||||
bottom: 3px;
|
opacity: 0.7;
|
||||||
}
|
bottom: 3px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,9 +94,6 @@
|
|||||||
.palatte-@{color}-@{index} {
|
.palatte-@{color}-@{index} {
|
||||||
@background: "@{color}-@{index}";
|
@background: "@{color}-@{index}";
|
||||||
background: @@background;
|
background: @@background;
|
||||||
&:after {
|
|
||||||
content: "@{@{background}}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.make-palatte(@color, (@index + 1)); // next iteration
|
.make-palatte(@color, (@index + 1)); // next iteration
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user