pianello-api/resources/js/colors.js
Ale Gallo 82f958e5da Committing laravel (part 3)
committing js templating files and components
2023-11-10 16:00:59 +01:00

24 lines
766 B
JavaScript

import helper from "./helper";
import resolveConfig from "tailwindcss/resolveConfig";
import tailwindConfig from "tailwind-config";
import flatten from "flat";
const twConfig = resolveConfig(tailwindConfig);
const colors = twConfig.theme?.colors;
function getColor(colorKey, opacity = 1) {
const flattenColors = flatten(colors);
if (flattenColors[colorKey].search("var") === -1) {
return `rgb(${helper.toRGB(flattenColors[colorKey])} / ${opacity})`;
} else {
const cssVariableName = `--color-${
flattenColors[colorKey].split("--color-")[1].split(")")[0]
}`;
return `rgb(${getComputedStyle(document.body).getPropertyValue(
cssVariableName
)} / ${opacity})`;
}
}
export { getColor };