diff --git a/gui/src/components/TabBar/TabBar.tsx b/gui/src/components/TabBar/TabBar.tsx index 2fe905674..be8c53213 100644 --- a/gui/src/components/TabBar/TabBar.tsx +++ b/gui/src/components/TabBar/TabBar.tsx @@ -22,8 +22,8 @@ const tabBackgroundVar = varWithFallback("background"); // --vscode-tab-inactive const tabForegroundVar = varWithFallback("foreground"); // --vscode-tab-inactiveForeground const tabHoverBackgroundVar = varWithFallback("list-hover"); // --vscode-tab-hoverBackground const tabHoverForegroundVar = varWithFallback("foreground"); // --vscode-tab-hoverForeground -const tabSelectedBackgroundVar = varWithFallback("list-hover"); // --vscode-tab-activeBackground -const tabSelectedForegroundVar = varWithFallback("list-active-foreground"); // --vscode-tab-activeForeground +const tabSelectedBackgroundVar = varWithFallback("background"); // --vscode-tab-activeBackground +const tabSelectedForegroundVar = varWithFallback("foreground"); // --vscode-tab-activeForeground const tabAccentVar = varWithFallback("accent"); // --vscode-tab-activeBorderTop const TabBarContainer = styled.div` diff --git a/gui/src/index.css b/gui/src/index.css index 34d0d004f..68f8861f2 100644 --- a/gui/src/index.css +++ b/gui/src/index.css @@ -25,7 +25,7 @@ body, #root { height: 100%; line-height: 1.3; - background-color: var(--vscode-sideBar-background); + /* background-color: var(--vscode-sideBar-background); */ font-family: system-ui, -apple-system, @@ -42,7 +42,7 @@ body, body { padding: 0; - color: var(--vscode-sideBar-foreground); + /* color: var(--vscode-sideBar-foreground); */ padding: 0px; margin: 0px; height: 100%; diff --git a/gui/src/styles/ThemePage.tsx b/gui/src/styles/ThemePage.tsx index a5439a94a..564155bfe 100644 --- a/gui/src/styles/ThemePage.tsx +++ b/gui/src/styles/ThemePage.tsx @@ -8,35 +8,39 @@ import { useNavigate } from "react-router-dom"; import { Button } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { isJetBrains } from "../util"; +import { ROUTES } from "../util/navigation"; import { clearThemeLocalCache, setDocumentStylesFromTheme, THEME_COLORS, + varWithFallback, } from "./theme"; const ThemeTailwindClassExample = ({ - className, - varName, + colorName, + varNames, defaultColor, isMissing, }: { - className: string; - varName: string; + colorName: string; + varNames: string[]; defaultColor: string; isMissing?: boolean; }) => { return ( <>
- {className} + {colorName}
- {varName} + {varNames.join(", ")}
{ const missingVars: string[] = []; Object.entries(THEME_COLORS).forEach(([colorName, themeVals]) => { - const value = getComputedStyle(document.documentElement).getPropertyValue( - themeVals.var, - ); - if (!value) { - missingVars.push(`${colorName}`); //: ${themeVals.var}`); + let found = false; + themeVals.vars.forEach((cssVar) => { + const value = getComputedStyle( + document.documentElement, + ).getPropertyValue(cssVar); + if (value) { + found = true; + } + }); + if (!found) { + missingVars.push(colorName); } }); setMissingVars(missingVars); @@ -88,7 +98,7 @@ function ThemePage() {
navigate("/more")} + onClick={() => navigate(ROUTES.HOME)} > ← Back to Settings @@ -117,7 +127,7 @@ function ThemePage() {
@@ -125,30 +135,49 @@ function ThemePage() { Badge
-
-
- - Success -
-
- - Warning -
-
- - Error -
+
+ + Success +
+
+ + Warning +
+
+ + Error
setListToggled(!listToggled)} className={`cursor-pointer p-2 ${listToggled ? "bg-list-active text-list-active-foreground" : "bg-background text-foreground hover:bg-list-hover"}`} > - List item (click to select) + List item (clickable)
Editor
+ + + + + + + + + +
+ even table row +
+ odd table row +
+
+ Link +
+
+ find match + current match +

@@ -197,9 +226,9 @@ function ThemePage() { ))}

diff --git a/gui/src/styles/theme.ts b/gui/src/styles/theme.ts index bfa24bbda..64238d410 100644 --- a/gui/src/styles/theme.ts +++ b/gui/src/styles/theme.ts @@ -4,146 +4,157 @@ // The current default theme is dark with blue accents export const THEME_COLORS = { background: { - var: "--vscode-sideBar-background", + vars: [ + "--vscode-sideBar-background", + "--vscode-panel-background", + "--vscode-editor-background", + ], default: "#1e1e1e", // dark gray }, foreground: { - var: "--vscode-sideBar-foreground", // --vscode-editor-foreground + vars: [ + "--vscode-sideBar-foreground", + "--vscode-editor-foreground", + "--vscode-panel-foreground", + ], // --vscode-editor-foreground default: "#e6e6e6", // light gray }, "editor-background": { - var: "--vscode-editor-background", + vars: ["--vscode-editor-background"], default: "#1e1e1e", // dark gray }, "editor-foreground": { - var: "--vscode-editor-foreground", + vars: ["--vscode-editor-foreground"], default: "#e6e6e6", // light gray }, "primary-background": { - var: "--vscode-button-background", + vars: ["--vscode-button-background"], default: "#2c5aa0", // medium blue }, "primary-foreground": { - var: "--vscode-button-foreground", + vars: ["--vscode-button-foreground"], default: "#ffffff", // white }, "primary-hover": { - var: "--vscode-button-hoverBackground", + vars: ["--vscode-button-hoverBackground"], default: "#3a6db3", // lighter blue }, "secondary-background": { - var: "--vscode-button-secondaryBackground", + vars: ["--vscode-button-secondaryBackground"], default: "#303030", // medium dark gray }, "secondary-foreground": { - var: "--vscode-button-secondaryForeground", + vars: ["--vscode-button-secondaryForeground"], default: "#e6e6e6", // light gray }, "secondary-hover": { - var: "--vscode-button-secondaryHoverBackground", + vars: ["--vscode-button-secondaryHoverBackground"], default: "#3a3a3a", // medium gray }, border: { - // --vscode-panel-border - var: "--vscode-sideBar-border", + vars: ["--vscode-sideBar-border", "--vscode-panel-border"], default: "#2a2a2a", // dark gray border }, "border-focus": { - var: "--vscode-focusBorder", + vars: ["--vscode-focusBorder"], default: "#3a6db3", // lighter blue }, // Command styles are used for tip-tap editor "command-background": { - var: "--vscode-commandCenter-background", + vars: ["--vscode-commandCenter-background"], default: "#252525", // dark gray }, "command-foreground": { - var: "--vscode-commandCenter-foreground", + vars: ["--vscode-commandCenter-foreground"], default: "#e6e6e6", // light gray }, "command-border": { - var: "--vscode-commandCenter-inactiveBorder", + vars: ["--vscode-commandCenter-inactiveBorder"], default: "#555555", // medium gray }, "command-border-focus": { - var: "--vscode-commandCenter-activeBorder", + vars: ["--vscode-commandCenter-activeBorder"], default: "#4d8bf0", // bright blue }, description: { - var: "--vscode-descriptionForeground", + vars: ["--vscode-descriptionForeground"], default: "#b3b3b3", // medium light gray }, "description-muted": { - var: "--vscode-list-deemphasizedForeground", + vars: ["--vscode-list-deemphasizedForeground"], default: "#8c8c8c", // medium gray }, "input-background": { - var: "--vscode-input-background", + vars: ["--vscode-input-background"], default: "#2d2d2d", // dark gray }, "input-foreground": { - var: "--vscode-input-foreground", + vars: ["--vscode-input-foreground"], default: "#e6e6e6", // light gray }, "input-border": { - var: "--vscode-input-border", + vars: [ + "--vscode-input-border", + "--vscode-commandCenter-inactiveBorder", + "vscode-border", + ], default: "#555555", // medium gray }, "input-placeholder": { - var: "--vscode-input-placeholderForeground", + vars: ["--vscode-input-placeholderForeground"], default: "#9e9e9e", // medium light gray }, "table-oddRow": { - var: "--vscode-tree-tableOddRowsBackground", + vars: ["--vscode-tree-tableOddRowsBackground"], default: "#2d2d2d", // dark gray }, "badge-background": { - var: "--vscode-badge-background", + vars: ["--vscode-badge-background"], default: "#4d4d4d", // medium dark gray }, "badge-foreground": { - var: "--vscode-badge-foreground", + vars: ["--vscode-badge-foreground"], default: "#ffffff", // white }, success: { - var: "--vscode-notebookStatusSuccessIcon-foreground", // "var(--vscode-testing-iconPassed, #1bbe84)" // --vscode-charts-green + vars: ["--vscode-notebookStatusSuccessIcon-foreground"], // "var(--vscode-testing-iconPassed, #1bbe84)" // --vscode-charts-green default: "#4caf50", // green }, warning: { - var: "--vscode-editorWarning-foreground", // --vscode-list-warningForeground + vars: ["--vscode-editorWarning-foreground"], // --vscode-list-warningForeground default: "#ffb74d", // amber/yellow }, error: { - var: "--vscode-editorError-foreground", // --vscode-list-errorForeground + vars: ["--vscode-editorError-foreground"], // --vscode-list-errorForeground default: "#f44336", // red }, link: { - var: "--vscode-textLink-foreground", + vars: ["--vscode-textLink-foreground"], default: "#5c9ce6", // medium blue }, accent: { - var: "--vscode-tab-activeBorderTop", + vars: ["--vscode-tab-activeBorderTop", "--vscode-focusBorder"], default: "#4d8bf0", // bright blue }, "find-match": { - var: "--vscode-editor-findMatchBackground", // Can't get "var(--vscode-editor-findMatchBackground, rgba(237, 18, 146, 0.5))" to work + vars: ["--vscode-editor-findMatchBackground"], // Can't get "var(--vscode-editor-findMatchBackground, rgba(237, 18, 146, 0.5))" to work default: "#264f7840", // translucent blue }, "find-match-selected": { - var: "--vscode-editor-findMatchHighlightBackground", + vars: ["--vscode-editor-findMatchHighlightBackground"], default: "#ffb74d40", // translucent amber }, "list-hover": { // --vscode-tab-hoverBackground - var: "--vscode-list-hoverBackground", + vars: ["--vscode-list-hoverBackground"], default: "#383838", // medium dark gray }, "list-active": { - var: "--vscode-list-activeSelectionBackground", + vars: ["--vscode-list-activeSelectionBackground"], default: "#2c5aa050", // translucent medium blue }, "list-active-foreground": { - var: "--vscode-list-activeSelectionForeground", + vars: ["--vscode-list-activeSelectionForeground"], default: "#ffffff", // white }, }; @@ -151,14 +162,15 @@ export const THEME_COLORS = { // TODO: add fonts - GUI fonts in jetbrains differ from IDE: // --vscode-editor-font-family; // --vscode-font-family; - -export const THEME_CSS_VARS = Object.values(THEME_COLORS).map( - (value) => value.var, -); +export const THEME_CSS_VARS = Object.values(THEME_COLORS) + .map((value) => value.vars) + .flat(); export const THEME_CSS_VAR_DEFAULTS = Object.entries(THEME_COLORS).reduce( (acc, [_, value]) => { - acc[value.var] = value.default; + value.vars.forEach((varName) => { + acc[varName] = value.default; + }); return acc; }, {} as Record, @@ -172,8 +184,12 @@ export const THEME_DEFAULTS = Object.entries(THEME_COLORS).reduce( {} as Record, ); -export const varWithFallback = (className: keyof typeof THEME_COLORS) => - `var(${THEME_COLORS[className].var}, ${THEME_COLORS[className].default})`; +// Generates recursive CSS variable fallback for a given color name +// e.g. var(--vscode-button-background, var(--vscode-button-foreground, #ffffff)) +export const varWithFallback = (colorName: keyof typeof THEME_COLORS) => + THEME_COLORS[colorName].vars.reduce((curr, varName) => { + return `var(${varName}, ${curr})`; + }, THEME_COLORS[colorName].default); export const setDocumentStylesFromTheme = ( theme: Record, @@ -191,47 +207,46 @@ export const setDocumentStylesFromTheme = ( // Write each theme color to the document Object.entries(theme).forEach(([colorName, value]) => { if (value) { - const cssVarName = - THEME_COLORS[colorName as keyof typeof THEME_COLORS]?.var; - // TODO VALUE WITHOUT ALPHA CHANNEL - document.body.style.setProperty(cssVarName, value); - document.documentElement.style.setProperty(cssVarName, value); - localStorage.setItem(colorName, value); + const themeVals = THEME_COLORS[colorName as keyof typeof THEME_COLORS]; + if (!themeVals) { + console.warn( + `Receieved theme color ${colorName} which is not used by the theme`, + ); + return; + } + + // Remove alpha channel from all hex colors besides ones that are expected to have it + let colorVal = value; + if ( + !colorName.includes("find-match") && + colorVal.startsWith("#") && + value.length > 7 + ) { + colorVal = colorVal.slice(0, 7); + } + + localStorage.setItem(colorName, colorVal); + for (const cssVar of themeVals.vars) { + document.body.style.setProperty(cssVar, colorVal); + document.documentElement.style.setProperty(cssVar, colorVal); + } } else { console.warn( `Theme color ${colorName} is undefined or null. Please check theme. Falling back to defaults.`, ); } }); - - // Cache values in local storage - for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) { - const currentVal = document.body.style.getPropertyValue(themeVals.var); - if (currentVal) { - localStorage.setItem(colorName, currentVal); - } - } }; export const setDocumentStylesFromLocalStorage = (checkCache: boolean) => { for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) { - const cssVarName = themeVals.var; - - // Get cached values (for non-vscode IDEs) - if (checkCache) { - const cached = localStorage.getItem(colorName); - if (cached) { - document.body.style.setProperty(cssVarName, cached); - } - } - - // Remove alpha channel from all hex colors besides ones that are expected to have it - if (!colorName.includes("find-match")) { - const value = getComputedStyle(document.documentElement).getPropertyValue( - cssVarName, - ); - if (value.startsWith("#") && value.length > 7) { - document.body.style.setProperty(cssVarName, value.slice(0, 7)); + for (const cssVar of themeVals.vars) { + // Get cached values (for non-vscode IDEs) + if (checkCache) { + const cached = localStorage.getItem(colorName); + if (cached) { + document.body.style.setProperty(cssVar, cached); + } } } }