Skip to content

Commit 7ca11b3

Browse files
authored
refactor: typing css custom properties (#873)
* refactor: typing css custom properties starting with the colors * Update index.ts
1 parent 5f8e5eb commit 7ca11b3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/utils/outputs/download.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { getFontFaces } from "./web/fonts.ts";
2121
import { kebabCase } from "../index.ts";
2222
import {
2323
getCssPropertyAsString,
24+
getTypedCssPropertyAsString,
2425
getCssThemeProperties,
2526
getFullColorCss,
2627
getPaletteOutput,
@@ -119,9 +120,9 @@ export const downloadTheme = async (
119120

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

122-
const colorsPalette = getCssPropertyAsString(
123+
const colorsPalette = getTypedCssPropertyAsString(
123124
getPaletteOutput(allColors, luminanceSteps),
124-
true,
125+
"color",
125126
);
126127
const colorSpeakingNames = getCssPropertyAsString(
127128
getSpeakingNames(speakingNames, allColors),
@@ -139,9 +140,9 @@ export const downloadTheme = async (
139140
if (theme.customColors) {
140141
const customColorsFolder: string = "Custom Colors";
141142

142-
const customColorsPalette = getCssPropertyAsString(
143+
const customColorsPalette = getTypedCssPropertyAsString(
143144
getPaletteOutput(theme.customColors, luminanceSteps),
144-
true,
145+
"color",
145146
);
146147

147148
const customColorsSpeakingNames = getCssPropertyAsString(

src/utils/outputs/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ export const getCssPropertyAsString = (
2626
return resultString;
2727
};
2828

29+
export const getTypedCssPropertyAsString = (
30+
properties: any,
31+
type: string,
32+
): string => {
33+
let resultString = "";
34+
35+
for (const [key, value] of Object.entries(properties)) {
36+
resultString += `@property ${key} { syntax: "<${type}>"; initial-value: ${value}; inherits: true; }\n`;
37+
}
38+
39+
return resultString;
40+
};
41+
2942
const nonRemProperties = ["opacity", "elevation", "transition", "font"];
3043

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

0 commit comments

Comments
 (0)