Skip to content

Commit

Permalink
refactor: typing css custom properties (#873)
Browse files Browse the repository at this point in the history
* refactor: typing css custom properties

starting with the colors

* Update index.ts
  • Loading branch information
mfranzke authored Sep 16, 2024
1 parent 5f8e5eb commit 7ca11b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/outputs/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getFontFaces } from "./web/fonts.ts";
import { kebabCase } from "../index.ts";
import {
getCssPropertyAsString,
getTypedCssPropertyAsString,
getCssThemeProperties,
getFullColorCss,
getPaletteOutput,
Expand Down Expand Up @@ -119,9 +120,9 @@ export const downloadTheme = async (

zip.file(`${webFolder}/${fileName}-theme.css`, themeProperties);

const colorsPalette = getCssPropertyAsString(
const colorsPalette = getTypedCssPropertyAsString(
getPaletteOutput(allColors, luminanceSteps),
true,
"color",
);
const colorSpeakingNames = getCssPropertyAsString(
getSpeakingNames(speakingNames, allColors),
Expand All @@ -139,9 +140,9 @@ export const downloadTheme = async (
if (theme.customColors) {
const customColorsFolder: string = "Custom Colors";

const customColorsPalette = getCssPropertyAsString(
const customColorsPalette = getTypedCssPropertyAsString(
getPaletteOutput(theme.customColors, luminanceSteps),
true,
"color",
);

const customColorsSpeakingNames = getCssPropertyAsString(
Expand Down
13 changes: 13 additions & 0 deletions src/utils/outputs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export const getCssPropertyAsString = (
return resultString;
};

export const getTypedCssPropertyAsString = (
properties: any,
type: string,
): string => {
let resultString = "";

for (const [key, value] of Object.entries(properties)) {
resultString += `@property ${key} { syntax: "<${type}>"; initial-value: ${value}; inherits: true; }\n`;
}

return resultString;
};

const nonRemProperties = ["opacity", "elevation", "transition", "font"];

const isFontFamily = (path: string[]): boolean =>
Expand Down

0 comments on commit 7ca11b3

Please sign in to comment.