Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit b8a5d20

Browse files
fix: fix lint errors in utils (#699)
* fix: fix lint errors in utils * refactor: cleaned up type in jsoncolor
1 parent 5f6674d commit b8a5d20

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

docs/utils/getCSSVariablesFromStylesheet.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ export const getCSSVariablesFromStylesheet = (varPrefix: string): Color => {
2222
// Access rules from the stylesheet, handle security errors when accessing cross-origin stylesheets
2323
return Array.from(styleSheet.cssRules);
2424
} catch (err) {
25-
console.error(
26-
'Access denied to stylesheet: ',
27-
styleSheet.href,
28-
'; Error: ',
29-
err.message,
30-
);
25+
if (err instanceof Error) {
26+
console.error(
27+
'Access denied to stylesheet: ',
28+
styleSheet.href,
29+
'; Error: ',
30+
err.message,
31+
);
32+
} else {
33+
console.error(
34+
'Access denied to stylesheet: ',
35+
styleSheet.href,
36+
'; Unknown error occurred.',
37+
);
38+
}
3139
return [];
3240
}
3341
})
@@ -47,7 +55,7 @@ export const getCSSVariablesFromStylesheet = (varPrefix: string): Color => {
4755
// Iterate over each property in the style rule
4856
for (let i = 0; i < style.length; i++) {
4957
const varName = style[i];
50-
if (varName.startsWith(varPrefix)) {
58+
if (varName?.startsWith(varPrefix)) {
5159
// Get the actual CSS variable value from the computed styles of the document's root element
5260
const value = getComputedStyle(document.documentElement)
5361
.getPropertyValue(varName)

docs/utils/useJsonColor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,23 @@ export const useJsonColor = (): CompiledColors => {
6868
}): CompiledColors => {
6969
const compiledColors: CompiledColors = {};
7070
Object.entries(themes).forEach(([themeName, theme]) => {
71-
compiledColors[themeName] = {};
71+
const tempThemeColors: Theme = {};
7272
Object.entries(theme).forEach(([colorName, colorValues]) => {
73-
compiledColors[themeName][colorName] = {};
73+
const tempThemeColorPalette: ColorPalette = {};
7474
Object.entries(colorValues).forEach(([shade, details]) => {
7575
const { value, description } = details;
7676
const resolvedValue = parseColorValue(value, figmaBrandColors);
77-
compiledColors[themeName][colorName][shade] = {
77+
const tempShadeColor = {
7878
...details,
7979
value: resolvedValue,
8080
description:
8181
description + (value === resolvedValue ? '' : ` ${value}`),
8282
};
83+
tempThemeColorPalette[shade] = tempShadeColor;
8384
});
85+
tempThemeColors[colorName] = tempThemeColorPalette;
8486
});
87+
compiledColors[themeName] = tempThemeColors;
8588
});
8689
return compiledColors;
8790
};

0 commit comments

Comments
 (0)