@thecb/components 9.1.7-beta.5 → 9.1.7-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +10 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +10 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/util/colorUtils.js +13 -4
package/package.json
CHANGED
package/src/util/colorUtils.js
CHANGED
|
@@ -73,6 +73,15 @@ const hexToRbg = hexColor => {
|
|
|
73
73
|
return [red, green, blue];
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
const rbgToHex = rbgColor => {
|
|
77
|
+
hexCodes = rbgColor.map(c => {
|
|
78
|
+
const hex = c.toString(16).toUpperCase();
|
|
79
|
+
return hex.length == 1 ? "0" + hex : hex;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return "#" + hexCodes.join("");
|
|
83
|
+
};
|
|
84
|
+
|
|
76
85
|
/*
|
|
77
86
|
Function to calculate a new hex color given an original
|
|
78
87
|
hex color, a hex background color, and an opacity number
|
|
@@ -80,7 +89,7 @@ const hexToRbg = hexColor => {
|
|
|
80
89
|
|
|
81
90
|
For example, to add a 20% black opacity (20% darker) to a green color
|
|
82
91
|
("#00ff00"):
|
|
83
|
-
addOpacityToHex("00ff00", "#000000", .2) => "
|
|
92
|
+
addOpacityToHex("00ff00", "#000000", .2) => "#00CC00"
|
|
84
93
|
*/
|
|
85
94
|
const addOpacityToHex = (hexColor, background, opacity) => {
|
|
86
95
|
if (hexColor == TRANSPARENT) {
|
|
@@ -93,7 +102,7 @@ const addOpacityToHex = (hexColor, background, opacity) => {
|
|
|
93
102
|
Math.floor(opacity * backgroundRbg[index] + (1 - opacity) * colorElem)
|
|
94
103
|
);
|
|
95
104
|
|
|
96
|
-
return
|
|
105
|
+
return rbgToHex(newColor);
|
|
97
106
|
};
|
|
98
107
|
|
|
99
108
|
/*
|
|
@@ -101,10 +110,10 @@ const addOpacityToHex = (hexColor, background, opacity) => {
|
|
|
101
110
|
it merges together a black or white opacity color with the original.
|
|
102
111
|
|
|
103
112
|
Lighten a color by 50%
|
|
104
|
-
lighten("#505050", .5) => "
|
|
113
|
+
lighten("#505050", .5) => "#A7A7A7"
|
|
105
114
|
|
|
106
115
|
Darken a color by 50%
|
|
107
|
-
darken("#505050", .5) => "
|
|
116
|
+
darken("#505050", .5) => "#282828"
|
|
108
117
|
*/
|
|
109
118
|
export const lighten = (hexColor, opacity) =>
|
|
110
119
|
addOpacityToHex(hexColor, "#ffffff", opacity);
|