Skip to content

feat: add light theme #11266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix the editor
  • Loading branch information
aslilac committed Dec 18, 2023
commit d86c20e8049cac6f2abdb56a5e3639b1edf8b604
11 changes: 4 additions & 7 deletions site/src/pages/TemplateVersionEditorPage/FileTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
}

&.Mui-selected {
color: ${theme.palette.text.primary};
background: ${theme.colors.gray[14]};
color: ${theme.experimental.roles.active.text};
background: ${theme.experimental.roles.active.background};
}

&.Mui-focused {
Expand Down Expand Up @@ -133,16 +133,13 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
} as CSSProperties
}
>
{isFolder ? (
{isFolder &&
Object.keys(content)
.sort(sortFileTree(content))
.map((filename) => {
const child = content[filename];
return buildTreeItems(filename, child, currentPath);
})
) : (
<></>
)}
})}
</TreeItem>
);
};
Expand Down
76 changes: 25 additions & 51 deletions site/src/pages/TemplateVersionEditorPage/MonacoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { useTheme } from "@emotion/react";
import Editor, { loader } from "@monaco-editor/react";
import * as monaco from "monaco-editor";
import { FC, useMemo } from "react";
import { type FC, useEffect, useMemo } from "react";
import { MONOSPACE_FONT_FAMILY } from "theme/constants";

loader.config({ monaco });

export const MonacoEditor: FC<{
interface MonacoEditorProps {
value?: string;
path?: string;
onChange?: (value: string) => void;
}> = ({ onChange, value, path }) => {
}

export const MonacoEditor: FC<MonacoEditorProps> = ({
onChange,
value,
path,
}) => {
const theme = useTheme();

const language = useMemo(() => {
Expand All @@ -31,6 +37,20 @@ export const MonacoEditor: FC<{
}
}, [path]);

useEffect(() => {
document.fonts.ready
.then(() => {
// Ensures that all text is measured properly.
// If this isn't done, there can be weird selection issues.
monaco.editor.remeasureFonts();
})
.catch(() => {
// Not a biggie!
});

monaco.editor.defineTheme("min", theme.monaco);
}, [theme]);

return (
<Editor
value={value}
Expand All @@ -52,62 +72,16 @@ export const MonacoEditor: FC<{
onChange(newValue);
}
}}
onMount={(editor, monaco) => {
onMount={(editor) => {
// This jank allows for Ctrl + Enter to work outside the editor.
// We use this keybind to trigger a build.
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Private type in Monaco!
(editor as any)._standaloneKeybindingService.addDynamicKeybinding(
`-editor.action.insertLineAfter`,
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
() => {
//
},
() => {},
);

document.fonts.ready
.then(() => {
// Ensures that all text is measured properly.
// If this isn't done, there can be weird selection issues.
monaco.editor.remeasureFonts();
})
.catch(() => {
// Not a biggie!
});

monaco.editor.defineTheme("min", {
base: "vs-dark",
inherit: true,
rules: [
{
token: "comment",
foreground: "6B737C",
},
{
token: "type",
foreground: "B392F0",
},
{
token: "string",
foreground: "9DB1C5",
},
{
token: "variable",
foreground: "BBBBBB",
},
{
token: "identifier",
foreground: "B392F0",
},
{
token: "delimiter.curly",
foreground: "EBB325",
},
],
colors: {
"editor.foreground": theme.palette.text.primary,
"editor.background": theme.palette.background.paper,
},
});
editor.updateOptions({
theme: "min",
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { chromatic } from "testHelpers/chromatic";
import {
MockFailedProvisionerJob,
MockRunningProvisionerJob,
Expand All @@ -14,19 +16,19 @@ import {
MockWorkspaceVolumeResource,
} from "testHelpers/entities";
import { TemplateVersionEditor } from "./TemplateVersionEditor";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof TemplateVersionEditor> = {
title: "pages/TemplateVersionEditorPage",
title: "pages/TemplateVersionEditor",
parameters: {
chromatic,
layout: "fullscreen",
},
component: TemplateVersionEditor,
args: {
template: MockTemplate,
templateVersion: MockTemplateVersion,
defaultFileTree: MockTemplateVersionFileTree,
},
parameters: {
layout: "fullscreen",
},
};

export default meta;
Expand Down
2 changes: 2 additions & 0 deletions site/src/theme/dark/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import colors from "./colors";
import experimental from "./experimental";
import monaco from "./monaco";
import muiTheme from "./mui";

export default {
...muiTheme,
colors,
experimental,
monaco,
};
37 changes: 37 additions & 0 deletions site/src/theme/dark/monaco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import muiTheme from "./mui";
import type * as monaco from "monaco-editor";

export default {
base: "vs-dark",
inherit: true,
rules: [
{
token: "comment",
foreground: "6B737C",
},
{
token: "type",
foreground: "B392F0",
},
{
token: "string",
foreground: "9DB1C5",
},
{
token: "variable",
foreground: "DDDDDD",
},
{
token: "identifier",
foreground: "B392F0",
},
{
token: "delimiter.curly",
foreground: "EBB325",
},
],
colors: {
"editor.foreground": muiTheme.palette.text.primary,
"editor.background": muiTheme.palette.background.paper,
},
} satisfies monaco.editor.IStandaloneThemeData;
2 changes: 2 additions & 0 deletions site/src/theme/darkBlue/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import colors from "./colors";
import experimental from "./experimental";
import monaco from "./monaco";
import muiTheme from "./mui";

export default {
...muiTheme,
colors,
experimental,
monaco,
};
37 changes: 37 additions & 0 deletions site/src/theme/darkBlue/monaco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import muiTheme from "./mui";
import type * as monaco from "monaco-editor";

export default {
base: "vs-dark",
inherit: true,
rules: [
{
token: "comment",
foreground: "6B737C",
},
{
token: "type",
foreground: "B392F0",
},
{
token: "string",
foreground: "9DB1C5",
},
{
token: "variable",
foreground: "DDDDDD",
},
{
token: "identifier",
foreground: "B392F0",
},
{
token: "delimiter.curly",
foreground: "EBB325",
},
],
colors: {
"editor.foreground": muiTheme.palette.text.primary,
"editor.background": muiTheme.palette.background.paper,
},
} satisfies monaco.editor.IStandaloneThemeData;
2 changes: 2 additions & 0 deletions site/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Theme as MuiTheme } from "@mui/material/styles";
import type * as monaco from "monaco-editor";
import dark from "./dark";
import darkBlue from "./darkBlue";
import light from "./light";
Expand All @@ -8,6 +9,7 @@ import type { Colors } from "./colors";
export interface Theme extends MuiTheme {
colors: Colors;
experimental: NewTheme;
monaco: monaco.editor.IStandaloneThemeData;
}

export const DEFAULT_THEME = "auto";
Expand Down
2 changes: 1 addition & 1 deletion site/src/theme/light/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {
},
},
active: {
background: colors.sky[50],
background: colors.sky[100],
outline: colors.sky[500],
fill: colors.sky[600],
text: colors.sky[950],
Expand Down
2 changes: 2 additions & 0 deletions site/src/theme/light/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import colors from "./colors";
import experimental from "./experimental";
import monaco from "./monaco";
import muiTheme from "./mui";

export default {
...muiTheme,
colors,
experimental,
monaco,
};
37 changes: 37 additions & 0 deletions site/src/theme/light/monaco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import muiTheme from "./mui";
import type * as monaco from "monaco-editor";

export default {
base: "vs",
inherit: true,
rules: [
{
token: "comment",
foreground: "6B737C",
},
{
token: "type",
foreground: "682CD7",
},
{
token: "string",
foreground: "1766B4",
},
{
token: "variable",
foreground: "444444",
},
{
token: "identifier",
foreground: "682CD7",
},
{
token: "delimiter.curly",
foreground: "EBB325",
},
],
colors: {
"editor.foreground": muiTheme.palette.text.primary,
"editor.background": muiTheme.palette.background.paper,
},
} satisfies monaco.editor.IStandaloneThemeData;