Skip to content

Commit

Permalink
fix(colors): alpha channel is now used if rgba is used
Browse files Browse the repository at this point in the history
Previously the alpha channel was ignored and the opacity setting was
used instead. Now the alpha channel will be used if specified.

Closes react-financial#27
  • Loading branch information
markmcdowell committed Sep 11, 2019
1 parent 7b8362a commit 0c3e2d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/charts/src/utils/colors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { colorPresets } from "./colorPresets";

export const colorToRGBA = (inputColor: string, opacity: number = 1) => {
if (inputColor.charAt(0) === "#") {
if (inputColor.startsWith("#")) {
return hexToRGBA(inputColor.trim(), opacity);
}

if (inputColor.indexOf("rgb(") !== -1 || inputColor.indexOf("rgba(") !== -1) {
if (inputColor.startsWith("rgba")) {
return inputColor;
}

if (inputColor.startsWith("rgb")) {
return rgbToRGBA(inputColor.trim(), opacity);
}

Expand All @@ -31,6 +35,7 @@ export const rgbToRGBA = (inputRGB: string, opacity: number = 1) => {
throw new Error(`invalid inputRGB: ${inputRGB}`);
}
const [, r, g, b] = res;

return `rgba(${r}, ${g}, ${b}, ${opacity})`;
};

Expand Down

0 comments on commit 0c3e2d5

Please sign in to comment.