Skip to content

Commit 2467575

Browse files
committed
fix(theme): replace hardcoded hex colors with CSS variables and apply theme settings at runtime
- Replace #141415 with var(--cortex-bg-primary) across layout components - Replace #1C1C1D with var(--cortex-bg-secondary) across layout components - Replace #2E2F31 with var(--cortex-border-default) across layout components - Replace hardcoded icon/text colors with semantic CSS variables - Add createEffect in AppCore to apply uiFontFamily, uiFontSize, and zoomLevel from SettingsContext to document.documentElement.style - Update tests to match new CSS variable output Closes #21896, #21897
1 parent a684f27 commit 2467575

File tree

9 files changed

+33
-23
lines changed

9 files changed

+33
-23
lines changed

src/AppCore.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useLayout } from "@/context/LayoutContext";
3737
import { useSettings } from "@/context/SettingsContext";
3838
import { useNotifications } from "@/context/NotificationsContext";
3939
import { useOutput } from "@/context/OutputContext";
40+
import { useSettings } from "@/context/SettingsContext";
4041
import { useWindowEvents } from "@/hooks/useWindowEvents";
4142
import { useAutoSave } from "@/hooks/useAutoSave";
4243
import { initGlobalErrorHandler } from "@/lib/error-handler";
@@ -281,7 +282,7 @@ function AppContent(props: ParentProps) {
281282
const layout = useLayout();
282283
const notifications = useNotifications();
283284
const output = useOutput();
284-
const settingsCtx = useSettings();
285+
const { settings } = useSettings();
285286

286287
// Window lifecycle events (close-requested with dirty file prompt, focus/blur,
287288
// beforeunload, visibilitychange, force-close cleanup)
@@ -290,12 +291,21 @@ function AppContent(props: ParentProps) {
290291
// Auto-save dirty files based on user settings (afterDelay, onFocusChange, onWindowChange)
291292
useAutoSave();
292293

294+
// Apply theme settings (font family, font size, zoom) to document root
293295
createEffect(() => {
294-
const theme = settingsCtx.settings().theme;
295-
const root = document.documentElement.style;
296-
root.setProperty("font-family", theme.uiFontFamily);
297-
root.setProperty("font-size", `${theme.uiFontSize}px`);
298-
root.setProperty("zoom", String(theme.zoomLevel));
296+
const theme = settings().theme;
297+
const docStyle = document.documentElement.style;
298+
if (theme.uiFontFamily) {
299+
docStyle.setProperty("font-family", theme.uiFontFamily);
300+
}
301+
if (theme.uiFontSize) {
302+
docStyle.setProperty("font-size", `${theme.uiFontSize}px`);
303+
}
304+
if (theme.zoomLevel && theme.zoomLevel !== 1) {
305+
docStyle.setProperty("zoom", String(theme.zoomLevel));
306+
} else {
307+
docStyle.removeProperty("zoom");
308+
}
299309
});
300310

301311
// Global error handler (unhandled rejections, uncaught errors)

src/components/cortex/CortexActivityBar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ const ActivityBarButton: Component<ActivityBarButtonProps> = (props) => {
134134
const [isHovered, setIsHovered] = createSignal(false);
135135

136136
const bg = () => {
137-
if (props.isActive) return "#BFFF00";
137+
if (props.isActive) return "var(--cortex-accent-primary)";
138138
if (isHovered()) return "var(--cortex-sidebar-selected)";
139139
return "transparent";
140140
};
141141

142142
const iconColor = () => {
143143
if (props.isActive) return "var(--cortex-icon-active)";
144-
if (isHovered()) return "#FCFCFC";
145-
return "#8C8D8F";
144+
if (isHovered()) return "var(--cortex-text-primary)";
145+
return "var(--cortex-icon-inactive)";
146146
};
147147

148148
return (
@@ -186,7 +186,7 @@ const ActivityBarButton: Component<ActivityBarButtonProps> = (props) => {
186186
"align-items": "center",
187187
"justify-content": "center",
188188
padding: "0 var(--cortex-space-1)",
189-
background: "#BFFF00",
189+
background: "var(--cortex-accent-primary)",
190190
color: "var(--cortex-icon-active)",
191191
"font-family": "var(--cortex-font-sans)",
192192
"font-size": "9px",

src/components/cortex/CortexCodeEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const EditorPlaceholder: Component = () => {
173173
"align-items": "center",
174174
"justify-content": "center",
175175
background: "var(--cortex-bg-primary)",
176-
color: "#8C8D8F",
176+
color: "var(--cortex-text-secondary)",
177177
gap: "16px",
178178
});
179179

src/components/cortex/__tests__/CortexFileExplorer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ describe("CortexFileExplorer", () => {
299299
expect(div?.style.borderRadius).toBe("16px");
300300
});
301301

302-
it("should have correct background color var(--cortex-bg-primary)", () => {
302+
it("should use cortex-bg-primary CSS variable for background", () => {
303303
const { container } = render(() => <CortexFileExplorer />);
304304
const div = container.firstChild as HTMLElement;
305305
const bg = div?.style.background;
306-
expect(bg === "var(--cortex-bg-primary)" || bg === "#141415" || bg === "rgb(20, 20, 21)").toBe(true);
306+
expect(bg).toContain("var(--cortex-bg-primary)");
307307
});
308308
});
309309
});

src/components/cortex/primitives/CortexHeaderItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const CortexHeaderItem: Component<CortexHeaderItemProps> = (props) => {
4141
padding: "8px 10px",
4242
gap: "10px",
4343
border: "none",
44-
background: isHighlighted() ? "#1C1C1D" : "transparent",
44+
background: isHighlighted() ? "var(--cortex-bg-secondary)" : "transparent",
4545
"border-radius": isHighlighted() ? "8px" : "0",
4646
color: isHighlighted() ? "#FCFCFC" : "#8C8D8F",
4747
"font-family": "'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",

src/components/cortex/primitives/CortexSeparator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const CortexSeparator: Component<CortexSeparatorProps> = (props) => {
2828
const lineStyle = (): JSX.CSSProperties => ({
2929
width: "100%",
3030
height: "0",
31-
"border-bottom": "1px solid #2E2F31",
31+
"border-bottom": "1px solid var(--cortex-border-default)",
3232
});
3333

3434
return (

src/components/cortex/titlebar/TitleBarDropdownMenu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ const DropdownMenuItem: Component<{ item: MenuItem; onClick: () => void }> = (pr
7979
"justify-content": "space-between",
8080
gap: "8px",
8181
padding: "4px 8px",
82-
background: hovered() ? "#252628" : "transparent",
82+
background: hovered() ? "var(--cortex-bg-hover)" : "transparent",
8383
border: "none",
8484
cursor: "pointer",
8585
"font-family": "'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
8686
"font-size": "12px",
8787
"font-weight": "400",
8888
"line-height": "1.167em",
89-
color: "#FCFCFC",
89+
color: "var(--cortex-text-primary)",
9090
"text-align": "left",
9191
"border-radius": hovered() ? "4px" : "0",
9292
"box-sizing": "border-box",
@@ -102,7 +102,7 @@ const DropdownMenuItem: Component<{ item: MenuItem; onClick: () => void }> = (pr
102102
<span>{props.item.label}</span>
103103
<Show when={props.item.shortcut}>
104104
<span style={{
105-
color: "#8C8D8F",
105+
color: "var(--cortex-text-secondary)",
106106
"font-family": "'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
107107
"font-size": "12px",
108108
"font-weight": "400",

src/components/cortex/titlebar/__tests__/TitleBarDropdownMenu.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("TitleBarDropdownMenu", () => {
9797
const dropdown = container.firstElementChild as HTMLElement;
9898
const style = dropdown.getAttribute("style") || "";
9999
expect(style).toContain("min-width:243px");
100-
expect(style).toMatch(/(var\(--cortex-bg-secondary\)|#1C1C1D|rgb\(28,\s*28,\s*29\))/i);
100+
expect(style).toContain("var(--cortex-bg-secondary)");
101101
expect(style).toContain("border-radius:8px");
102102
expect(style).toContain("z-index:9999");
103103
});
@@ -186,7 +186,7 @@ describe("TitleBarDropdownMenu", () => {
186186
expect(button.style.background).toBe("transparent");
187187

188188
await fireEvent.mouseEnter(button);
189-
expect(button.style.background).toMatch(/rgb\(37,\s*38,\s*40\)|#252628/i);
189+
expect(button.style.background).toContain("var(--cortex-bg-hover)");
190190

191191
await fireEvent.mouseLeave(button);
192192
expect(button.style.background).toBe("transparent");

src/components/layout/ActivityBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ const ActivityBarButton: Component<{
112112
};
113113

114114
const color = () => {
115-
if (props.isActive) return "#141415";
116-
if (hovered()) return "#FCFCFC";
117-
return "#8C8D8F";
115+
if (props.isActive) return "var(--cortex-icon-active)";
116+
if (hovered()) return "var(--cortex-text-primary)";
117+
return "var(--cortex-icon-inactive)";
118118
};
119119

120120
return (

0 commit comments

Comments
 (0)