We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bb1f49e commit 02b218bCopy full SHA for 02b218b
src/Utils.js
@@ -89,3 +89,24 @@ export const mergeViewStyle = (style, defaultStyle) => {
89
}
90
return style;
91
};
92
+
93
+/**
94
+ * Get color contrast
95
+ * @param hexcolor
96
+ * @returns {string}
97
+ */
98
+export const getColorContrast = (hexcolor) => {
99
+ if (hexcolor.slice(0, 1) === '#') {
100
+ hexcolor = hexcolor.slice(1);
101
+ }
102
+ if (hexcolor.length === 3) {
103
+ hexcolor = hexcolor.split('').map(function (hex) {
104
+ return hex + hex;
105
+ }).join('');
106
107
+ var r = parseInt(hexcolor.substr(0,2),16);
108
+ var g = parseInt(hexcolor.substr(2,2),16);
109
+ var b = parseInt(hexcolor.substr(4,2),16);
110
+ var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
111
+ return (yiq >= 128) ? '#000000' : '#FFFFFF';
112
+};
0 commit comments