From 2c5fc49e218ff1ff28c4823c6a1b50aeb33c3ddb Mon Sep 17 00:00:00 2001 From: Shannon Hochkins Date: Wed, 8 Nov 2023 15:23:52 +1100 Subject: [PATCH] fixing helper --- packages/components/src/ThemeProvider/helpers.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/components/src/ThemeProvider/helpers.ts diff --git a/packages/components/src/ThemeProvider/helpers.ts b/packages/components/src/ThemeProvider/helpers.ts new file mode 100644 index 00000000..657e2ab8 --- /dev/null +++ b/packages/components/src/ThemeProvider/helpers.ts @@ -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, ""); +} +