Skip to content

Commit 9d4b4ed

Browse files
committed
fix: style panel not detecting applied text color (shows "None")
1 parent ad24e03 commit 9d4b4ed

File tree

2 files changed

+17
-2
lines changed
  • apps/studio/src/routes/editor/EditPanel/StylesTab/single/ColorInput
  • packages/utility/src

2 files changed

+17
-2
lines changed

apps/studio/src/routes/editor/EditPanel/StylesTab/single/ColorInput/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { invokeMainChannel } from '@/lib/utils';
44
import type { ColorItem } from '@/routes/editor/LayersPanel/BrandTab/ColorPanel/ColorPalletGroup';
55
import { DEFAULT_COLOR_NAME, MainChannels } from '@onlook/models/constants';
66
import { Icons } from '@onlook/ui/icons';
7-
import { Color, isColorEmpty } from '@onlook/utility';
7+
import { Color, isColorEmpty, resolveCssVariables } from '@onlook/utility';
88
import { observer } from 'mobx-react-lite';
99
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
1010
import { BrandPopoverPicker } from './ColorBrandPicker';
@@ -98,12 +98,17 @@ const ColorInput = observer(
9898
}
9999
const newValue = elementStyle.getValue(editorEngine.style.selectedStyle?.styles);
100100

101+
const resolvedValue = resolveCssVariables(
102+
newValue,
103+
editorEngine.style.selectedStyle.styles,
104+
);
105+
101106
const color = editorEngine.theme.getColorByName(newValue);
102107
if (color) {
103108
return Color.from(color);
104109
}
105110

106-
return Color.from(newValue);
111+
return Color.from(resolvedValue);
107112
}, [editorEngine.style.selectedStyle?.styles, elementStyle, isFocused, editorEngine.theme]);
108113

109114
// Update color state when getColor changes

packages/utility/src/color.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,13 @@ function rgb2hsv({ r, g, b }: { r: number; g: number; b: number }): {
337337
const h = c && (v === r ? (g - b) / c : v === g ? 2 + (b - r) / c : 4 + (r - g) / c);
338338
return { h: (h < 0 ? h + 6 : h) / 6, s: v && c / v, v };
339339
}
340+
341+
export function resolveCssVariables(
342+
valueWithVars: string,
343+
styleRecord: Record<string, string>,
344+
fallback = '1',
345+
): string {
346+
return valueWithVars.replace(/var\((--[^)]+)\)/g, (_, varName: string) => {
347+
return styleRecord[varName] ?? fallback;
348+
});
349+
}

0 commit comments

Comments
 (0)