@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "9.1.7-beta.5",
3
+ "version": "9.1.7-beta.6",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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) => "rgb(0, 204, 0)"
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 `rgb(${newColor[0]}, ${newColor[1]}, ${newColor[2]})`;
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) => "rgb(167, 167, 167)"
113
+ lighten("#505050", .5) => "#A7A7A7"
105
114
 
106
115
  Darken a color by 50%
107
- darken("#505050", .5) => "rgb(40, 40, 40)"
116
+ darken("#505050", .5) => "#282828"
108
117
  */
109
118
  export const lighten = (hexColor, opacity) =>
110
119
  addOpacityToHex(hexColor, "#ffffff", opacity);