Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/src/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ import { componentTokens } from "./common/variables.js";
const ThemeContext = React.createContext();

const setLightness = (hexColor, newLightness) => {
if (hexColor) {
const color = Color(hexColor);
const hslColor = color.hsl();
const lightnessColor = hslColor.color[2];
return hslColor.lightness(lightnessColor + newLightness).hex();
try {
if (hexColor) {
const color = Color(hexColor);
const hslColor = color.hsl();
const lightnessColor = hslColor.color[2];
return hslColor.lightness(lightnessColor + newLightness).hex();
}
} catch (e) {
return null;
}
return null;
};

const setOpacity = (hexColor, newOpacity) => {
if (hexColor) {
const color = Color(hexColor);
return "#" + rgbHex(color.color[0], color.color[1], color.color[2], newOpacity);
try {
if (hexColor) {
const color = Color(hexColor);
return "#" + rgbHex(color.color[0], color.color[1], color.color[2], newOpacity);
}
} catch (e) {
return null;
}
return null;
};

const parseTheme = (theme) => {
Expand Down