Skip to content

Commit 3cb5144

Browse files
committed
color: add contrast method
1 parent a992b59 commit 3cb5144

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/color/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ color.combine = function(front, back) {
5757
return tinycolor(fcflat).toRgbString();
5858
};
5959

60+
color.contrast = function(cstr, lightAmount, darkAmount) {
61+
var tc = tinycolor(cstr);
62+
63+
var newColor = tc.isLight() ?
64+
tc.darken(darkAmount) :
65+
tc.lighten(lightAmount);
66+
67+
return newColor.toString();
68+
};
69+
6070
color.stroke = function(s, c) {
6171
var tc = tinycolor(c);
6272
s.style({'stroke': color.tinyRGB(tc), 'stroke-opacity': tc.getAlpha()});

0 commit comments

Comments
 (0)