Skip to content

Commit fc642e1

Browse files
authored
Merge pull request #227 from dxc-technology/rarrojolopez-fix-cdk
[Patch] Avoid error when color is not hexadecimal
2 parents 14fffff + 0b0264c commit fc642e1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/src/ThemeContext.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ import { componentTokens } from "./common/variables.js";
88
const ThemeContext = React.createContext();
99

1010
const setLightness = (hexColor, newLightness) => {
11-
if (hexColor) {
12-
const color = Color(hexColor);
13-
const hslColor = color.hsl();
14-
const lightnessColor = hslColor.color[2];
15-
return hslColor.lightness(lightnessColor + newLightness).hex();
11+
try {
12+
if (hexColor) {
13+
const color = Color(hexColor);
14+
const hslColor = color.hsl();
15+
const lightnessColor = hslColor.color[2];
16+
return hslColor.lightness(lightnessColor + newLightness).hex();
17+
}
18+
} catch (e) {
19+
return null;
1620
}
17-
return null;
1821
};
1922

2023
const setOpacity = (hexColor, newOpacity) => {
21-
if (hexColor) {
22-
const color = Color(hexColor);
23-
return "#" + rgbHex(color.color[0], color.color[1], color.color[2], newOpacity);
24+
try {
25+
if (hexColor) {
26+
const color = Color(hexColor);
27+
return "#" + rgbHex(color.color[0], color.color[1], color.color[2], newOpacity);
28+
}
29+
} catch (e) {
30+
return null;
2431
}
25-
return null;
2632
};
2733

2834
const parseTheme = (theme) => {

0 commit comments

Comments
 (0)