Skip to content

Commit

Permalink
fixing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonhochkins committed Nov 8, 2023
1 parent fe03c30 commit 2c5fc49
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/components/src/ThemeProvider/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { isObject, isNumber, kebabCase } from "lodash";
import { NAMESPACE } from "./constants";


export function convertToCssVars(obj: object, prefix = "") {
return Object.entries(obj)
.reduce((acc, [key, value]): string => {
const name = `${prefix ? `${prefix}-` : ""}${kebabCase(key)}`;
return `
${acc}
${isObject(value) ? convertToCssVars(value, name) : `--${NAMESPACE}-${name}: ${isNumber(value) ? `${value}` : value};`}
`;
}, "")
.replace(/^\s*[\r\n]/gm, "");
}

0 comments on commit 2c5fc49

Please sign in to comment.