@thecb/components 9.1.7-beta.3 → 9.1.7-beta.5

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.3",
3
+ "version": "9.1.7-beta.5",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -16,12 +16,11 @@ import {
16
16
  GREY_CHATEAU,
17
17
  MINESHAFT_GREY,
18
18
  STORM_GREY,
19
- TRANSPARENT,
20
19
  WHITE
21
20
  } from "../../../constants/colors";
22
21
  import { fallbackValues } from "./Dropdown.theme";
23
22
  import { themeComponent } from "../../../util/themeUtils";
24
- import { addOpacity } from "../../../util/colorUtils";
23
+ import { darken } from "../../../util/colorUtils";
25
24
 
26
25
  const IconWrapper = styled.div`
27
26
  position: absolute;
@@ -58,11 +57,10 @@ const DropdownContentWrapper = styled.div`
58
57
 
59
58
  const DropdownItemWrapper = styled.li`
60
59
  text-align: start;
61
- background: ${({ selected, themeValues }) =>
62
- selected ? themeValues.selectedColor : WHITE};
63
60
  border-width: 2px;
64
61
  border-style: solid;
65
- border-color: transparent;
62
+ border-color: ${({ selected, themeValues }) =>
63
+ selected ? themeValues.selectedColor : WHITE};
66
64
  box-shadow: none;
67
65
  box-sizing: border-box;
68
66
  width: 100%;
@@ -70,35 +68,34 @@ const DropdownItemWrapper = styled.li`
70
68
  cursor: ${({ disabled }) => (disabled ? "default" : "pointer")};
71
69
 
72
70
  &:hover {
73
- background: ${({ selected, disabled, themeValues }) =>
71
+ border-color: ${({ disabled, selected, themeValues }) =>
74
72
  selected
75
- ? addOpacity(themeValues.selectedColor, 0.2, 0, 0, 0)
73
+ ? darken(themeValues.selectedColor, 0.2)
76
74
  : disabled
77
75
  ? WHITE
78
76
  : themeValues.hoverColor};
79
77
  > * {
80
78
  background: ${({ selected, disabled, themeValues }) =>
81
79
  selected
82
- ? addOpacity(themeValues.selectedColor, 0.2, 0, 0, 0)
80
+ ? darken(themeValues.selectedColor, 0.2)
83
81
  : disabled
84
82
  ? WHITE
85
83
  : themeValues.hoverColor};
86
- border-color: ${({ selected, themeValues }) =>
84
+ border-color: ${({ selected, disabled, themeValues }) =>
87
85
  selected
88
- ? TRANSPARENT
86
+ ? darken(themeValues.selectedColor, 0.2)
87
+ : disabled
88
+ ? WHITE
89
89
  : themeValues.hoverColor};
90
90
  }
91
91
  }
92
92
  &:focus {
93
93
  outline: none;
94
- background: ${({ selected, themeValues }) =>
95
- selected ? addOpacity(themeValues.selectedColor, 0.2, 0, 0, 0) : ""};
96
- border-color: ${({ selected, themeValues }) =>
97
- selected ? TRANSPARENT : themeValues.selectedColor};
94
+ border-color: ${({ themeValues }) => themeValues.selectedColor};
98
95
  > * {
99
96
  background: ${({ selected, disabled, themeValues }) =>
100
97
  selected
101
- ? addOpacity(themeValues.selectedColor, 0.2, 0, 0, 0)
98
+ ? darken(themeValues.selectedColor, 0.2)
102
99
  : disabled
103
100
  ? WHITE
104
101
  : themeValues.hoverColor};
@@ -1,13 +1,4 @@
1
- /*
2
-
3
- A utility function that can generate box-shadow values for components
4
- Takes a string representing an rgb color value and returns an object
5
- with values for standard, inset, and overlay shadows.
6
-
7
- The objects for standard and inset shadows contain versions approiate
8
- for base, hover, and active interaction states.
9
-
10
- */
1
+ import { TRANSPARENT } from "../constants/colors";
11
2
 
12
3
  /*
13
4
  Function to convert string representing rgb color to rgba value with provided opacity
@@ -28,6 +19,16 @@ const rgbToRgba = (rgbValue = "", opacity = "") => {
28
19
  )}, ${opacity}${rgbValue.slice(-1)}`;
29
20
  };
30
21
 
22
+ /*
23
+
24
+ A utility function that can generate box-shadow values for components
25
+ Takes a string representing an rgb color value and returns an object
26
+ with values for standard, inset, and overlay shadows.
27
+
28
+ The objects for standard and inset shadows contain versions approiate
29
+ for base, hover, and active interaction states.
30
+
31
+ */
31
32
  export const generateShadows = (baseColorRGB = "rgb(41, 42, 51)") => {
32
33
  const colorTen = rgbToRgba(baseColorRGB, "0.1") || "rgba(41, 42, 51, 0.1)";
33
34
  const colorTwenty = rgbToRgba(baseColorRGB, "0.2") || "rgba(41, 42, 51, 0.2)";
@@ -59,8 +60,53 @@ export const generateShadows = (baseColorRGB = "rgb(41, 42, 51)") => {
59
60
  };
60
61
  };
61
62
 
62
- export const addOpacity = (color, opacity, r, g, b) => {
63
- const rgba = `rgba(${r}, ${g}, ${b}, ${opacity})`;
63
+ /*
64
+ Function to convert a string representing hex color to rgb color
65
+ hexToRbg("#00ff00") => [0, 255, 0]
66
+ */
67
+ const hexToRbg = hexColor => {
68
+ const hexArr = hexColor.replace("#", "");
69
+ const red = parseInt(hexArr.slice(0, 2), 16);
70
+ const green = parseInt(hexArr.slice(2, 4), 16);
71
+ const blue = parseInt(hexArr.slice(4, 6), 16);
72
+
73
+ return [red, green, blue];
74
+ };
75
+
76
+ /*
77
+ Function to calculate a new hex color given an original
78
+ hex color, a hex background color, and an opacity number
79
+ between 0 and 1 to apply to the background.
64
80
 
65
- return `linear-gradient(0deg, ${rgba}, ${rgba}), linear-gradient(0deg, ${color}, ${color});`;
81
+ For example, to add a 20% black opacity (20% darker) to a green color
82
+ ("#00ff00"):
83
+ addOpacityToHex("00ff00", "#000000", .2) => "rgb(0, 204, 0)"
84
+ */
85
+ const addOpacityToHex = (hexColor, background, opacity) => {
86
+ if (hexColor == TRANSPARENT) {
87
+ return hexColor;
88
+ }
89
+
90
+ const color = hexToRbg(hexColor);
91
+ const backgroundRbg = hexToRbg(background);
92
+ const newColor = color.map((colorElem, index) =>
93
+ Math.floor(opacity * backgroundRbg[index] + (1 - opacity) * colorElem)
94
+ );
95
+
96
+ return `rgb(${newColor[0]}, ${newColor[1]}, ${newColor[2]})`;
66
97
  };
98
+
99
+ /*
100
+ Functions to lighten or darken a hex color by a certain percent. Under the hood,
101
+ it merges together a black or white opacity color with the original.
102
+
103
+ Lighten a color by 50%
104
+ lighten("#505050", .5) => "rgb(167, 167, 167)"
105
+
106
+ Darken a color by 50%
107
+ darken("#505050", .5) => "rgb(40, 40, 40)"
108
+ */
109
+ export const lighten = (hexColor, opacity) =>
110
+ addOpacityToHex(hexColor, "#ffffff", opacity);
111
+ export const darken = (hexColor, opacity) =>
112
+ addOpacityToHex(hexColor, "#000000", opacity);