Skip to content

Commit

Permalink
chore(tokens): update transparent color function
Browse files Browse the repository at this point in the history
  • Loading branch information
mainframev committed Nov 23, 2023
1 parent d364d3d commit ef34b2c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/orbit-design-tokens/src/js/transparentColor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { parseToRgba, rgba, guard } from "color2k";

const isHex = (color: string): boolean => color.startsWith("#");
const isRgb = (color: string): boolean => color.startsWith("rgb");

const transparentColor = (color: string, opacity: number): string => {
// tailwind package is using css variables
if (color.match(/var\(/)) {
const regex = /var\(([^,]+),\s*([^)]+)\)/;
const [, , colorValue] = color.match(regex);
return transparentColor(colorValue, opacity);
const value = colorValue as string;
const isValidColor = isHex(value) || isRgb(value);
return transparentColor(isValidColor ? value : `rgb(${value})`, opacity);
}

const [R, G, B] = parseToRgba(color);
Expand Down

0 comments on commit ef34b2c

Please sign in to comment.